package cz.moneta.test.dsl.ufo.banka.pages.fon;

import cz.moneta.test.dsl.ufo.banka.pages.cards.debit.OBR003_S001_ClientContractSignPage;
import cz.moneta.test.dsl.ufo.operations.shared.SharedElements;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ufo.banka.pages.fon.SZR004_S001_PersonIdentificationInFundamentalRegisters.SZR004_S001_PAGE_LABEL_XPATH;

@Wait(value = SZR004_S001_PAGE_LABEL_XPATH, by = Lookup.XPATH)
public interface SZR004_S001_PersonIdentificationInFundamentalRegisters extends WebFlow<SZR004_S001_PersonIdentificationInFundamentalRegisters>, StoreAccessor {

    String SZR004_S001_PAGE_LABEL_XPATH = "//div[text()='SZR004_S001']";
    String FIRST_NAME_INPUT = "SZR004_S001_E001";
    String LAST_NAME_INPUT = "SZR004_S001_E002";
    String BIRTH_NUMBER_INPUT = "SZR004_S001_E003";
    String BIRTH_DATE_INPUT = "SZR004_S001_E004";
    String DOCUMENT_NUMBER_INPUT = "SZR004_S001_E005";
    String NATIONALITY_SELECT = "SZR004_S001_C001";
    String CZECH_NATIONALITY_BUTTON = "SZR004_S001_B009";
    String CONTINUE_BUTTON = "SZR004_S001_B006";

    @TypeInto(FIRST_NAME_INPUT)
    SZR004_S001_PersonIdentificationInFundamentalRegisters fillFirstName(String firstName);

    @TypeInto(LAST_NAME_INPUT)
    SZR004_S001_PersonIdentificationInFundamentalRegisters fillLastName(String lastName);

    @TypeInto(BIRTH_NUMBER_INPUT)
    SZR004_S001_PersonIdentificationInFundamentalRegisters fillBirthNumber(String birthNumber);

    @TypeInto(BIRTH_DATE_INPUT)
    SZR004_S001_PersonIdentificationInFundamentalRegisters fillBirthDate(String birthDate);

    @TypeInto(DOCUMENT_NUMBER_INPUT)
    SZR004_S001_PersonIdentificationInFundamentalRegisters fillDocumentNumber(String documentNumber);

    @Select(NATIONALITY_SELECT)
    SZR004_S001_PersonIdentificationInFundamentalRegisters selectNationality(String nationality);

    @Click(value = CZECH_NATIONALITY_BUTTON, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    SZR004_S001_PersonIdentificationInFundamentalRegisters clickCzechNationality();

    /**
     * Na klientech v UFO Bance neprochází ztotožnění v základních registrech ČR, proto je potřeba se pro správné
     * testování proklikat errorovými hláškami tímto způsobem.
     */
    @CustomAction
    default OBR003_S001_ClientContractSignPage clickContinue() {

        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        for (int i = 0; i < 3; i++) {
            endpoint.click(() -> CZECH_NATIONALITY_BUTTON);
            endpoint.click(() -> CONTINUE_BUTTON);
        }
        return null;
    }

}
