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.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 KSN53Page extends KSNPageFlow<KSN53Page>, KSNUtils<KSN53Page> {

    String AUTH_PERSON_NAME = "//select[@name='authPerson']";

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

    @CustomAction
    default KSN53Page fillIdentificationAndSymbolsLong() {
        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(() -> VARIABLE_SYMBOL_INPUT, KSNNumberGenerator.getRandomNumberValue(), false);
        endpoint.type(() -> CONSTANT_SYMBOL_INPUT, KSNNumberGenerator.getRandomNumberValue(), false);
        endpoint.type(() -> SPECIFIC_SYMBOL_INPUT, KSNNumberGenerator.getRandomNumberValue(), false);
        return null;
    }

    @CustomAction
    default KSN53Page fillIdentificationAndSymbolsShort() {
        KasanovaEndpoint endpoint = getEndpoint(KasanovaEndpoint.class);
        endpoint.selectByVisibleText(IDENTIFICATION_PERSONAL_NUMBER_TYPE_SELECT, KSNIdCards.getRandomIdCardValue());
        endpoint.type(() -> IDENTIFICATION_ID_NUMBER_INPUT, KSNNumberGenerator.getRandomNumberValue(), false);
        endpoint.type(() -> IDENTIFICATION_ADDRESS_INPUT, KSNAdress.getRandomAdressValue(), false);
        endpoint.type(() -> VARIABLE_SYMBOL_INPUT, KSNNumberGenerator.getRandomNumberValue(), false);
        endpoint.type(() -> CONSTANT_SYMBOL_INPUT, KSNNumberGenerator.getRandomNumberValue(), false);
        endpoint.type(() -> SPECIFIC_SYMBOL_INPUT, KSNNumberGenerator.getRandomNumberValue(), false);
        return null;
    }

    @Select(value = AUTH_PERSON_NAME, by = Lookup.XPATH)
    KSN53Page authPerson(String text);

}
