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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.fon.TIS050_S002_SignerSelectionPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ufo.banka.pages.cards.credit.POZ015_S001_ChangeLimitsOnMbcPage.POZ015_S001_PAGE_LABEL_XPATH;

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

    String POZ015_S001_PAGE_LABEL_XPATH = "//div[text()='POZ015_S001']";
    String ATM_LIMIT_INPUT = "POZ015_S001_E004";
    String INT_LIMIT_INPUT = "POZ015_S001_E007";
    String MOTO_LIMIT_INPUT = "POZ015_S001_E006";
    String CHANGE_LIMIT_BUTTON = "POZ015_S001_B002";

    @TypeInto(clear = true, value = ATM_LIMIT_INPUT)
    POZ015_S001_ChangeLimitsOnMbcPage changeAtmLimit(String atmLimit);

    @TypeInto(clear = true, value = INT_LIMIT_INPUT)
    POZ015_S001_ChangeLimitsOnMbcPage changeIntLimit(String intLimit);

    @TypeInto(clear = true, value = MOTO_LIMIT_INPUT)
    POZ015_S001_ChangeLimitsOnMbcPage changeMotoLimit(String motoLimit);

    @Click(value = CHANGE_LIMIT_BUTTON, jsClick = true)
    @DismissAlert(waitSecondsForAlert = 5)
    POZ015_S001_ChangeLimitsOnMbcPage changeLimitsWithAlert();

    @Click(value = CHANGE_LIMIT_BUTTON, jsClick = true)
    TIS050_S002_SignerSelectionPage changeLimits();

    @CustomAction
    default POZ015_S001_ChangeLimitsOnMbcPage checkAndChangeLimits(String atmLimitExpected, String intLimitExpected, String motoLimitExpected, Harness harness) {
        String atmLimitActual = harness.get("LIM_BANK_PAYMENT_CURRENT");
        String intLimitActual = harness.get("LIM_INT_PAYMENT_CURRENT");
        String posLimitActual = harness.get("LIM_MOTO_PAYMENT_CURRENT");

        if (atmLimitActual.equals(atmLimitExpected)) {
            atmLimitExpected = "4310";
        }
        changeAtmLimit(atmLimitExpected);
        harness.store("LIM_BANK_PAYMENT_CHANGED", atmLimitExpected);

        if (intLimitActual.equals(intLimitExpected)) {
            intLimitExpected = "4310";
        }
        changeIntLimit(intLimitExpected);
        harness.store("LIM_INT_PAYMENT_CHANGED", intLimitExpected);

        if (posLimitActual.equals(motoLimitExpected)) {
            motoLimitExpected = "4310";
        }
        changeMotoLimit(motoLimitExpected);
        harness.store("LIM_MOTO_PAYMENT_CHANGED", motoLimitExpected);

        return null;
    }
}
