package cz.moneta.test.dsl.ufo.banka.pages.products.universal.request;

import cz.moneta.test.dsl.ufo.banka.pages.loans.expres.HLE001_S001_CoApplicantSearchPage;
import cz.moneta.test.dsl.ufo.operations.shared.SharedElements;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;
import org.junit.jupiter.api.Assertions;

import static cz.moneta.test.dsl.ufo.banka.pages.products.universal.request.UZO001_S001_UniverzalRequestIdentificationPage.LOAN_AMOUNT;

@Wait(value = LOAN_AMOUNT, waitSecondsForElement = 30)
public interface UZO001_S001_UniverzalRequestIdentificationPage extends WebFlow<UZO001_S001_UniverzalRequestIdentificationPage>, SharedElements, StoreAccessor {

    String PAGE_ID_XPATH = "//div[text()=' UZO001_S001' or text()='lala']";
    String CONTINUE_BUTTON = "UZO001_S001_B002";
    String LOAN_AMOUNT = "UZO001_S001_E006";
    String NUMBER_OF_INSTALLMENTS = "UZO001_S001_C003";
    String PRIMARY_REQUIRED_PRODUCT_SELECT = "UZO001_S001_C001";
    String MONTHLY_INSTALLMENT_INPUT = "UZO001_S001_E007";
    String NOT_INCLUDE_EXTERN_COMMITMENTS_RADIO = "UZO001_S001_R002_0";
    String REQUIRED_INCREASE_INPUT = "UZO001_S001_E022";
    String CALCULATION_OF_INSTALLMENTS = "UZO001_S001_B004";
    String LOADER_XPATH = "/html/body/div[@class='gwt-PopupPanel']/div[@class='popupContent']/img[@class='gwt-Image']/@src";
    String OTHER_APPLICANT_INPUT = "UZO001_S001_H003_1";
    String FILL_IN_APPLICANT_BUTTON = "UZO001_S001_B005";
    String RELATIONSHIP_WITH_MAIN_APPLICANT_SELECT = "UZO001_S001_C005";

    @TypeInto(LOAN_AMOUNT)
    UZO001_S001_UniverzalRequestIdentificationPage typeIntoLoanAmount(int loanAmount);

    @Select(value = NUMBER_OF_INSTALLMENTS, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    UZO001_S001_UniverzalRequestIdentificationPage selectNumberOfInstallments(int numberOfInstallments);

    @Click(CALCULATION_OF_INSTALLMENTS)
    UZO001_S001_UniverzalRequestIdentificationPage clickCalculationOfInstallmentsButtonUniversalRequestPage();

    @Select(value = PRIMARY_REQUIRED_PRODUCT_SELECT, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    UZO001_S001_UniverzalRequestIdentificationPage selectPrimaryRequiredProduct(String primaryRequiredProduct);

    @CustomAction
    default UZO001_S001_UniverzalRequestIdentificationPage checkMonthlyInstallmentNotEmpty() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertNotEquals("", endpoint.getAttribute(MONTHLY_INSTALLMENT_INPUT, "value"));
        return null;
    }

    @Click(value = NOT_INCLUDE_EXTERN_COMMITMENTS_RADIO, jsClick = true)
    UZO001_S001_UniverzalRequestIdentificationPage clickNotIncludeExternCommitments();

    @Click(value = CALCULATION_OF_INSTALLMENTS,
            andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    UZO001_S001_UniverzalRequestIdentificationPage clickCalculateInstallment();

    @Click(value = CONTINUE_BUTTON, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    UZO001_S001_UniverzalRequestIdentificationPageTransitions clickContinue();

    @TypeInto(REQUIRED_INCREASE_INPUT)
    UZO001_S001_UniverzalRequestIdentificationPage fillRequiredIncrease(String requiredIncrease);

    @Click(value = OTHER_APPLICANT_INPUT, jsClick = true)
    UZO001_S001_UniverzalRequestIdentificationPage clickOtherApplicant();

    @Click(FILL_IN_APPLICANT_BUTTON)
    HLE001_S001_CoApplicantSearchPage clickFillInApplicant();

    @Select(RELATIONSHIP_WITH_MAIN_APPLICANT_SELECT)
    UZO001_S001_UniverzalRequestIdentificationPage selectRelationshipWithMainApplicant(String relationshipWithMainApplicant);

}