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

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.UZO006_S004_UniverzalRequestCombinationsCalculatorPage.PAGE_ID_XPATH;

@Wait(value = PAGE_ID_XPATH, by = Lookup.XPATH)
public interface UZO006_S004_UniverzalRequestCombinationsCalculatorPage extends WebFlow<UZO006_S004_UniverzalRequestCombinationsCalculatorPage>, StoreAccessor {

    String PAGE_ID_XPATH = "//div[text()='UZO006_S004']";
    String CREDIT_SELECT = "UZO006_S004_C001";
    String CALCULATION_BUTTON = "UZO006_S004_B002";
    String INSURANCE_SELECT = "UZO006_S004_C004";
    String PAYMENT_INPUT = "UZO006_S004_E003";
    String CREDIT_RATE_INPUT = "UZO006_S004_E004";
    String RPSN_INPUT = "UZO006_S004_E005";
    String INSURANCE_CHARGE_INPUT = "UZO006_S004_E006";
    String RECALCULATION_SELECT = "UZO006_S004_C002";
    String RECALCULATE_BUTTON = "UZO006_S004_B003";
    String DO_NOT_ACCEPT_THIRD_PRODUCT_CHECKBOX = "UZO006_S004_H001_1";
    String CREDIT_AMOUNT_INPUT = "UZO006_S004_E001";
    String BACK_BUTTON = "UZO006_S004_B001";

    @Select(value = CREDIT_SELECT, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    UZO006_S004_UniverzalRequestCombinationsCalculatorPage selectCredit(String credit);

    @TypeInto(value = CREDIT_AMOUNT_INPUT, clear = true)
    UZO006_S004_UniverzalRequestCombinationsCalculatorPage fillCreditAmount(String creditAmount);

    @Click(value = CALCULATION_BUTTON, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    UZO006_S004_UniverzalRequestCombinationsCalculatorPage clickCalculation();

    @Select(INSURANCE_SELECT)
    UZO006_S004_UniverzalRequestCombinationsCalculatorPage selectInsurance(String insurance);

    @CustomAction
    default UZO006_S004_UniverzalRequestCombinationsCalculatorPage checkPaymentNotEmpty() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertNotEquals("", endpoint.getAttribute(PAYMENT_INPUT, "value"));
        return null;
    }

    @CustomAction
    default UZO006_S004_UniverzalRequestCombinationsCalculatorPage checkCreditRateNotEmpty() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertNotEquals("", endpoint.getAttribute(CREDIT_RATE_INPUT, "value"));
        return null;
    }

    @CustomAction
    default UZO006_S004_UniverzalRequestCombinationsCalculatorPage checkRpsnNotEmpty() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertNotEquals("", endpoint.getAttribute(RPSN_INPUT, "value"));
        return null;
    }

    @CustomAction
    default UZO006_S004_UniverzalRequestCombinationsCalculatorPage checkInsuranceChargeNotEmpty() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        Assertions.assertNotEquals("", endpoint.getAttribute(INSURANCE_CHARGE_INPUT, "value"));
        return null;
    }

    @Select(value = RECALCULATION_SELECT, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    UZO006_S004_UniverzalRequestCombinationsCalculatorPage selectRecalculation(String recalculation);

    @Click(value = RECALCULATE_BUTTON, andWait = @Wait(value = SharedElements.LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    UZO006_S004_UniverzalRequestCombinationsCalculatorPage clickRecalculate();

    @CustomAction
    default UZO006_S004_UniverzalRequestCombinationsCalculatorPage checkDoNotAcceptThirdProductIsVisible() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementsToLoad(10, Until.VISIBLE, DO_NOT_ACCEPT_THIRD_PRODUCT_CHECKBOX);
        return null;
    }

    @Click(BACK_BUTTON)
    UZO006_S001_UniverzalRequestModeling clickBack();

}
