package cz.moneta.test.dsl.ufo.banka.pages.cards.debit;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.fon.TIS050_S001_SignerSelectionPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.PSP004_S001_PrintPage;
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.cards.debit.POZ002_S002_Change3dSecureRetailDebitCard.PAGE_LABEL_XPATH;
import static cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage.CLIENT_ID_KEY;

@Wait(value = PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 60)
public interface POZ002_S002_Change3dSecureRetailDebitCard extends WebFlow<POZ002_S002_Change3dSecureRetailDebitCard>, StoreAccessor {

    String PAGE_LABEL_XPATH = "//div[text()='POZ002_S002']";
    String DOCUMENT_TYPE_COMBO = "POZ002_S002_C001";
    String DOCUMENT_NUMBER_INPUT = "POZ002_S002_E002";
    String EXISTING_NUMBER_LABEL = "POZ002_S002_L009";
    String NEW_NUMBER_INPUT = "POZ002_S002_E001";
    String NEW_NUMBER_BUTTON = "POZ002_S002_B001";


    @Select(value = DOCUMENT_TYPE_COMBO, selectByOrder = true)
    POZ002_S002_Change3dSecureRetailDebitCard selectDocumentType(int indexNumOfDocumentType);

    @TypeInto(DOCUMENT_NUMBER_INPUT)
    POZ002_S002_Change3dSecureRetailDebitCard fillDocumentNumber(String idCardNumber);

    @CustomAction
    default POZ002_S002_Change3dSecureRetailDebitCard fillDocumentNumberFromHko(Harness harness) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.type(() -> DOCUMENT_NUMBER_INPUT, harness.get(CLIENT_ID_KEY), false);
        return null;
    }

    @CustomAction
    default POZ002_S002_Change3dSecureRetailDebitCard fillNew3dSecureNumber() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        if (!endpoint.getText(EXISTING_NUMBER_LABEL).equals("720961931")) {
            endpoint.type(() -> NEW_NUMBER_INPUT, "720961931", false);
        } else {
            endpoint.type(() -> NEW_NUMBER_INPUT, "702227334", false);
        }
        return null;
    }

    @Click(value = NEW_NUMBER_BUTTON)
    TIS050_S001_SignerSelectionPage clickToChange3dSecureNumber();

    @Click(value = NEW_NUMBER_BUTTON)
    PSP004_S001_PrintPage clickToChange3dSecureNumberToPrint();
}
