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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.loans.creditCard.PLK014_S002_CardActivationPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage;
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.HPO009_S001_DebitCardDetailPage.HPO009_S001_PAGE_LABEL_XPATH;
import static org.junit.Assert.assertEquals;

@Wait(value = HPO009_S001_PAGE_LABEL_XPATH, waitSecondsForElement = 60, by = Lookup.XPATH)

public interface HPO009_S001_DebitCardDetailPage extends WebFlow<HPO009_S001_DebitCardDetailPage>, StoreAccessor {
    String HPO009_S001_PAGE_LABEL_XPATH = "//div[text()='HPO009_S001']";
    String BACK_TO_CLIENT_BUTTON = "HPO009_S001_S014";
    String CARD_CANCELLATION = "HPO009_S001_B020";
    String CARD_ACTIVATION = "HPO009_S001_B021";
    String CARD_CHANGE_MOTO_INTERNET = "HPO009_S001_I009";
    String OP_NUMBER = "XXX001_T002_L112";
    String CARD_STATUS = "HPO009_S001_L003";
    String ACCOUNT_NUM = "HPO009_S001_L201";
    String CARD_PRESENCE = "HPO009_S001_L055";
    String CARD_NUM = "HPO009_S001_L038";
    String CARD_DESIGN = "HPO009_S001_L056";
    String CARD_TYPE = "HPO009_S001_L002";
    String MOTO_AND_INT = "HPO009_S001_L028";
    String LIM_INT = "HPO009_S001_L017";
    String LIM_MOTO = "HPO009_S001_L009";
    String LIM_BANK = "HPO009_S001_L008";
    String CHANGE_OF_DATA = "HPO009_S001_B022";
    String CARD_CHANGE_3DSECURE = "HPO009_S001_B002";
    String BLOCK_MENU = "HPO009_S001_I006";
    String BLOCKATION_BUTTON = "HPO009_S001_B018";
    String CARD_TYPE_LABEL = "HPO009_S001_L002";
    String CARD_FEE_TYPE_LABEL = "HPO009_S001_L022";
    String CARDHOLDER_NAME_LABEL = "HPO009_S001_L011";
    String ADDRESS_FOR_CARD_LABEL = "HPO009_S001_L020";
    String ADDRESS_FOR_PIN_LABEL = "HPO009_S001_L031";
    String ACTIVATION_PASSWORD_LABEL = "HPO009_S001_L007";
    String CARD_STATUS_LABEL = "HPO009_S001_L003";
    String GENERATE_PIN_BUTTON = "HPO009_S001_B027";


    @Click(value = BACK_TO_CLIENT_BUTTON, jsClick = true)
    HKO101_S001_MainClientPage clickBackToClient();

    @Click(value = CARD_CANCELLATION)
    PLK007_S002_DebitCardCancellationPage clickCardCancellation();

    @Click(value = CARD_ACTIVATION)
    PLK014_S002_CardActivationPage clickCardActivation();

    @Click(value = CARD_CHANGE_MOTO_INTERNET)
    PLK033_S001_ChangeMotoIntTransactions clickMotoInt();

    @Click(value = CARD_CHANGE_3DSECURE)
    POZ002_S002_Change3dSecureRetailDebitCard click3dSecureChange();

    @Click(value = BLOCK_MENU)
    @Click(value = BLOCKATION_BUTTON)
    PLK003_S002_BlockMenu clickBlockMenu();

    @Click(CHANGE_OF_DATA)
    PLK008_S001_ChangeInfoOfDebitCard clickChangeOfData();

    @Click(GENERATE_PIN_BUTTON)
    PLK013_S001_GeneratePinPage clickGeneratePinButton();

    @CheckElementContent(CARD_TYPE_LABEL)
    HPO009_S001_DebitCardDetailPage assertCardType(String type);

    @CheckElementContent(CARD_FEE_TYPE_LABEL)
    HPO009_S001_DebitCardDetailPage assertCardFeeType(String type);

    @CheckElementContent(CARDHOLDER_NAME_LABEL)
    HPO009_S001_DebitCardDetailPage assertCardholderName(String type);

    @CheckElementContent(ADDRESS_FOR_CARD_LABEL)
    HPO009_S001_DebitCardDetailPage assertAddressForCard(String type);

    @CheckElementContent(ADDRESS_FOR_PIN_LABEL)
    HPO009_S001_DebitCardDetailPage assertAddressForPin(String type);

    @CheckElementContent(LIM_BANK)
    HPO009_S001_DebitCardDetailPage assertATMLimit(String limit);

    @CheckElementContent(LIM_MOTO)
    HPO009_S001_DebitCardDetailPage assertPOSLimit(String limit);

    @CheckElementContent(LIM_INT)
    HPO009_S001_DebitCardDetailPage assertInternetAMOTOLimit(String limit);

    @CheckElementContent(ACTIVATION_PASSWORD_LABEL)
    HPO009_S001_DebitCardDetailPage assertActivationPassword(String limit);

    @CheckElementContent(CARD_STATUS_LABEL)
    HPO009_S001_DebitCardDetailPage assertCardStatus(String limit);

    @CustomAction
    default HPO009_S001_DebitCardDetailPage storeLimits(Harness harness) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        harness.store("LIM_INT_PAYMENT_CURRENT", endpoint.getText(LIM_INT).replace(" ", ""));
        harness.store("LIM_MOTO_PAYMENT_CURRENT", endpoint.getText(LIM_MOTO).replace(" ", ""));
        harness.store("LIM_BANK_PAYMENT_CURRENT", endpoint.getText(LIM_BANK).replace(" ", ""));
        return null;
    }

    @CustomAction
    default HPO009_S001_DebitCardDetailPage checkLastName(String lastName) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String str = endpoint.getText("HPO009_S001_L011");
        String[] splitStr = str.split("\\s+");
        assertEquals(lastName, splitStr[1]);
        return null;
    }
}