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

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.dsl.newib.components.HorizontalMainMenu;
import cz.moneta.test.dsl.newib.mainpage.DashboardPage;
import cz.moneta.test.dsl.newib.settings.accounts.AccountsSettingsPage;
import cz.moneta.test.dsl.newib.settings.cards.CardsSettingsPage;
import cz.moneta.test.dsl.newib.settings.communication.contacts.ChangePasswordPage;
import cz.moneta.test.dsl.newib.settings.disponents.DisponentsSettingsPage;
import cz.moneta.test.dsl.newib.settings.mobileapplication.AboutTheSmartBankaPage;
import cz.moneta.test.dsl.newib.settings.communication.contacts.ContactsPage;
import cz.moneta.test.dsl.newib.settings.envelopes.EnvelopesPage;
import cz.moneta.test.dsl.newib.settings.communication.contacts.PersonalAndContactDetailsPage;
import cz.moneta.test.dsl.newib.settings.payments.directdebit.DirectDebitsPage;
import cz.moneta.test.dsl.newib.settings.payments.sipo.SipoOrdersPage;
import cz.moneta.test.dsl.newib.settings.payments.standingorders.StandingOrdersPage;
import cz.moneta.test.dsl.newib.settings.payments.templates.TemplatesPage;
import cz.moneta.test.dsl.newib.settings.payments.trustedcontacts.TrustedContactsPage;
import cz.moneta.test.dsl.newib.settings.security.AuthorizationPage;
import cz.moneta.test.dsl.newib.settings.security.LimitsSettingsPage;
import cz.moneta.test.dsl.newib.settings.workingonproduct.WorkingModalPage;
import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.newib.settings.SettingsModalPage.*;
import static org.junit.jupiter.api.Assertions.assertTrue;

@Wait(value = {SETTINGS_MODAL_CLOSE_BTN_XPATH}, waitSecondsForElement = 30)
public interface SettingsModalPage extends NewIbPageFlow<SettingsModalPage>, HorizontalMainMenu {

    String SETTINGS_TITLE_XPATH = "//h2[@class='t-title t-title--h3 u-mb--0'][text()='Nastavení']";
    String STANDING_ORDERS_BTN_XPATH = "//button[@data-testid='settings_crossroad_payments-standingOrders']";
    String TEMPLATES_BTN_XPATH = "//button[@data-testid='settings_crossroad_payments-templates']";
    String DIRECT_DEBIT_BTN_XPATH = "//button[@data-testid='settings_crossroad_payments-directDebits']";
    String SIPO_BTN_XPATH = "//button[@data-testid='settings_crossroad_payments-sipos']";
    String THEME_SWITCHER_XPATH = "//div[@data-testid='themeSwitcher_toggle']";
    String SETTINGS_MODAL_CLOSE_BTN_XPATH = "//button[@data-testid='settings_modal-close']";
    String PERSONAL_AND_CONTACT_DETAILS_BTN_XPATH = "//button[@data-testid='settings_crossroad_personal-personalInformation']";
    String CONTACTS_BTN_XPATH = "//button[@data-testid='settings_crossroad_personal-contacts']";
    String AUTHORIZATION_BTN_XPATH = "//button[@data-testid='settings_crossroad_security-authorizations']";
    String ABOUT_SMART_BANKA_BTN_XPATH = "//button[@data-testid='settings_crossroad_mobileApp-aboutApp']";
    String SAVING_ACCOUNT_BTN_XPATH = "//button[@data-testid='settings_crossroad_products-savingsAccounts']";
    String CURRENT_ACCOUNT_BTN_XPATH = "//button[@data-testid='settings_crossroad_products-currentAccounts']";
    String LIMITS_BTN_XPATH = "//button[@data-testid='settings_crossroad_security-dispoLimits']";
    String TRUSTED_CONTACTS_BTN_XPATH = "//button[text()='Důvěryhodní příjemci']";
    String ENVELOPES_BTN_XPATH = "//button[@data-testid='settings_crossroad_products-envelopes']";
    String CHANGE_ID_BTN_XPATH = "//button[@data-testid='settings_crossroad_security-idChange']";
    String ACCOUNTS_BTN_XPATH = "//button[@data-testid='settings_crossroad_products-%s']";
    String CHANGE_PASSWORD_BUTTON_XPATH = "//button[@data-testid='settings_crossroad_personal-password' and text()='Změna hesla']";
    String CARDS_BUTTON_XPATH = "//button[@data-testid='settings_crossroad_products-cards' and text()='Karty']";
    String DISPONENTS_BUTTON_XPATH = "//button[@data-testid='settings_crossroad_profi-eDisponents' and text()='Správa eDisponentů']";

    @Click(value = STANDING_ORDERS_BTN_XPATH, andWait = @Wait(explicitWaitSeconds = 1))
    StandingOrdersPage clickOnStandingOrders();

    @Click(TEMPLATES_BTN_XPATH)
    TemplatesPage clickOnTemplates();

    @Click(DIRECT_DEBIT_BTN_XPATH)
    DirectDebitsPage clickOnDirectDebit();

    @Click(SIPO_BTN_XPATH)
    SipoOrdersPage clickOnSipo();

    @CheckElementPresent(THEME_SWITCHER_XPATH)
    SettingsModalPage checkThemeSwitcherIsPresent();

    @CheckElementPresent(SETTINGS_TITLE_XPATH)
    SettingsModalPage checkSettingsTitleIsPresent();

    @Click(SETTINGS_MODAL_CLOSE_BTN_XPATH)
    DashboardPage closeSettingsModal();

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

    @Click(CONTACTS_BTN_XPATH)
    ContactsPage clickOnContacts();

    @Click(AUTHORIZATION_BTN_XPATH)
    AuthorizationPage clickOnAuthorizations();

    @Click(ABOUT_SMART_BANKA_BTN_XPATH)
    AboutTheSmartBankaPage clickOnAboutTheSmartBanka();

    @Click(LIMITS_BTN_XPATH)
    LimitsSettingsPage clickOnLimits();

    @Click(value = TRUSTED_CONTACTS_BTN_XPATH, andWait = @Wait(explicitWaitSeconds = 1))
    TrustedContactsPage clickOnTrustedContacts();

    @Click(PERSONAL_AND_CONTACT_DETAILS_BTN_XPATH)
    PersonalAndContactDetailsPage clickOnPersonalAndContactDetailsSettings();

    @Click(value = ENVELOPES_BTN_XPATH)
    EnvelopesPage clickOnEnvelopes();

    @Click(CHANGE_ID_BTN_XPATH)
    WorkingModalPage clickOnChangeId();

    @Click(value = ACCOUNTS_BTN_XPATH, by = Lookup.XPATH, isStringDynamicXpath = true)
    AccountsSettingsPage clickOnAccounts(String account);

    @Click(CHANGE_PASSWORD_BUTTON_XPATH)
    ChangePasswordPage clickOnChangePasswordButton();

    @Click(CARDS_BUTTON_XPATH)
    CardsSettingsPage clickOnCards();

    @Click(DISPONENTS_BUTTON_XPATH)
    DisponentsSettingsPage clickOnDisponents();
}
