package cz.moneta.test.dsl.ufo.banka.pages.products.current.account;

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.products.current.account.ZPL006_S002_ListOfForeignPaymentsPage.NEW_PAYMENT_BUTTON;
import static cz.moneta.test.dsl.ufo.banka.pages.products.current.account.ZPL006_S002_ListOfForeignPaymentsPage.ZPL006_S002_PAGE_LABEL_XPATH;

@Wait(value = ZPL006_S002_PAGE_LABEL_XPATH, by = Lookup.XPATH, waitSecondsForElement = 90)
@Wait(value = {NEW_PAYMENT_BUTTON}, waitSecondsForElement = 90)
public interface ZPL006_S002_ListOfForeignPaymentsPage extends WebFlow<ZPL006_S002_ListOfForeignPaymentsPage>, StoreAccessor {

    String ZPL006_S002_PAGE_LABEL_XPATH = "//div[text()='ZPL006_S002']";
    String NEW_PAYMENT_BUTTON = "ZPL006_S002_B001";
    String PAYMENT_XPATH = "//table[@id='ZPL006_S002_G001_UfoTable']//td[text()='%s']";
    String EDIT_BUTTON = "ZPL006_S002_B005";
    String PAYMENT_AMOUNT_XPATH = PAYMENT_XPATH + "/following-sibling::td[3]";
    String CANCEL_PAYMENT_BUTTON = "ZPL006_S002_B006";

    @Click(NEW_PAYMENT_BUTTON)
    ZPL006_S001_ForeignPaymentInputPage clickNewPayment();

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

    @CheckElementPresent(value = PAYMENT_XPATH, by = Lookup.XPATH, isStringDynamicXpath = true)
    ZPL006_S002_ListOfForeignPaymentsPage checkPresentCreatedTransaction(String paymentId);

    @Click(value = PAYMENT_XPATH, by = Lookup.XPATH, isStringDynamicXpath = true)
    ZPL006_S002_ListOfForeignPaymentsPage clickPayment(String paymentId);

    @Click(EDIT_BUTTON)
    @AcceptAlert(waitSecondsForAlert = 5, expectedAlertText = "Jedná se o editaci platby. " +
            "Kurzovní lístek se mohl od doby zadání změnit. " +
            "Ekvivalent platby je tedy pouze orientační - podle aktuálního kurzovního lístku.")
    ZPL006_S004_EditSmoothPaymentPage clickEditAndAcceptAlert();

    @CheckElementContent(value = PAYMENT_AMOUNT_XPATH, by = Lookup.XPATH, isStringDynamicXpath = true)
    ZPL006_S002_ListOfForeignPaymentsPage checkPaymentAmount(String paymentId, String expectedAmount);

    @Click(CANCEL_PAYMENT_BUTTON)
    ZPL006_S005_CancelSmoothPaymentPage clickCancelPayment();


}
