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

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.dsl.newib.payments.*;
import cz.moneta.test.dsl.newib.savings.PersonalDetailPage;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.newib.mainpage.BuildingSavingsPage.BUILDING_SAVINGS_TITLE_XPATH;

@Wait(value = {BUILDING_SAVINGS_TITLE_XPATH}, waitSecondsForElement = 30)
public interface BuildingSavingsPage extends NewIbPageFlow<BuildingSavingsPage> {

    String BUILDING_SAVINGS_TITLE_XPATH = "//h1[text()='Stavební spoření']";
    String BUILDING_SAVINGS_TEXT_XPATH = "//div[@class='c-card__header__text'][contains(., 'Nastavte si své stavební spoření') and contains(., 'Měsíční vklad') and contains(., 'Doba spoření') and contains(., 'Cílová částka') and contains(., 'Celkem naspoříte') and contains(., 'Vlastní vklad') and contains(., 'Státní podpora, v prvních 6 letech Vám ji zdvojnásobíme') and contains(., 'Poplatek za uzavření') and contains(., 'Měsíční vedení účtu stavebního spoření')]";
    String MONTHLY_PAYMENT_XPATH = "//input[@id='monthlyPayment']";
    String MONTHLY_PAYMENT_DEFAULT_XPATH = "//input[@id='monthlyPayment' and @value='1 700']";
    String MONTHLY_PAYMENT_ALERT_MAX_XPATH = "//div[@class='c-alert__text' and contains(., 'Skvělé, dosáhnete na maximální státní podporu') and contains(., '1') and  contains(., '000') and contains(., 'Kč ročně. Tu Vám navíc za prvních 6 let zdvojnásobíme.')]";
    String MONTHLY_PAYMENT_ALERT_MIN_XPATH = "//div[@class='c-alert__text' and contains(., 'Vkládejte alespoň') and contains(., '1') and contains (., '700')  and contains(., 'Kč měsíčně pro zisk maximální státní podpory') and contains(., '1') and contains(., '000') and contains(., 'Kč ročně, kterou Vám navíc za prvních 6 let zdvojnásobíme.')]";
    String TARGET_AMOUNT_OVERALL_XPATH = "//input[@id='targetAmount' and @value='%s']";
    String TARGET_AMOUNT_XPATH = "//input[@id='targetAmount']";
    String CHECKBOX_STATE_CONTRIBUTION_XPATH = "//label[@for='stateContributionEnabled']//span[text()='Požaduji státní podporu']";
    String CONTINUE_BUTTON_XPATH = "//button[@data-testid='Button'][text()='Pokračovat']";
    String MOBILE_KEY_SEND_BTN_XPATH = "//button[@data-testid='secondFactorSend']";
    String MOBILE_KEY_INPUT_XPATH = "//label[@for='mobileKey']//following-sibling::div//input[@id='mobileKey']";
    String VICTORY_TEXT_XPATH = "//div[@class='c-card__header__text'][contains(., 'Hotovo! Můžete začít spořit') and contains(., 'Na aktivaci Vašeho stavebního spoření budeme ještě chvíli pracovat, ale už teď si můžete nastavit trvalý příkaz.') and contains(., 'Smlouvu a ostatní dokumenty najdete v sekci Dokumenty. Aktivaci stavebního spoření Vám následně potvrdíme dopisem.')]";
    String SET_STANDING_ORDER_BUTTON_XPATH = "//button[@data-testid='Button'][text()='Nastavit trvalý příkaz']";
    String STANDING_ORDER_DESTINATION_ACC_NUMBER_XPATH = "//input[@id='destinationAccountNumber' and string-length(@value) > 0]";
    String STANDING_ORDER_DESTINATION_ACC_BANK_XPATH = "//button[@id='destinationAccountBank_button']//span[text()='7970']";
    String STANDING_ORDER_AMOUNT_XPATH = "//input[@id='amount' and @value='%s']";
    String STANDING_ORDER_FREQUENCY_XPATH = "//button[@id='frequency_button']//span[text()='Měsíčně']";
    String STANDING_ORDER_NOTE_FOR_RECIPIENT_XPATH = "//textarea[@id='noteForRecipient' and text()='Stavební spoření']";
    String STANDING_ORDER_CONTINUE_BUTTON_XPATH = "//button[@data-testid='submit' and text()='Pokračovat']";
    String STANDING_ORDER_CONFIRM_BUTTON_XPATH = "//button[@data-testid='submit' and text()='Potvrdit']";
    String STANDING_ORDER_VICTORY_TITLE_PAGE_XPATH = "//h1[contains(., 'Trvalý příkaz byl přijat ke zpracování')]";

    @CheckElementPresent(MONTHLY_PAYMENT_DEFAULT_XPATH)
    BuildingSavingsPage checkMonthlyPaymentDefault();

    @CheckElementPresent(BUILDING_SAVINGS_TEXT_XPATH)
    BuildingSavingsPage checkBuildingSavingsText();

    @CheckElementPresent(MONTHLY_PAYMENT_ALERT_MAX_XPATH)
    BuildingSavingsPage checkMonthlyPaymentMaxAlert();

    @TypeInto(value = MONTHLY_PAYMENT_XPATH, clear = true)
    BuildingSavingsPage setMonthlyPayment(String monthlyPayment);

    @CheckElementPresent(MONTHLY_PAYMENT_ALERT_MIN_XPATH)
    BuildingSavingsPage checkMonthlyPaymentMinAlert();

    @CheckElementPresent(value = TARGET_AMOUNT_OVERALL_XPATH, isStringDynamicXpath = true)
    BuildingSavingsPage checkTargetAmountOverall(String amount);

    @Click(TARGET_AMOUNT_XPATH)
    BuildingSavingsPage clickOnTargetAmount();

    @Click(CHECKBOX_STATE_CONTRIBUTION_XPATH)
    BuildingSavingsPage clickOnCheckboxStateContribution();

    @Click(CONTINUE_BUTTON_XPATH)
    PersonalDetailPage clickOnContinue();

    @Click(MOBILE_KEY_SEND_BTN_XPATH)
    BuildingSavingsPage clickOnContinueMobileKey();

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

    @Wait(value = VICTORY_TEXT_XPATH, until = Until.VISIBLE)
    @CheckElementPresent(VICTORY_TEXT_XPATH)
    BuildingSavingsPage checkVictoryText();

    @Click(SET_STANDING_ORDER_BUTTON_XPATH)
    BuildingSavingsPage clickSetStandingOrderButton();

    @CheckElementPresent(STANDING_ORDER_DESTINATION_ACC_NUMBER_XPATH)
    BuildingSavingsPage checkDestinationAccNumber();

    @CheckElementPresent(STANDING_ORDER_DESTINATION_ACC_BANK_XPATH)
    BuildingSavingsPage checkDestinationAccBank();

    @CheckElementPresent(value = STANDING_ORDER_AMOUNT_XPATH, isStringDynamicXpath = true)
    BuildingSavingsPage checkAmount(String amount);

    @CheckElementPresent(STANDING_ORDER_FREQUENCY_XPATH)
    BuildingSavingsPage checkFrequency();

    @CheckElementPresent(STANDING_ORDER_NOTE_FOR_RECIPIENT_XPATH)
    BuildingSavingsPage checkOrderNoteForRecipient();

    @Click(STANDING_ORDER_CONTINUE_BUTTON_XPATH)
    BuildingSavingsPage clickOnContinueButtonStandingOrder();

    @Click(STANDING_ORDER_CONFIRM_BUTTON_XPATH)
    BuildingSavingsPage clickOnConfirmButtonStandingOrder();

    @CheckElementPresent(STANDING_ORDER_VICTORY_TITLE_PAGE_XPATH)
    StandingOrderVictoryPage checkStandingOrderVictoryText();
}