package cz.moneta.test.dsl.newib.settings.security;

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.dsl.newib.components.HorizontalMainMenu;
import cz.moneta.test.dsl.newib.mainpage.AccountsPage;
import cz.moneta.test.dsl.newib.mainpage.DashboardPage;
import cz.moneta.test.dsl.newib.settings.SettingsModalPage;
import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.*;

import static org.junit.jupiter.api.Assertions.assertTrue;

public interface LimitsSettingsPage extends NewIbPageFlow<AccountsPage>, HorizontalMainMenu {

    String BACK_TO_SETTINGS_BTN_XPATH = "//button[@data-testid='back-to-settings-crossroad']";
    String CLOSE_BTN_XPATH = "//button[@data-testid='settings_modal-close']";
    String TEXT_COMPONENT_IB_XPATH = "//p[@data-testid='TextComponent'][text()='Internet Banka']";
    String TEXT_COMPONENT_SB_XPATH = "//p[@data-testid='TextComponent'][text()='Smart Banka']";
    String INTERNET_BANKA_DAY_LIMIT_ACTIVATE_XPATH = "//label[@id='channels.ib.day.active-label' and normalize-space(.)='Nastaven']";
    String INTERNET_BANKA_WEEK_LIMIT_UNACTIVATE_XPATH = "//label[@id='channels.ib.week.active-label' and normalize-space(.)='Nenastaven']";
    String INTERNET_BANKA_DAY_LIMIT_VALUE_PRESENT_XPATH = "//input[@data-testid='limits.ib.day.amount' and translate(@value, ' ', '')='%s']";
    String INTERNET_BANKA_DAY_LIMIT_VALUE_XPATH = "//input[@data-testid='limits.ib.day.amount']";
    String INTERNET_BANKA_WEEK_LIMIT_BUTTON_XPATH = "//button[@id='channels.ib.week.active']";
    String INTERNET_BANKA_WEEK_LIMIT_VALUE_XPATH = "//input[@data-testid='limits.ib.week.amount']";
    String SMART_BANKA_DAY_LIMIT_ACTIVATE_XPATH = "//label[@id='channels.sb.day.active-label' and normalize-space(.)='Nastaven']";
    String SMART_BANKA_WEEK_LIMIT_UNACTIVATE_XPATH = "//label[@id='channels.sb.week.active-label' and normalize-space(.)='Nenastaven']";
    String SMART_BANKA_DAY_LIMIT_VALUE_PRESENT_XPATH = "//input[@data-testid='limits.sb.day.amount' and translate(@value, ' ', '')='%s']";
    String SMART_BANKA_DAY_LIMIT_VALUE_XPATH = "//input[@data-testid='limits.sb.day.amount']";
    String SMART_BANKA_WEEK_LIMIT_BUTTON_XPATH = "//button[@id='channels.sb.week.active']";
    String SMART_BANKA_WEEK_LIMIT_VALUE_XPATH = "//input[@data-testid='limits.sb.week.amount']";
    String CONTINUE_BTN_XPATH = "//button[@data-testid='dispoLimit__button--submit']";
    String INTERNET_BANKA_DAY_LIMIT_VALUE_SUMMARY_PRESENT_XPATH = "//p[normalize-space(.)='Internet Banka']/ancestor::ul//p[starts-with(normalize-space(.), 'Denní limit')]/strong[text()='%s']";
    String INTERNET_BANKA_WEEK_LIMIT_VALUE_SUMMARY_PRESENT_XPATH = "//p[normalize-space(.)='Internet Banka']/ancestor::ul//p[starts-with(normalize-space(.), 'Týdenní limit')]/strong[text()='%s']";
    String SMART_BANKA_DAY_LIMIT_VALUE_SUMMARY_PRESENT_XPATH = "//p[normalize-space(.)='Smart Banka']/ancestor::ul//p[starts-with(normalize-space(.), 'Denní limit')]/strong[text()='%s']";
    String SMART_BANKA_WEEK_LIMIT_VALUE_SUMMARY_PRESENT_XPATH = "//p[normalize-space(.)='Smart Banka']/ancestor::ul//p[starts-with(normalize-space(.), 'Týdenní limit')]/strong[text()='%s']";
    String CONFIRM_BTN_XPATH = "//button[@data-testid='submit']";
    String MOBILE_KEY_INPUT_XPATH = "//label[@for='mobileKey']//following-sibling::div//input[@id='mobileKey']";
    String MOBILE_KEY_SEND_BTN_XPATH = "//button[@data-testid='secondFactorSend']";
    String VICTORY_TITLE_XPATH = "//h3[normalize-space(text())='Váš požadavek na změnu limitů a kanálů byl proveden']";
    String BACK_TO_LIMITS_BTN_XPATH = "//button[@data-testid='Button' and normalize-space(.)='Zobrazit přehled limitů']";
    String INTERNET_BANKA_WEEK_LIMIT_VALUE_PRESENT_XPATH = "//input[@data-testid='limits.ib.week.amount' and translate(@value, ' ', '')='%s']";
    String SMART_BANKA_WEEK_LIMIT_VALUE_PRESENT_XPATH = "//input[@data-testid='limits.sb.week.amount' and translate(@value, ' ', '')='%s']";

    @CustomAction
    default LimitsSettingsPage checkUrl() {
        NewIbEndpoint newIbEndpoint = getEndpoint(NewIbEndpoint.class);
        String actualUrl = newIbEndpoint.getCurrentUrl();
        String urlContains = "settings/limits";
        assertTrue(actualUrl.contains(urlContains));
        return null;
    }

    @CheckElementPresent(BACK_TO_SETTINGS_BTN_XPATH)
    LimitsSettingsPage checkBackToSettingsIsPresent();

    @CheckElementPresent(CLOSE_BTN_XPATH)
    LimitsSettingsPage checkCloseBtnIsPresent();

    @CheckElementPresent(TEXT_COMPONENT_IB_XPATH)
    LimitsSettingsPage checkTextComponentIBIsPresent();

    @CheckElementPresent(TEXT_COMPONENT_SB_XPATH)
    LimitsSettingsPage checkTextComponentSBIsPresent();

    @Click(BACK_TO_SETTINGS_BTN_XPATH)
    SettingsModalPage clickOnBackToSettings();

    @CheckElementPresent(INTERNET_BANKA_DAY_LIMIT_ACTIVATE_XPATH)
    LimitsSettingsPage checkInternetBankaDayLimitActive();

    @CheckElementPresent(INTERNET_BANKA_WEEK_LIMIT_UNACTIVATE_XPATH)
    LimitsSettingsPage checkInternetBankaWeekLimitUnactive();

    @CheckElementPresent(value = INTERNET_BANKA_DAY_LIMIT_VALUE_PRESENT_XPATH, isStringDynamicXpath = true)
    LimitsSettingsPage checkInternetBankaDayLimitValueIsPresent(String dayLimitValue);

    @Click(INTERNET_BANKA_WEEK_LIMIT_BUTTON_XPATH)
    LimitsSettingsPage clickOnInternetBankyWeekLimitActivate();

    @Wait(value = INTERNET_BANKA_DAY_LIMIT_VALUE_XPATH, until = Until.VISIBLE)
    @TypeInto(value = INTERNET_BANKA_DAY_LIMIT_VALUE_XPATH, clear = true)
    LimitsSettingsPage changeInternetBankaDayLimit(String dayLimitValue);

    @TypeInto(value = INTERNET_BANKA_WEEK_LIMIT_VALUE_XPATH, clear = true)
    LimitsSettingsPage changeInternetBankaWeekLimit(String weekLimitValue);

    @CheckElementPresent(SMART_BANKA_DAY_LIMIT_ACTIVATE_XPATH)
    LimitsSettingsPage checkSmartBankaDayLimitActive();

    @CheckElementPresent(SMART_BANKA_WEEK_LIMIT_UNACTIVATE_XPATH)
    LimitsSettingsPage checkSmartBankaWeekLimitUnactive();

    @CheckElementPresent(value = SMART_BANKA_DAY_LIMIT_VALUE_PRESENT_XPATH, isStringDynamicXpath = true)
    LimitsSettingsPage checkSmartBankaDayLimitValueIsPresent(String dayLimitValue);

    @Click(SMART_BANKA_WEEK_LIMIT_BUTTON_XPATH)
    LimitsSettingsPage clickOnSmartBankyWeekLimitActivate();

    @TypeInto(value = SMART_BANKA_DAY_LIMIT_VALUE_XPATH, clear = true)
    LimitsSettingsPage changeSmartBankaDayLimit(String dayLimitValue);

    @TypeInto(value = SMART_BANKA_WEEK_LIMIT_VALUE_XPATH, clear = true)
    LimitsSettingsPage changeSmartBankaWeekLimit(String weekLimitValue);

    @Click(CONTINUE_BTN_XPATH)
    LimitsSettingsPage clickOnContinueBtn();

    @CheckElementPresent(value = INTERNET_BANKA_DAY_LIMIT_VALUE_SUMMARY_PRESENT_XPATH, isStringDynamicXpath = true)
    LimitsSettingsPage checkInternetBankaDayLimit(String dayLimitValue);

    @CheckElementPresent(value = INTERNET_BANKA_WEEK_LIMIT_VALUE_SUMMARY_PRESENT_XPATH, isStringDynamicXpath = true)
    LimitsSettingsPage checkInternetBankaWeekLimit(String weekLimitValue);

    @CheckElementPresent(value = SMART_BANKA_DAY_LIMIT_VALUE_SUMMARY_PRESENT_XPATH, isStringDynamicXpath = true)
    LimitsSettingsPage checkSmartBankaDayLimit(String dayLimitValue);

    @CheckElementPresent(value = SMART_BANKA_WEEK_LIMIT_VALUE_SUMMARY_PRESENT_XPATH, isStringDynamicXpath = true)
    LimitsSettingsPage checkSmartBankaWeekLimit(String weekLimitValue);

    @Click(CONFIRM_BTN_XPATH)
    LimitsSettingsPage clickOnConfirmBtn();

    @TypeInto(MOBILE_KEY_INPUT_XPATH)
    LimitsSettingsPage setMobileKey(String mobileKey);

    @Click(MOBILE_KEY_SEND_BTN_XPATH)
    LimitsSettingsPage clickOnConfirm();

    @CheckElementPresent(VICTORY_TITLE_XPATH)
    LimitsSettingsPage checkVictoryTitleIsPresent();

    @Click(BACK_TO_LIMITS_BTN_XPATH)
    LimitsSettingsPage clickOnBackToLimits();

    @CheckElementPresent(value = INTERNET_BANKA_WEEK_LIMIT_VALUE_PRESENT_XPATH, isStringDynamicXpath = true)
    LimitsSettingsPage checkInternetBankaWeekLimitValueIsPresent(String weekLimitValue);

    @CheckElementPresent(value = SMART_BANKA_WEEK_LIMIT_VALUE_PRESENT_XPATH, isStringDynamicXpath = true)
    LimitsSettingsPage checkSmartBankaWeekLimitValueIsPresent(String weekLimitValue);

    @Click(CLOSE_BTN_XPATH)
    DashboardPage clickOnCloseBtn();
}
