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

import cz.moneta.test.dsl.Harness;
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.PKU001_S002_CreatePaymentOrderPage.PKU001_S002_PAGE_LABEL_XPATH;

@Wait(value = PKU001_S002_PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 90)
@Wait(value = PKU001_S002_CreatePaymentOrderPage.CREDITOR_ACC_NUMBER_INPUT, waitSecondsForElement = 90)
public interface PKU001_S002_CreatePaymentOrderPage extends WebFlow<PKU001_S002_CreatePaymentOrderPage>, StoreAccessor {

    String PKU001_S002_PAGE_LABEL_XPATH = "//div[text()='PKU001_S002']";
    String DEBTOR_ACC_NUMBER_INPUT = "PKU001_S002_E003";
    String CREDITOR_ACC_NUMBER_INPUT = "PKU001_S002_E005";
    String CREDITOR_ACC_BANK_CODE_INPUT = "PKU001_S002_E006";
    String AMOUNT_INPUT = "PKU001_S002_E007";
    String VARIABLE_SYMBOL_INPUT = "PKU001_S002_E008";
    String CONSTANT_SYMBOL_INPUT = "PKU001_S002_E009";
    String SPECIFIC_SYMBOL_INPUT = "PKU001_S002_E010";
    String MESSAGE_INPUT = "PKU001_S002_E011";
    String TODAY_BUTTON = "PKU001_S002_B005";
    String PRIORITY_PAYMENT_CHECKBOX = "PKU001_S002_H002_1";
    String SAVE_BUTTON = "PKU001_S002_B002";
    String CREATED_TRANSACTIONS_TABLE_CELLS_XPATH = "//table[@id='PKU001_S002_G001_UfoTable']//td[contains(@class, 'ufo-Table-BodyCell')]";
    String FIRST_PAYMENT_ORDER_ID_XPATH = "//table[@id='PKU001_S002_G001_UfoTable']//td[4]";

    @TypeInto(DEBTOR_ACC_NUMBER_INPUT)
    PKU001_S002_CreatePaymentOrderPage fillDebtorAccNumber(String debtorAccountNumber);

    @TypeInto(CREDITOR_ACC_NUMBER_INPUT)
    PKU001_S002_CreatePaymentOrderPage fillCreditorAccNumber(String creditorAccountNumber);

    @TypeInto(CREDITOR_ACC_BANK_CODE_INPUT)
    PKU001_S002_CreatePaymentOrderPage fillCreditorAccBankCode(String creditorAccountBankCode);

    @TypeInto(value = AMOUNT_INPUT, andWait = @Wait(explicitWaitSeconds = 1))
    PKU001_S002_CreatePaymentOrderPage fillAmountInput(String amount);

    @TypeIntos({@TypeInto(VARIABLE_SYMBOL_INPUT), @TypeInto(CONSTANT_SYMBOL_INPUT),
            @TypeInto(SPECIFIC_SYMBOL_INPUT), @TypeInto(MESSAGE_INPUT)})
    PKU001_S002_CreatePaymentOrderPage fillOptionalData(String variableSymbol, String constantSymbol,
                                                        String specificSymbol, String message);

    @Click(TODAY_BUTTON)
    PKU001_S002_CreatePaymentOrderPage clickTodayButton();

    @Click(PRIORITY_PAYMENT_CHECKBOX)
    PKU001_S002_CreatePaymentOrderPage clickPriorityPaymentCheckbox();

    @Click(SAVE_BUTTON)
    PSP004_S001_PrintPage clickSaveButton();

    @CheckElementPresent(value = CREATED_TRANSACTIONS_TABLE_CELLS_XPATH, by = Lookup.XPATH)
    PKU001_S002_CreatePaymentOrderPage checkPresentCreatedTransactions();


    @CustomAction
    default PKU001_S002_CreatePaymentOrderPage checkNotSavingNotFilledForm() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String alertMessage = "Pole Datum splatnosti musí být vyplněno.\nNení vyplněno datum splatnosti.";
        endpoint.click(() -> SAVE_BUTTON);
        Assertions.assertEquals(alertMessage, endpoint.getAlertText(1));
        endpoint.acceptAlert(1);
        return null;
    }

    @CheckElementContent(value = FIRST_PAYMENT_ORDER_ID_XPATH, by = Lookup.XPATH)
    PKU001_S002_CreatePaymentOrderPage checkFirstOrderPaymentId(String paymentOrderId);

}
