package cz.moneta.test.dsl.ufo.banka.pages.loans.creditCard;

import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ufo.banka.pages.loans.creditCard.ONC001_S001_NewCreditCardPage.*;

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

    String PAGE_ID_XPATH = "//div[text()='ONC001_S001']";
    String AMOUNT_INPUT = "ONC001_S001_E004";
    String NO_RECOMMENDATION_CHECKBOX = "ONC001_S001_H003_1";
    String PROMO_SELECT = "ONC001_S001_C001";
    String SEND_BUTTON = "ONC001_S001_B001";
    String ACCOUNT_SELECT = "ONC001_S001_C004";
    String CHANGE_REQUEST_PARAMETERS_CHECKBOX = "ONC001_S001_H001_1";

    @TypeInto(AMOUNT_INPUT)
    ONC001_S001_NewCreditCardPage fillAmount(int value);

    @Select(PROMO_SELECT)
    ONC001_S001_NewCreditCardPage selectPromo(String text);

    @Click(NO_RECOMMENDATION_CHECKBOX)
    ONC001_S001_NewCreditCardPage clickNoRecommendation();

    @Click(value = CHANGE_REQUEST_PARAMETERS_CHECKBOX, jsClick = true)
    ONC001_S001_NewCreditCardPage clickCheckRequestParametersCheckbox();

    @CustomAction
    default ONC001_S001_NewCreditCardPage selectAccountIfPossible(){
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        if(endpoint.isElementVisible(3,ACCOUNT_SELECT,Lookup.ID)){
            endpoint.selectByOptionOrder(ACCOUNT_SELECT,2,Lookup.ID);
        }
        return null;
    }

    @CustomAction
    default ONC001_S001_NewCreditCardPage dismissCardApplicationAlert() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.dismissAlert(20);
        return null;
    }

    @Click(SEND_BUTTON)
    ONC001_S001_NewCreditCardPageTransitions clickSend();
}
