package cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_monitoring;

import cz.moneta.test.dsl.Harness;
import cz.moneta.test.dsl.payment_engine.enums.TransactionReasonPAE;
import cz.moneta.test.dsl.payment_engine.home.PaymentEngineHomePage;
import cz.moneta.test.dsl.payment_engine.utils.PaymentEngineUtils;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_monitoring.PaymentEngineMonitoringInstanceFileRecords.FIRST_ROW;
import static cz.moneta.test.dsl.payment_engine.parts_of_menu.menu_monitoring.PaymentEngineMonitoringInstanceFileRecords.REFRESH_BUTTON;

@Wait({REFRESH_BUTTON, FIRST_ROW})
public interface PaymentEngineMonitoringInstanceFileRecords extends WebFlow<PaymentEngineMonitoringInstanceFileRecords>, StoreAccessor {

    String TRANSACTION_ID_KEY = "TRANSACTION_ID";
    String TRANSACTION_ID_XPATH = "//div[@class='x-panel-body x-panel-body-noheader x-border-layout-ct']//div[contains(@class,'x-grid3-row-selected')]//div[@class='x-grid3-cell-inner x-grid3-col-2']";
    String OUTGOING_TRANSACTION_ID_KEY = "OUTGOING_TRANSACTION_ID";
    String OUTGOING_TRANSACTION_ID_XPATH = "//div[@class='x-panel-body x-panel-body-noheader x-border-layout-ct']//div[contains(@class,'x-grid3-row-selected')]/following-sibling::div//div[@class='x-grid3-cell-inner x-grid3-col-2']";
    String FIRST_ROW = "//div[contains(@class,'x-grid3-row-selected')]";
    String CLOSE_TAB = "//a[@class='x-tab-strip-close']";
    String LIFECYCLE_BUTTON = "//a[text()='Životní cyklus']";
    String EQUIVALENT_AMOUNT_KEY = "EQUIVALENT_AMOUNT";
    String FIRST_ROW_AMOUNT_KEY = "FIRST_ROW_AMOUNT";
    String SECOND_ROW_AMOUNT_KEY = "SECOND_ROW_AMOUNT";
    String FIRST_ROW_AMOUNT_XPATH = "//div[@class='x-panel-body x-panel-body-noheader x-border-layout-ct']//div[contains(@class,'x-grid3-row-selected')]/following-sibling::div//div[@class='x-grid3-cell-inner x-grid3-col-8']";
    String SECOND_ROW_AMOUNT_XPATH = "//div[@class='x-panel-body x-panel-body-noheader x-border-layout-ct']//div[contains(@class,'x-grid3-row-selected')]//div[@class='x-grid3-cell-inner x-grid3-col-8']";
    String EQUIVALENT_AMOUNT_CZK_XPATH = "//div[@class='x-grid3-scroller']//div[text() = 'CZK']/../preceding-sibling::td[contains(@class, 'x-grid3-td-11')]/div";
    String EQUIVALENT_AMOUNT_EUR_XPATH = "//div[@class='x-grid3-scroller']//div[text() = 'EUR']/../following-sibling::td[contains(@class, 'x-grid3-td-10')]/div";
    String TRANSACTION_AMOUNT_XPATH = "//div[@class='x-panel-body x-panel-body-noheader x-border-layout-ct']//div[contains(@class,'x-grid3-row-selected')]//div[@class='x-grid3-cell-inner x-grid3-col-8']";
    String REFRESH_BUTTON = "//div[@class= 'x-panel-body x-panel-body-noheader x-border-layout-ct']//button[contains(@class,'loading')]";

    @StoreElementContent(storeKey = TRANSACTION_ID_KEY, value = TRANSACTION_ID_XPATH, by = Lookup.XPATH)
    PaymentEngineMonitoringInstanceFileRecords storeTransactionId();

    @StoreElementContent(storeKey = OUTGOING_TRANSACTION_ID_KEY, value = OUTGOING_TRANSACTION_ID_XPATH, by = Lookup.XPATH)
    PaymentEngineMonitoringInstanceFileRecords storeOutgoingTransactionId();

    @CustomAction
    default PaymentEngineMonitoringInstanceFileRecords waitForStatus(Harness harness, TransactionReasonPAE status) {
        PaymentEngineUtils.waitForElementPresence(harness, String.format("//*[contains(@class,'x-grid3-body')]//div[text() = '%s']", status.getStatus()), REFRESH_BUTTON);
        return null;
    }

    @Click(CLOSE_TAB)
    PaymentEngineHomePage closeTab();

    @Click(LIFECYCLE_BUTTON)
    PaymentEngineMonitoringInstanceLifeCycle clickOnLifeCycleButton();

    @StoreElementContent(storeKey = FIRST_ROW_AMOUNT_KEY, value = FIRST_ROW_AMOUNT_XPATH, by = Lookup.XPATH)
    PaymentEngineMonitoringInstanceFileRecords storeFirstRowAmount();

    @StoreElementContent(storeKey = SECOND_ROW_AMOUNT_KEY, value = SECOND_ROW_AMOUNT_XPATH, by = Lookup.XPATH)
    PaymentEngineMonitoringInstanceFileRecords storeSecondRowAmount();

    @StoreElementContent(storeKey = EQUIVALENT_AMOUNT_KEY, value = EQUIVALENT_AMOUNT_CZK_XPATH, by = Lookup.XPATH)
    PaymentEngineMonitoringInstanceFileRecords storeEquivalentAmountCzk();

    @StoreElementContent(storeKey = EQUIVALENT_AMOUNT_KEY, value = EQUIVALENT_AMOUNT_EUR_XPATH, by = Lookup.XPATH)
    PaymentEngineMonitoringInstanceFileRecords storeEquivalentAmountEur();

    @CheckElementContent(TRANSACTION_AMOUNT_XPATH)
    PaymentEngineMonitoringInstanceFileRecords checkTransactionAmount(String amount);
}
