package cz.moneta.test.dsl.ufo.banka.pages.products.flexi.credit;

import cz.moneta.test.dsl.ufo.banka.pages.common.pages.PSI001_S050_PreContractualInfromationPrintedPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.PSP004_S001_PrintPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.signature.patterns.NPV010_S001_PrintSignPadPage;
import cz.moneta.test.dsl.ufo.banka.pages.requests.PSI001_S050_PreContractualInformationPrintedPage;
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.products.flexi.credit.NKK003_S001_SelectingApprovedVariantsPage.*;

@Wait(value = NKK003_S001_PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 60)
@Wait(value = {PAGE_ID, LOAN_AMOUNT_RADIO}, waitSecondsForElement = 60)
public interface NKK003_S001_SelectingApprovedVariantsPage extends WebFlow<NKK003_S001_SelectingApprovedVariantsPage>, StoreAccessor {

    String NKK003_S001_PAGE_LABEL_XPATH = "//div[text()='NKK003_S001']";
    String PAGE_ID = "XXX001_T001_C001";
    String LOAN_AMOUNT_RADIO = "NKK003_S001_G001-0";
    String SECOND_VARIANT_RADIO = "NKK003_S001_G001-1";
    String LOAN_AMOUNT_ARRAY = "NKK003_S001_E001";
    String SELECT_BUTTON = "NKK003_S001_B001";

    @Click(value = LOAN_AMOUNT_RADIO, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    NKK003_S001_SelectingApprovedVariantsPage clickToLoanAmountRadioButton();

    @Click(value = SECOND_VARIANT_RADIO, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    NKK003_S001_SelectingApprovedVariantsPage clickSecondVariant();

    @Wait(LOAN_AMOUNT_ARRAY)
    @TypeInto(LOAN_AMOUNT_ARRAY)
    NKK003_S001_SelectingApprovedVariantsPage typeIntoLoanAmount(String loanAmount);

    @CustomAction
    default NKK003_S001_SelectingApprovedVariantsPage fillIntoLoanAmountIfVisible(String loanAmount) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        if (endpoint.isElementVisible(LOAN_AMOUNT_ARRAY)) {
            endpoint.type(() -> LOAN_AMOUNT_ARRAY, loanAmount, true);
        }
        return null;
    }

    @Click(SELECT_BUTTON)
    PSI001_S050_PreContractualInfromationPrintedPage clickSelectButtonToPreContractualPage();

    @Click(SELECT_BUTTON)
    NPV010_S001_PrintSignPadPage clickSelectButtonToPrintSingPadPage();

    @Click(SELECT_BUTTON)
    PSI001_S050_PreContractualInformationPrintedPage clickSelect();

    @Click(SELECT_BUTTON)
    PSP004_S001_PrintPage clickSelectToPrint();
}
