package cz.moneta.test.dsl.kasanova.components;

import cz.moneta.test.dsl.kasanova.KSNPageFlow;
import cz.moneta.test.dsl.kasanova.KSNUtils;
import cz.moneta.test.dsl.kasanova.components.enums.KSNAdress;
import cz.moneta.test.dsl.kasanova.components.enums.KSNBirthPlaces;
import cz.moneta.test.dsl.kasanova.components.enums.KSNCountries;
import cz.moneta.test.dsl.kasanova.components.enums.KSNDescriptions;
import cz.moneta.test.dsl.kasanova.components.enums.KSNGender;
import cz.moneta.test.dsl.kasanova.components.enums.KSNIdCards;
import cz.moneta.test.dsl.kasanova.components.enums.KSNNames;
import cz.moneta.test.dsl.kasanova.components.enums.KSNNumberGenerator;
import cz.moneta.test.dsl.kasanova.components.enums.KSNPatterns;
import cz.moneta.test.dsl.util.DateUtils;
import cz.moneta.test.harness.endpoints.WebEndpoint;
import cz.moneta.test.harness.endpoints.kasanova.KasanovaEndpoint;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Lookup;
import cz.moneta.test.harness.support.web.Select;

public interface KSN86Page extends KSNPageFlow<KSN86Page>, KSNUtils<KSN86Page> {

    default void loadPage(WebEndpoint endpoint) {
        KSNPageFlow.loadLocalPage(endpoint, FEE_CODE);
    }

    @CustomAction
    default KSN86Page fillIdentificationMini() {
        KasanovaEndpoint endpoint = getEndpoint(KasanovaEndpoint.class);
        endpoint.type(() -> IDENTIFICATION_CLIENT_NAME_INPUT, KSNNames.getRandomNameValue(), true);
        endpoint.type(() -> IDENTIFICATION_PERSONAL_NUMBER_INPUT, DateUtils.getRandomDate(1940, 2000, KSNPatterns.DD_MM_YYYY.getValue()), false);
        endpoint.selectByVisibleText(IDENTIFICATION_SEX_SELECT, KSNGender.getRandomGenderValue());
        endpoint.selectByVisibleText(IDENTIFICATION_PERSONAL_NUMBER_TYPE_SELECT, KSNIdCards.getRandomIdCardValue());
        endpoint.type(() -> IDENTIFICATION_ID_NUMBER_INPUT, KSNNumberGenerator.getRandomNumberValue(), false);
        endpoint.selectByVisibleText(IDENTIFICATION_NATIONALITY_SELECT, KSNCountries.getRandomCountryValue());
        endpoint.type(() -> IDENTIFICATION_ADDRESS_INPUT, KSNAdress.getRandomAdressValue(), false);
        endpoint.type(() -> DESCRIPTION_INPUT, KSNDescriptions.getRandomDescriptionValue(), false);
        return null;
    }

    @CustomAction
    default KSN86Page fillIdentificationShort() {
        KasanovaEndpoint endpoint = getEndpoint(KasanovaEndpoint.class);
        endpoint.type(() -> IDENTIFICATION_CLIENT_NAME_INPUT, KSNNames.getRandomNameValue(), true);
        endpoint.type(() -> IDENTIFICATION_PERSONAL_NUMBER_INPUT, DateUtils.getRandomDate(1940, 2000, KSNPatterns.DD_MM_YYYY.getValue()), false);
        endpoint.selectByVisibleText(IDENTIFICATION_SEX_SELECT, KSNGender.getRandomGenderValue());
        endpoint.selectByVisibleText(IDENTIFICATION_PERSONAL_NUMBER_TYPE_SELECT, KSNIdCards.getRandomIdCardValue());
        endpoint.type(() -> IDENTIFICATION_ID_NUMBER_INPUT, KSNNumberGenerator.getRandomNumberValue(), false);
        endpoint.type(() -> IDENTIFICATION_ID_END_DATE_INPUT, DateUtils.getRandomDate(YEAR_ONE.getYear(), YEAR_MORE.getYear(), KSNPatterns.DDMMYYYY.getValue()), true);
        String coutry = KSNCountries.getRandomCountryValue();
        endpoint.selectByVisibleText(IDENTIFICATION_COUNTRY_ID_SELECT, coutry);
        endpoint.selectByVisibleText(IDENTIFICATION_LONG_TERM_RESIDENCE_SELECT, coutry);
        endpoint.selectByVisibleText(IDENTIFICATION_NATIONALITY_SELECT, coutry);
        endpoint.type(() -> IDENTIFICATION_BIRTH_PLACE_INPUT, KSNBirthPlaces.getRandomBirthPlaceValue(), true);
        endpoint.type(() -> IDENTIFICATION_ADDRESS_INPUT, KSNAdress.getRandomAdressValue(), false);
        endpoint.type(() -> DESCRIPTION_INPUT, KSNDescriptions.getRandomDescriptionValue(), false);
        return null;
    }

    @CustomAction
    default KSN86Page fillIdentificationLong() {
        KasanovaEndpoint endpoint = getEndpoint(KasanovaEndpoint.class);
        endpoint.type(() -> IDENTIFICATION_CLIENT_NAME_INPUT, KSNNames.getRandomNameValue(), true);
        endpoint.type(() -> IDENTIFICATION_PERSONAL_NUMBER_INPUT, DateUtils.getRandomDate(1940, 2000, KSNPatterns.DD_MM_YYYY.getValue()), false);
        endpoint.selectByVisibleText(IDENTIFICATION_SEX_SELECT, KSNGender.getRandomGenderValue());
        endpoint.selectByVisibleText(IDENTIFICATION_PERSONAL_NUMBER_TYPE_SELECT, KSNIdCards.getRandomIdCardValue());
        endpoint.type(() -> IDENTIFICATION_ID_NUMBER_INPUT, KSNNumberGenerator.getRandomNumberValue(), false);
        endpoint.type(() -> IDENTIFICATION_ID_END_DATE_INPUT, DateUtils.getRandomDate(YEAR_ONE.getYear(), YEAR_MORE.getYear(), KSNPatterns.DDMMYYYY.getValue()), true);
        String coutry = KSNCountries.getRandomCountryValue();
        endpoint.selectByVisibleText(IDENTIFICATION_COUNTRY_ID_SELECT, coutry);
        endpoint.selectByVisibleText(IDENTIFICATION_LONG_TERM_RESIDENCE_SELECT, coutry);
        endpoint.selectByVisibleText(IDENTIFICATION_NATIONALITY_SELECT, coutry);
        endpoint.type(() -> IDENTIFICATION_BIRTH_PLACE_INPUT, KSNBirthPlaces.getRandomBirthPlaceValue(), true);
        endpoint.type(() -> IDENTIFICATION_ADDRESS_INPUT, KSNAdress.getRandomAdressValue(), true);
        endpoint.type(() -> DESCRIPTION_INPUT, KSNDescriptions.getRandomDescriptionValue(), false);
        return null;
    }

	@CustomAction
	default KSN86Page dismissMultiAlerts(int timeout) {
		KasanovaEndpoint endpoint = getEndpoint(KasanovaEndpoint.class);
		if (endpoint.isElementVisible(timeout, BUTTON_KASADIALOG, Lookup.XPATH)) {
			endpoint.click(() -> BUTTON_KASADIALOG_OK, Lookup.XPATH);
		}
		if (endpoint.isElementVisible(timeout, BUTTON_KASADIALOG, Lookup.XPATH)) {
			endpoint.click(() -> BUTTON_KASADIALOG_OK, Lookup.XPATH);
		}
		return null;
	}

    @Select(FEE_CODE)
    KSN86Page selectFee(String text);

}
