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.auto.smartauto.shared.CommonElements.LOADER_DIV;
import static cz.moneta.test.dsl.ufo.banka.pages.loans.creditCard.PLK014_S002_CardActivationPage.ACTIVATE_BUTTON;

@Wait(ACTIVATE_BUTTON)
public interface PLK014_S002_CardActivationPage extends WebFlow<PLK014_S002_CardActivationPage>, StoreAccessor {

    String ACTIVATE_BUTTON = "PLK014_S002_B005";
    String ID_CARD_NUMBER_INPUT = "PLK014_S002_E002";
    String ID_CARD_TYPE_SELECT = "PLK014_S002_C001";

    @Select(value = ID_CARD_TYPE_SELECT, andWait = @Wait(value = LOADER_DIV, until = Until.GONE))
    PLK014_S002_CardActivationPage selectIdCardType(String idCardType);

    @TypeInto(value = ID_CARD_NUMBER_INPUT, andWait = @Wait(value = LOADER_DIV, until = Until.GONE))
    PLK014_S002_CardActivationPage fillIdCardNumber(String idCardNumber);

    @Click(value = ACTIVATE_BUTTON, andWait = @Wait(value = LOADER_DIV, until = Until.GONE))
    PLK014_S003_CardActivationPageTransitions clickActivateCard();

    @Select(value = ID_CARD_TYPE_SELECT, selectByOrder = true)
    PLK014_S002_CardActivationPage selectOP(int indexOfOP);

    @CustomAction
    default PLK014_S002_CardActivationPage fillIdCardNumberWithPossibleAlert(String idCardNumber) {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        this.fillIdCardNumber(idCardNumber);
        if (endpoint.isAlertPresent(3)) {
            endpoint.dismissAlert(1);
            this.fillIdCardNumber(idCardNumber);
        }
        return null;
    }
}