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.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.*;


public interface PaymentEngineMonitoringInstanceLifeCycle extends WebFlow<PaymentEngineMonitoringInstanceLifeCycle>, StoreAccessor {
    String CHECK_XCT_STATUS = "//tr[td[div[text() = 'xCT prichozi']]]//*[contains(text(),'%s')]";
    String FEE_AMOUNT_KEY = "FEE_AMOUNT";
    String FEE_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/following-sibling::div//div[@class='x-grid3-cell-inner x-grid3-col-8']";
    String TRANSACTION_TYPE_FEE = "//div[@class='x-panel-body x-panel-body-noheader x-border-layout-ct']//div[contains(@class,'x-grid3-row-selected')]/following-sibling::div/following-sibling::div//div[@class='x-grid3-cell-inner x-grid3-col-5']";
    String FEE_TRANSACTION_ID_KEY = "FEE_TRANSACTION_ID";
    String FEE_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/following-sibling::div//div[@class='x-grid3-cell-inner x-grid3-col-2']";
    String INGOING_TRANSACTION_ID_KEY = "INGOING_TRANSACTION_ID";
    String INGOING_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 INGOING_HD11_TRANSACTION_ID_KEY = "INGOING_HD11_TRANSACTION_ID";
    String INGOING_HD11_TRANSACTION_ID_XPATH = "//tr[td[div[text() = 'HD:11 Inicialni prichozi']]]/td[@class='x-grid3-col x-grid3-cell x-grid3-td-2 ']/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')]/following-sibling::div//div[@class='x-grid3-cell-inner x-grid3-col-8']";
    String CLOSE_TAB = "//a[@class = 'x-tab-strip-close']";
    String REFRESH_BUTTON = "(//div[@class= 'x-panel-body x-panel-body-noheader x-border-layout-ct']//button[contains(@class,'loading')])[2]";

    @CustomAction
    default PaymentEngineMonitoringInstanceLifeCycle waitForHd11Status(Harness harness, String status) {
        PaymentEngineUtils.waitForElementPresence(harness, String.format("//tr[td[div[text() = 'HD:11 Inicialni prichozi']]]/td[@class='x-grid3-col x-grid3-cell x-grid3-td-7 ']/div[contains(text(),'%s')]", status), REFRESH_BUTTON);
        return null;
    }

    @CustomAction
    default PaymentEngineMonitoringInstanceLifeCycle waitForXctStatus(Harness harness, String status) {
        PaymentEngineUtils.waitForElementPresence(harness, String.format("//tr[td[div[text() = 'xCT prichozi']]]//*[contains(text(),'%s')]", status), REFRESH_BUTTON);
        return null;
    }

    @StoreElementContent(storeKey = FEE_AMOUNT_KEY, value = FEE_AMOUNT_XPATH, by = Lookup.XPATH)
    PaymentEngineMonitoringInstanceLifeCycle storeFeeAmount();

    @CheckElementContent(TRANSACTION_TYPE_FEE)
    PaymentEngineMonitoringInstanceLifeCycle checkTransactionTypeFee(String transactionTypeFee);

    @StoreElementContent(storeKey = FEE_TRANSACTION_ID_KEY, value = FEE_TRANSACTION_ID_XPATH, by = Lookup.XPATH)
    PaymentEngineMonitoringInstanceLifeCycle storeFeeTransactionId();

    @StoreElementContent(storeKey = INGOING_TRANSACTION_ID_KEY, value = INGOING_TRANSACTION_ID_XPATH, by = Lookup.XPATH)
    PaymentEngineMonitoringInstanceLifeCycle storeIngoingTransactionId();

    @StoreElementContent(storeKey = INGOING_HD11_TRANSACTION_ID_KEY, value = INGOING_HD11_TRANSACTION_ID_XPATH, by = Lookup.XPATH)
    PaymentEngineMonitoringInstanceLifeCycle storeIngoingHd11TransactionId();

    @CheckElementContent(TRANSACTION_AMOUNT_XPATH)
    PaymentEngineMonitoringInstanceLifeCycle checkTransactionAmount(String amount);

    @Click(value = CLOSE_TAB, andWait = @Wait(value = CLOSE_TAB, until = Until.GONE))
    PaymentEngineHomePage closeTab();
}
