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

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.dsl.newib.components.VerticalMainMenu;
import cz.moneta.test.dsl.newib.payments.AdvicePage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.*;

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

@Wait({ACCOUNTS_TITLE_XPATH})
public interface AccountsPage extends NewIbPageFlow<AccountsPage>, StoreAccessor, VerticalMainMenu {

    String ACCOUNTS_TITLE_XPATH = "//h1[@class='t-title t-title--h5 u-ml--small'][text()='Účty']";
    String EXCHANGE_PRODUCT_CARD = "//div[@data-testid='newProductCard-currentAccountForeign']";
    String AVAILABLE_BALANCE_XPATH = "//div[@class='t-amountWithUnit t-amountWithUnit--large t-amountWithUnit--bold']";
    String AVAILABLE_BALANCE_VALUE_KEY = "AVAILABLE_BALANCE_VALUE";
    String ADVANCED_SEARCH = "//button[@data-testid='advanced-search']";
    String DATE_FROM = "//input[@id='dateFrom']";
    String FILTER_TRANSACTIONS_BUTTON = "//button[@data-testid='advanced-filter-search']";
    String TRANSACTION_TYPE = "//button[text()='%s']";
    String PAYMENT_VALUE_XPATH = "//div[text()='%s']";
    String RESERVATION_DATA_XPATH = "//small[text()='%s']";
    String RESERVATION_AMOUNT_XPATH = "//div[@class='t-amountWithUnit t-amountWithUnit--medium t-amountWithUnit--bold'][text()='%s']";
    String RESERVATION_DESC_XPATH = "//span[text()='%s']";
    String ACCOUNT_NUMBERS_LIST = "//nav[@data-testid = 'Menu']/ul[@data-testid = 'MenuList']//p[@data-testid='TextComponent']/small[text()='%s']";
    String ACCOUNT_SETTINGS_XPATH = "//button[@aria-label='Nastavení']";
    String ACCOUNT_SET_AS_PREFFERED_XPATH = "//button[@data-testid='account-set-as-preffered-button']";
    String CONFIRM_BUTTON_XPATH = "//button[@data-testid='confirm-button']";
    String ACCOUNT_TITLE_XPATH = "//h1[@class='t-title t-title--h3'][text()='Běžné účty']";
    String SEARCH_FIELD = "//*[@id=\"fulltext\"]";
    String TRANSACTION_DETAIL_XPATH = "(//h2[@class='t-title t-title--h6 c-contentTableRow__title' and normalize-space(text())='%s'])[1]";
    String DOWNLOAD_CASH_RECEIPT_XPATH = "//button[@data-testid='Button'][text()='Zobrazit potvrzení platby']";
    String DEBIT_CARD_ONBOARDING_XPATH = "//div[@data-testid='banner-second-debit-card']";
    String DEBIT_CARD_ONBOARDING_NOT_VISIBLE_XPATH = "//div[not(.//div[@data-testid='banner-second-debit-card'])]";
    String ADVICE_BUTTON_XPATH = "//span[@data-testid='advices-tab' and text()='Avíza']";

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

    @CheckElementPresent(EXCHANGE_PRODUCT_CARD)
    AccountsPage checkExchangeProductCardIsPresent();

    @StoreElementContent(storeKey = AVAILABLE_BALANCE_VALUE_KEY, value = AVAILABLE_BALANCE_XPATH, by = Lookup.XPATH)
    AccountsPage getAvailableBalance();

    @Click(ADVANCED_SEARCH)
    AccountsPage clickAdvancedSearch();

    @TypeInto(value = DATE_FROM, clear = true)
    AccountsPage fillDateFrom(String actualDate);

    @Click(FILTER_TRANSACTIONS_BUTTON)
    AccountsPage clickFilterTransactions();

    @Click(value = TRANSACTION_TYPE, isStringDynamicXpath = true, by = Lookup.XPATH)
    AccountsPage selectTransactionType(String transactionTypes);

    @CheckElementPresent(value = PAYMENT_VALUE_XPATH, by = Lookup.XPATH, isStringDynamicXpath = true)
    AccountsPage checkPaymentValue(String paymentValue);

    @CheckElementPresent(value = RESERVATION_AMOUNT_XPATH, isStringDynamicXpath = true)
    AccountsPage checkReservationAmount(String amount);

    @CheckElementPresent(value = RESERVATION_DATA_XPATH, by = Lookup.XPATH, isStringDynamicXpath = true)
    AccountsPage checkReservationDate(String date);

    @CheckElementPresent(value = RESERVATION_DESC_XPATH, isStringDynamicXpath = true)
    AccountsPage checkReservationDescription(String description);

    @Click(value = ACCOUNT_NUMBERS_LIST, by = Lookup.XPATH, isStringDynamicXpath = true)
    AccountsPage selectAccountNumber(String accountNumber);

    @Click(ACCOUNT_SETTINGS_XPATH)
    AccountsPage clickOnAccountSettings();

    @Click(ACCOUNT_SET_AS_PREFFERED_XPATH)
    AccountsPage clickOnSetAsPreffered();

    @Click(value = CONFIRM_BUTTON_XPATH, andWait = @Wait(explicitWaitSeconds = 1))
    AccountsPage clickOnConfirmButton();

    @CheckElementPresent(ACCOUNT_TITLE_XPATH)
    AccountsPage checkAccountsTitleIsPresent();

    @TypeInto(value = SEARCH_FIELD, andWait = @Wait(explicitWaitSeconds = 3))
    AccountsPage searchAmount(String amount);

    @Click(value = TRANSACTION_DETAIL_XPATH, by = Lookup.XPATH, isStringDynamicXpath = true)
    AccountsPage openTransactionDetails(String transaction);

    @Click(DOWNLOAD_CASH_RECEIPT_XPATH)
    AccountsPage clickOnDownloadCashReceipt();

    @Click(DEBIT_CARD_ONBOARDING_XPATH)
    CardsOnboardingWelcomingPage clickOnNewDebitCard();

    @CheckElementPresent(DEBIT_CARD_ONBOARDING_NOT_VISIBLE_XPATH)
    AccountsPage checkNewDebitCardNotVisible();

    @Click(ADVICE_BUTTON_XPATH)
    AdvicePage clickOnAdviceButton();
}
