package cz.moneta.test.dsl.ufo.banka.pages.main.components;

import cz.moneta.test.dsl.ufo.banka.pages.fop.TIS005_S002_SignerSelectionPoPage;
import cz.moneta.test.dsl.ufo.banka.pages.main.client.settings.PVX002_S002_AccountDispositionOwnerPage;
import cz.moneta.test.dsl.ufo.banka.pages.products.current.account.KUL032_S001_MiniFlexiBusinessLimitPage;
import cz.moneta.test.dsl.ufo.banka.pages.products.debit.card.SIF004_S001_ContactSettingsForSendingEmailsPage;
import cz.moneta.test.dsl.ufo.banka.pages.requests.DUP009_S001_CreateElectronicDistributionChannel;
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.main.components.BUF051_S001_CreateCurrentAccountPage.BUF051_S001_PAGE_LABEL_XPATH;
import static cz.moneta.test.dsl.ufo.banka.pages.main.components.BUF051_S001_CreateCurrentAccountPage.CONTINUE_BUTTON;
import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;

@Wait(value = BUF051_S001_PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 60)
@Wait(value = CONTINUE_BUTTON, waitSecondsForElement = 60)
public interface BUF051_S001_CreateCurrentAccountPage extends WebFlow<BUF051_S001_CreateCurrentAccountPage>, StoreAccessor {
    String BUF051_S001_PAGE_LABEL_XPATH = "//div[text()='BUF051_S001']";

    String PRODUCT_TYPE_SELECT = "BUF051_S001_C001";
    String DISTRIBUTION_TYPE_SELECT = "BUF051_S001_C003";
    String ACCOUNT_FLAG_SELECT = "BUF051_S001_C010";
    String ACCOUNT_TYPE_SELECT = "BUF051_S001_C007";
    String CURRENCY_SELECT = "BUF051_S001_C006";
    String STANDARD_CURRENCY_ACCOUNT_BUTTON = "BUF051_S001_B013";
    String CREATE_MFB_CHECKBOX = "BUF051_S001_H004_1";
    String CONTINUE_BUTTON = "BUF051_S001_B001";

    @Select(value = ACCOUNT_FLAG_SELECT, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 60))
    BUF051_S001_CreateCurrentAccountPage selectAccountFlag(String accountFlag);

    @Select(value = ACCOUNT_TYPE_SELECT, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 60))
    BUF051_S001_CreateCurrentAccountPage selectAccountType(String accountType);

    @Select(value = PRODUCT_TYPE_SELECT, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 60))
    BUF051_S001_CreateCurrentAccountPage selectProductType(String productType);

    @Select(value = DISTRIBUTION_TYPE_SELECT, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 60))
    BUF051_S001_CreateCurrentAccountPage selectDistributionType(String distributionType);

    @Select(value = CURRENCY_SELECT, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 60))
    BUF051_S001_CreateCurrentAccountPage selectCurrency(String accountFlag);

    @Select(value = PRODUCT_TYPE_SELECT, selectByOrder = true, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 60))
    BUF051_S001_CreateCurrentAccountPage selectProductTypeByOrder(int orderOfProductType);

    @Click(value = CREATE_MFB_CHECKBOX, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 60))
    BUF051_S001_CreateCurrentAccountPage changeMfbSetting();

    @Click(CONTINUE_BUTTON)
    TIS005_S002_SignerSelectionPoPage confirmAccountCreation();

    @Click(CONTINUE_BUTTON)
    SIF004_S001_ContactSettingsForSendingEmailsPage confirmCreationOnContactSettingPage();

    @Click(CONTINUE_BUTTON)
    PVX002_S002_AccountDispositionOwnerPage confirmCreationDispositionOwnerPage();

    @Click(CONTINUE_BUTTON)
    DUP009_S001_CreateElectronicDistributionChannel continueToCreateElectronicDistributionChannel();

    @Click(value = STANDARD_CURRENCY_ACCOUNT_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 60))
    BUF051_S001_CreateCurrentAccountPage clickStandardCurrencyAccount();

    @CustomAction
    @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 60)
    default KUL032_S001_MiniFlexiBusinessLimitPage clickContinueButtonToMainClientPageAndCloseAlertIfVisible() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> CONTINUE_BUTTON);
        if (endpoint.isAlertPresent(0)) {
            endpoint.acceptAlert(0);
        }
        return null;
    }
}
