package cz.moneta.test.dsl.ufo.banka.pages.ib;

import cz.moneta.test.dsl.ufo.banka.pages.main.ADC012_S001_SettingADC;
import cz.moneta.test.dsl.util.task.udebs.UdebsTasks;
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.ib.ADC001_S001_IbPasswordKeyPage.ADC001_S001_PAGE_LABEL_XPATH;
import static cz.moneta.test.dsl.ufo.banka.pages.ib.ADC001_S001_IbPasswordKeyPage.GSM_NUMBER_MK_IB;
import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;

@Wait(value = ADC001_S001_PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 80)
@Wait(value = GSM_NUMBER_MK_IB, waitSecondsForElement = 80)
public interface ADC001_S001_IbPasswordKeyPage extends StoreAccessor, WebFlow<ADC001_S001_IbPasswordKeyPage> {
    String ADC001_S001_PAGE_LABEL_XPATH = "//div[text()='ADC001_S001']";
    String PASSWORD_PLUS_MK = "Heslo + mobilní klíč";

    String NEW_ENVELOPE_NUMBER_INPUT = "ADC001_S001_U004";
    String SEND_BUTTON = "ADC001_S001_B001";
    String LOGIN_METHOD_SELECT = "ADC001_S001_C003";
    String DAILY_lIMIT = "ADC001_S001_U003";
    String GSM_NUMBER_MK_IB = "ADC001_S001_E002";

    String FILL_FROM_CIF_CHECKBOX = "ADC001_S001_H004_1";

    @CustomAction
    default ADC001_S001_IbPasswordKeyPage insertEnvelopeNumber() {
        String envelopeNumber = new UdebsTasks(this).getEnvelopeNumberWithoutPrefixZero();
        getEndpoint(UfoEndpoint.class)
                .type(() -> NEW_ENVELOPE_NUMBER_INPUT, envelopeNumber, false);
        return null;
    }

    @TypeInto(NEW_ENVELOPE_NUMBER_INPUT)
    ADC001_S001_IbPasswordKeyPage fillEnvelopeNumber(int envelopeNumber);

    @Select(LOGIN_METHOD_SELECT)
    ADC001_S001_IbPasswordKeyPage selectLoginMethod(String method);

    @TypeInto(GSM_NUMBER_MK_IB)
    ADC001_S001_IbPasswordKeyPage enterMobilePhoneNumber(String phoneNumber);

    @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE)
    @Click(SEND_BUTTON)
    ADC012_S001_SettingADC clickContinueToSettingADCPage();

    @Click(value = FILL_FROM_CIF_CHECKBOX, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    ADC001_S001_IbPasswordKeyPage clickFillFromCifCheckbox();

    @CustomAction
    default ADC001_S001_IbPasswordKeyPage scrollIntoSendButton() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.scrollIntoView(LOGIN_METHOD_SELECT);
        return null;
    }

    @Click(SEND_BUTTON)
    ADC001_S001_IbPasswordKeyPageTransitions clickContinue();

    @TypeInto(value = DAILY_lIMIT, clear = true)
    ADC001_S001_IbPasswordKeyPage typeDailyLimit(String limit);
}