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

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.ufo.banka.pages.common.pages.INK001_OBR001_004_ConfirmationPage;
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.main.INK001_S004_CreateNewDirectDebitPage.INK001_S004_PAGE_LABEL_XPATH;

@Wait(value = INK001_S004_PAGE_LABEL_XPATH, by = Lookup.XPATH)
@Wait(value = INK001_S004_CreateNewDirectDebitPage.SAVE_BUTTON, waitSecondsForElement = 120)
public interface INK001_S004_CreateNewDirectDebitPage extends WebFlow<INK001_S004_CreateNewDirectDebitPage>, StoreAccessor {

    String INK001_S004_PAGE_LABEL_XPATH = "//div[text()='INK001_S004']";
    String SAVE_BUTTON = "INK001_S004_B003";
    String RECEIVER_ACCOUNT_NUMBER_INPUT = "INK001_S004_E005";
    String RECEIVER_ACCOUNT_BANK_CODE_INPUT = "INK001_S004_E006";
    String AMOUNT_INPUT = "INK001_S004_E007";
    String RECEIVER_ACCOUNT_NAME_INPUT = "INK001_S004_E009";
    String PERIOD_COMBOBOX = "INK001_S004_C001";

    @TypeInto(RECEIVER_ACCOUNT_NUMBER_INPUT)
    INK001_S004_CreateNewDirectDebitPage fillReceiverAccountNumber(String receiverAccountNumber);

    @TypeInto(RECEIVER_ACCOUNT_BANK_CODE_INPUT)
    INK001_S004_CreateNewDirectDebitPage fillReceiverAccountBankCode(String receiverAccountBankCode);

    @TypeInto(AMOUNT_INPUT)
    INK001_S004_CreateNewDirectDebitPage fillAmount(String amount);

    @TypeInto(RECEIVER_ACCOUNT_NAME_INPUT)
    INK001_S004_CreateNewDirectDebitPage fillReceiverAccountName(String ReceiverAccountNameInput);

    @Select(PERIOD_COMBOBOX)
    INK001_S004_CreateNewDirectDebitPage selectPeriod(String period);

    @Click(SAVE_BUTTON)
    INK001_OBR001_004_ConfirmationPage clickSave();

    @Click(SAVE_BUTTON)
    PSP004_S001_PrintPage clickSaveToPrint();

    @CustomAction
    default INK001_S004_CreateNewDirectDebitPage checkNotSavingNotFilledForm() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> SAVE_BUTTON);
        Assertions.assertEquals("Limit musí být zadán a musí být větší než 0.", endpoint.getAlertText(1));
        endpoint.acceptAlert(1);
        return null;
    }

}
