package cz.moneta.test.dsl.payment_engine;

import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.payment_engine.PaymentEngineReservationPage.CREATE_BUTTON;
import static cz.moneta.test.dsl.payment_engine.PaymentEngineReservationPage.EDIT_BUTTON;

@Wait({CREATE_BUTTON, EDIT_BUTTON})
public interface PaymentEngineReservationPage extends WebFlow<PaymentEngineReservationPage> {
    String CREATE_BUTTON = "//a[text()='Založit']";
    String EDIT_BUTTON = "//a[text()='Editovat']";
    String DELETE_BUTTON = "//a[text()='Vymazat']";
    String FIST_MANUAL_RESERVATION = "(//div[contains(@class,'x-grid3-row')]//div[@class='x-grid3-cell-inner x-grid3-col-3'][text() = 'M'])[1]";
    String LAST_RESERVATION_DATE_XPATH = "//div[contains(@class,'x-grid3-row')][position()=last()]//div[text() = \"PDNG\"]/../following-sibling::td[contains(@class, 'x-grid3-td-11')]/div";
    String LAST_RESERVATION_DATE_KEY = "LAST_RESERVATION_DATE_KEY";
    String SELECTED_RESERVATION_ID_XPATH = "//*[contains(@class,'x-grid3-row    x-grid3-row-selected')]//div[@class='x-grid3-cell-inner x-grid3-col-1'][string-length(text()) > 10]";
    String SELECTED_RESERVATION_ID_KEY = "SELECTED_RESERVATION_ID_KEY";
    String CHECK_SELECTED_RESERVATION_DATA_PATH = "//*[contains(@class,'x-grid3-row-selected')]//*[contains(text(),'%s')]";

    @Click(CREATE_BUTTON)
    PaymentEngineCreateReservationPage clickCreateOnButton();

    @StoreElementContent(storeKey = LAST_RESERVATION_DATE_KEY, value = LAST_RESERVATION_DATE_XPATH, by = Lookup.XPATH)
    PaymentEngineReservationPage getLastReservationDate();

    @Click(EDIT_BUTTON)
    PaymentEngineEditReservationPage clickOnEditButton();

    @Click(DELETE_BUTTON)
    PaymentEngineEditReservationPage clickOnDeleteButton();

    @CheckElementPresent(value = CHECK_SELECTED_RESERVATION_DATA_PATH, isStringDynamicXpath = true)
    PaymentEngineReservationPage checkSelectedReservationAmount(String amount);

    @StoreElementContent(storeKey = SELECTED_RESERVATION_ID_KEY, value = SELECTED_RESERVATION_ID_XPATH, by = Lookup.XPATH)
    PaymentEngineReservationPage getSelectedReservationId();

    @Click(FIST_MANUAL_RESERVATION)
    PaymentEngineReservationPage clickOnFirstManualReservation();
}
