package cz.moneta.test.dsl.ib.settings.ib.ediponents;

import cz.moneta.test.dsl.ib.IbPageFlow;
import cz.moneta.test.dsl.ib.components.MainMenu;
import cz.moneta.test.dsl.ib.settings.ib.SettingsVerticalMenu;
import cz.moneta.test.harness.endpoints.ib.IbEndpoint;
import cz.moneta.test.harness.support.web.*;

import java.util.List;

import static cz.moneta.test.dsl.ib.settings.ib.ediponents.RequestSetDiponentPage.REQUEST_SET_DISPONENT_TITLE;
import static cz.moneta.test.dsl.ib.settings.ib.ediponents.RequestSetDiponentPage.SET_ACTIVE_DISPONENT_STEP_1;

@Waits({
        @Wait(REQUEST_SET_DISPONENT_TITLE),
        @Wait(SET_ACTIVE_DISPONENT_STEP_1)})
public interface RequestSetDiponentPage extends IbPageFlow<RequestSetDiponentPage>, MainMenu, SettingsVerticalMenu {
    String REQUEST_SET_DISPONENT_TITLE = "//img[@alt='Nastavení disponenta']";
    String SET_ACTIVE_DISPONENT_STEP_1 = "//img[@src='images_new/top_step1.gif']";
    String RIGHTS_FOR_ACCOUNTS_CHECKBOX = "//td[text()='Práva pro účty']//following::label[contains(text(),'%s')]/input[@type='checkbox']";
    String USE_SMART_BANK = "//td[text()='Využívání Smart Banky']//following::label[contains(text(),'Povolení používání Smart Banky')]/input[@type='checkbox']";
    String CONTINUE_BUTTON_REQUEST_SET_DISPONENT = "//img[@alt='Pokračovat']";
    String PAYMENTS_LIMITS_CHECKBOX = "//td[text()='Platební limity']/following::label[contains(text(),'Nastavit denní limit')]/input[@type='checkbox']";
    String LIMIT_INPUT = "//td[text()='Platební limity']/following::input[@id='limit']";

    @Click(value = RIGHTS_FOR_ACCOUNTS_CHECKBOX, isStringDynamicXpath = true)
    RequestSetDiponentPage rightsForAccountsClickToCheckbox(String nameOfItem);

    @Click(USE_SMART_BANK)
    RequestSetDiponentPage allowedToUseSmartBankClickCheckbox();

    @Click(CONTINUE_BUTTON_REQUEST_SET_DISPONENT)
    RequestSetDiponentPage clickToContinueButtonWithoutSelection();

    @Click(CONTINUE_BUTTON_REQUEST_SET_DISPONENT)
    CheckSetDiponentPage clickToContinueButton();

    @AcceptAlert(waitSecondsForAlert = 10, expectedAlertText = "Chyba - minimálně jeden účet musí být vybrán")
    RequestSetDiponentPage accpetAlertWindow();

    @Click(PAYMENTS_LIMITS_CHECKBOX)
    RequestSetDiponentPage clickCheckboxPaymentsLimits();

    @TypeInto(value = LIMIT_INPUT, clear = true)
    RequestSetDiponentPage typeLimit(String limit);

    @CustomAction
    default RequestSetDiponentPage rightsForAccountsClicksToCheckboxes(List<String> namesOfItems) {
        IbEndpoint ibEndpoint = getEndpoint(IbEndpoint.class);
        namesOfItems.forEach(s -> ibEndpoint.click(() -> String.format(RIGHTS_FOR_ACCOUNTS_CHECKBOX, s)));
        return null;
    }
}