package cz.moneta.test.dsl.ufo.banka.pages.main.client.settings;

import cz.moneta.test.dsl.ufo.banka.pages.main.HKO101_S001_MainClientPage;
import cz.moneta.test.dsl.ufo.operations.client.clientDetail.STS701_S002_ClientDetailPage;
import cz.moneta.test.dsl.ufo.operations.ufoOperations.PSP701_S001_AmortizationPage;
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.client.settings.EVY701_S001_StatementsDistributionPage.CONTINUE_BUTTON;
import static cz.moneta.test.dsl.ufo.banka.pages.main.client.settings.EVY701_S001_StatementsDistributionPage.EVY701_S001_PAGE_LABEL;

@Wait(value = EVY701_S001_PAGE_LABEL, waitSecondsForElement = 40)
@Wait(value = CONTINUE_BUTTON, waitSecondsForElement = 40)
public interface EVY701_S001_StatementsDistributionPage extends WebFlow<EVY701_S001_StatementsDistributionPage>, StoreAccessor {
    String EVY701_S001_PAGE_LABEL = "EVY701_S001_L001";

    String CONTINUE_BUTTON = "EVY701_S001_B001";
    String SELECT_DISTRIBUTION_OF_STATEMENT = "EVY701_S001_C001";
    String SAVINGS_ACCOUNT_RADIO = "ufo-et-EVY701_S001_F001_row_2_sel";
    String CLICK_BACK_BUTTON = "EVY701_S001_B002";

    @Wait(CONTINUE_BUTTON)
    @Click(value = CONTINUE_BUTTON)
    HKO101_S001_MainClientPage continueToClientDetailPage();

    @Click(SAVINGS_ACCOUNT_RADIO)
    EVY701_S001_StatementsDistributionPage clickSavingsAccountRadio();

    @AcceptAlert(waitSecondsForAlert = 5, expectedAlertText = "Změnu distribuce výpisu je možné provést pouze na vybraném produktu.")
    EVY701_S001_StatementsDistributionPage acceptAlertChangeDistribution();

    @Wait(value = SELECT_DISTRIBUTION_OF_STATEMENT, explicitWaitSeconds = 5)
    @CustomAction
    default EVY701_S001_StatementsDistributionPage selectAnotherDistributionOfStatement() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String currentValue = endpoint.getSelectedFirstItemText(SELECT_DISTRIBUTION_OF_STATEMENT);
        if (currentValue.contains("Poštou")) {
            endpoint.selectByVisibleText(SELECT_DISTRIBUTION_OF_STATEMENT, "Osobně");
        } else if (currentValue.contains("Elektronicky IB")) {
            endpoint.selectByVisibleText(SELECT_DISTRIBUTION_OF_STATEMENT, "Poštou");
        } else if (currentValue.contains("Osobně"))
            endpoint.selectByVisibleText(SELECT_DISTRIBUTION_OF_STATEMENT, "Elektronicky IB");
        return null;
    }

    @Wait(CONTINUE_BUTTON)
    @Click(CONTINUE_BUTTON)
    PSP701_S001_AmortizationPage clickChangeDistribution();

    @Wait(value = CLICK_BACK_BUTTON, until = Until.VISIBLE)
    @Click(CLICK_BACK_BUTTON)
    STS701_S002_ClientDetailPage clickBackButton();
}
