package cz.moneta.test.dsl.monetaportal.loans;

import cz.moneta.test.dsl.monetaportal.components.Naviblocks;
import cz.moneta.test.dsl.monetaportal.components.calculators.ExpressLoanCalculator;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.support.web.Click;
import cz.moneta.test.harness.support.web.GetElementContent;
import cz.moneta.test.harness.support.web.TypeInto;
import cz.moneta.test.harness.support.web.Until;
import cz.moneta.test.harness.support.web.Wait;
import cz.moneta.test.harness.support.web.WebFlow;

import static cz.moneta.test.dsl.monetaportal.components.calculators.ExpressLoanCalculator.RESULT_SECTION_MONTHLY_PRICE_SPAN;

@Wait(RESULT_SECTION_MONTHLY_PRICE_SPAN)
public interface UDCExpressLoanPage extends WebFlow<UDCExpressLoanPage>, ExpressLoanCalculator, Naviblocks, StoreAccessor {
    //UDC loan calculator
    String CALCULATOR_DIV = "//div[contains(@id, 'PersonalCalculator')]";
    String CALCULATOR_ADD_LOAN_BUTTON = CALCULATOR_DIV + "//span[@data-message-id='ObligationForm.addLoan']/..";
    String CALCULATOR_ADD_OVERDRAFT_BUTTON = CALCULATOR_DIV + "//span[@data-message-id='ObligationForm.addOverdraft']/..";
    String CALCULATOR_ADD_CREDIT_CARD_BUTTON = CALCULATOR_DIV + "//span[@data-message-id='ObligationForm.addCreditCard']/..";
    String CALCULATOR_ADD_OBLIGATION_INPUT_ = "(" + CALCULATOR_DIV + "//div[contains(@class, 'Obligation')]//input[not(contains(@value, '00'))])[1]";
    String CALCULATOR_ADD_EXTRA_MONEY_INPUT_ = "(" + CALCULATOR_DIV + "//div[contains(@class, 'Loan')]//input)[1]";
    String CALCULATOR_BANNER_SECTION_BUTTON = "//div[@class='b-product-claim__text-side']//a[@class='btn btn-primary ']";

    @Click(CALCULATOR_BANNER_SECTION_BUTTON)
    UDCExpressLoanPage clickCalculatorSection();

    @Click(CALCULATOR_ADD_LOAN_BUTTON)
    UDCExpressLoanPage clickCalculatorAddLoan();

    @Click(CALCULATOR_ADD_OVERDRAFT_BUTTON)
    UDCExpressLoanPage clickCalculatorAddOverdraft();

    @Click(CALCULATOR_ADD_CREDIT_CARD_BUTTON)
    UDCExpressLoanPage clickCalculatorAddCreditCard();

    @TypeInto(value = CALCULATOR_ADD_OBLIGATION_INPUT_, clear = true)
    UDCExpressLoanPage fillCalculatorObligation(String obligationAmount);

    @TypeInto(value = CALCULATOR_ADD_EXTRA_MONEY_INPUT_, clear = true)
    UDCExpressLoanPage fillCalculatorExtraMoney(String extraMoneyAmount);

    @Wait(value = CALCULATOR_SPINNER, until = Until.GONE)
    @GetElementContent(RESULT_SECTION_MONTHLY_PRICE_SPAN)
    String getMonthlyPrice();

    /*@CustomAction
    default UDCLoanPage moveCalculatorLoanLengthBy(int xOffset) {
        MonetaPortalEndpoint endpoint = getEndpoint(MonetaPortalEndpoint.class);
        String initialMonthlyPrice = this.getMonthlyPrice();
        endpoint.dragAndDropBy(CALCULATOR_LENGTH_SLIDER, xOffset, 0);
        String changedMonthlyPrice = this.getMonthlyPrice();
        Assertions.assertNotEquals(initialMonthlyPrice, changedMonthlyPrice, "Monthly price calculation did not change.");
        return null;
    }

    @Wait(value = CALCULATOR_SPINNER, until = Until.GONE)
    @Click(CALCULATOR_NEXT_BUTTON)
    GetUDCLoanPage clickCalculatorGetLoan();*/
}