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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.cards.debit.PLK033_S001_ChangeMotoIntTransactions;
import cz.moneta.test.dsl.ufo.banka.pages.main.DOK001_S001_SelectionOfSubmittedDocumentsPage;
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.*;

@Wait(value = HPO019_S001_CreditCardDetailPage.HPO019_S001_PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 40)
public interface HPO019_S001_CreditCardDetailPage extends WebFlow<HPO019_S001_CreditCardDetailPage>, StoreAccessor {
    String HPO019_S001_PAGE_LABEL_XPATH = "//div[text()='HPO019_S001']";
    String METHOD_OF_PAYMENT_STORE_KEY = "METHOD_OF_PAYMENT_STORE_KEY";
    String CREDIT_FOR_CASH_WITHDRAV_STORE = "CREDIT_FOR_CASH_WITHDRAV_STORE";
    String TOTAL_CREDIT_STORE = "TOTAL_CREDIT_STORE";
    String METHOD_OF_PAYMENT_DIV = "HPO019_S001_L006";
    String TOTAL_CREDIT_DIV = "HPO019_S001_L003";
    String CREDIT_FOR_CASH_WITHDRAV_DIV = "HPO019_S001_L005";
    String BACK_TO_CLIENT_BUTTON = "HPO019_S001_S014";
    String CONTRACT_NUMBER_KEY = "CONTRACT_NUMBER";
    String ACTIVATE_CARD_BUTTON = "HPO019_S001_B002";
    String CARD_STAT_DIV_LABEL = "HPO019_S001_L020";
    String PROD_STAT_STORE = "PROD_STAT_STORE";
    String PRODUCT_TRANSFER_BUTTON = "HPO019_S001_B005";
    String CARD_CHANGE_MOTO_INTERNET = "HPO019_S001_I006";
    String EXPIRATION_LABEL = "HPO019_S001_L011";
    String DAILY_WITHDRAW_LIMIT_LABEL = "HPO019_S001_L009";
    String DAILY_PURCHASE_LIMIT_LABEL = "HPO019_S001_L007";
    String CONTRACT_NUMBER_LABEL = "HPO019_S001_L001";
    String SERVICE_OPERATIONS_BUTTON = "HPO019_S001_B012";
    String DAILY_INTERNET_LIMIT_LABEL = "HPO019_S001_L051";
    String CLIP_CARD_BUTTON = "HPO019_S001_B007";
    String DECLIP_CARD_BUTTON = "HPO019_S001_B017";

    @StoreElementContent(value = METHOD_OF_PAYMENT_DIV, storeKey = METHOD_OF_PAYMENT_STORE_KEY)
    @StoreElementContent(value = CREDIT_FOR_CASH_WITHDRAV_DIV, storeKey = CREDIT_FOR_CASH_WITHDRAV_STORE)
    @StoreElementContent(value = TOTAL_CREDIT_DIV, storeKey = TOTAL_CREDIT_STORE)
    HPO019_S001_CreditCardDetailPage storeCreditCardValues();

    @StoreElementContent(value = TOTAL_CREDIT_DIV, storeKey = TOTAL_CREDIT_STORE)
    HPO019_S001_CreditCardDetailPage storeCreditCardTotalCredit();

    @Click(BACK_TO_CLIENT_BUTTON)
    HKO101_S001_MainClientPage clickBackToClient();

    @CheckElementContent(METHOD_OF_PAYMENT_DIV)
    HPO019_S001_CreditCardDetailPage assertPaymentMethod(String method);

    @CheckElementContent(DAILY_WITHDRAW_LIMIT_LABEL)
    HPO019_S001_CreditCardDetailPage assertDailyWithdrawLimit(String method);

    @CheckElementContent(DAILY_PURCHASE_LIMIT_LABEL)
    HPO019_S001_CreditCardDetailPage assertDailyPurchaseLimit(String method);

    @StoreElementContent(storeKey = CONTRACT_NUMBER_KEY, value = CONTRACT_NUMBER_LABEL)
    HPO019_S001_CreditCardDetailPage storeContractNumber();

    @Click(ACTIVATE_CARD_BUTTON)
    HPO019_CreditCardDetailPageTransitions clickActivateCard();

    @StoreElementContent(storeKey = PROD_STAT_STORE, value = CARD_STAT_DIV_LABEL)
    HPO019_S001_CreditCardDetailPage storeProductStat();

    @Click(PRODUCT_TRANSFER_BUTTON)
    HPO019_CreditCardDetailPageTransitions clickProductTransferButton();

    @Click(CARD_CHANGE_MOTO_INTERNET)
    PLK033_S001_ChangeMotoIntTransactions clickMotoInt();

    @Click(SERVICE_OPERATIONS_BUTTON)
    POZ001_S007_CreditCardServiceOperationsPage clickCardService();

    @CustomAction
    default POZ001_S007_CreditCardServiceOperationsPage clickCardServiceWithPossibleAlert() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> SERVICE_OPERATIONS_BUTTON);
        if (endpoint.isAlertPresent(3)) {
            endpoint.dismissAlert(1);
        }
        return null;
    }

    @Click(CLIP_CARD_BUTTON)
    DOK001_S001_SelectionOfSubmittedDocumentsPage clickClipCard();

    @Click(DECLIP_CARD_BUTTON)
    NKK019_S001_DeclipRequestPage clickDeclipCard();

    @CustomAction
    default HPO019_S001_CreditCardDetailPage storeLimits(Harness harness) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        harness.store("LIM_INT_PAYMENT_CURRENT", endpoint.getText(DAILY_INTERNET_LIMIT_LABEL).replace(" ", "").replace(",00", ""));
        harness.store("LIM_MOTO_PAYMENT_CURRENT", endpoint.getText(DAILY_PURCHASE_LIMIT_LABEL).replace(" ", "").replace(",00", ""));
        harness.store("LIM_BANK_PAYMENT_CURRENT", endpoint.getText(DAILY_WITHDRAW_LIMIT_LABEL).replace(" ", "").replace(",00", ""));
        return null;
    }
}
