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.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.credit.HPO039_S001_MbcDetailPage.HPO039_S001_PAGE_LABEL_XPATH;

@Wait(value = HPO039_S001_PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 60)
public interface HPO039_S001_MbcDetailPage extends WebFlow<HPO039_S001_MbcDetailPage>, StoreAccessor {
    String HPO039_S001_PAGE_LABEL_XPATH = "//div[text()='HPO039_S001']";
    String DAILY_WITHDRAW_LIMIT_LABEL = "HPO039_S001_L075";
    String DAILY_PURCHASE_LIMIT_LABEL = "HPO039_S001_L074";
    String DAILY_INTERNET_LIMIT_LABEL = "HPO039_S001_L077";

    String CHANGE_FRAME_BUTTON = "HPO039_S001_I010";
    String SERVICE_OPERATIONS_BUTTON = "HPO039_S001_I028";
    String INTERNET_AND_MOTO_TRANS_BUTTON = "HPO039_S001_I032";
    String INCREASE_FRAME_BUTTON = "HPO039_S001_I045";
    String DECREASE_FRAME_BUTTON = "HPO039_S001_I046";
    String CHANGE_LIMITS_BUTTON = "HPO039_S001_I048";
    String CARD_STATUS_LABEL = "HPO039_S001_L059";
    String BACK_TO_CLIENT_BUTTON = "HPO039_S001_I044";

    @CustomAction
    default HPO039_S001_MbcDetailPage 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;
    }

    @Click(CHANGE_LIMITS_BUTTON)
    POZ015_S001_ChangeLimitsOnMbcPage clickChangeLimits();

    @Click(INTERNET_AND_MOTO_TRANS_BUTTON)
    PLK033_S001_ChangeMotoIntTransactions clickChangeMotoInt();

    @Click(SERVICE_OPERATIONS_BUTTON)
    POZ001_S007_CreditCardServiceOperationsPage clickServiceOperations();

    @CustomAction
    default HPO039_S001_MbcDetailPageTransitions mouseOverFrameChangeAndDecrease() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.moveToElement(CHANGE_FRAME_BUTTON);
        endpoint.click(() -> DECREASE_FRAME_BUTTON);
        return null;
    }

    @CustomAction
    default HPO039_S001_MbcDetailPageTransitions mouseOverFrameChangeAndIncrease() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.moveToElement(CHANGE_FRAME_BUTTON);
        endpoint.click(() -> INCREASE_FRAME_BUTTON);
        return null;
    }
}
