package cz.moneta.test.dsl.ufo.banka.pages.main.client.settings;

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.main.client.settings.ODS003_S001_AddCodeOfRecommendedPersonPage.*;

@Wait(value = ODS003_S001_PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 80)
@Wait(value = {PAGE_ID, PRODUCT_NOT_RECOMMENDED_CHECKBOX}, waitSecondsForElement = 80)
public interface ODS003_S001_AddCodeOfRecommendedPersonPage extends WebFlow<ODS003_S001_AddCodeOfRecommendedPersonPage>, StoreAccessor {
    String ODS003_S001_PAGE_LABEL_XPATH = "//div[text()='ODS003_S001']";
    String PAGE_ID = "ODS003_S001_Z001";
    String SAVE_PROMOTER_CODE_BUTTON = "ODS003_S001_B001";
    String WITHOUT_RECOMMEND_BUTTON = "ODS003_S001_B003";
    String RECOMMENDED_BY_INPUT = "ODS003_S001_E001";
    String PRODUCT_NOT_RECOMMENDED_CHECKBOX = "ODS003_S001_H003_1";

    @TypeInto(RECOMMENDED_BY_INPUT)
    ODS003_S001_AddCodeOfRecommendedPersonPage fillPromoterCode(String operatorinstCode);

    @Click(PRODUCT_NOT_RECOMMENDED_CHECKBOX)
    ODS003_S001_AddCodeOfRecommendedPersonPage checkProductNotRecommended();

    @Click(SAVE_PROMOTER_CODE_BUTTON)
    ODS003_S001_AddCodeOfRecommendedPersonPageTransitions clickSavePromoter();

    @Click(WITHOUT_RECOMMEND_BUTTON)
    ODS003_S001_AddCodeOfRecommendedPersonPageTransitions clickWithoutRecommendation();

    @CustomAction
    default ODS003_S001_AddCodeOfRecommendedPersonPageTransitions clickWithoutRecommendationAndDismissAlertIfvisible() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> WITHOUT_RECOMMEND_BUTTON);
        if (endpoint.isAlertPresent(3)) {
            endpoint.dismissAlert(1);
        }
        return null;
    }
}