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

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


public interface PaymentEngineSearchTransactionDetailLifeCycle extends WebFlow<PaymentEngineSearchTransactionDetailLifeCycle>, StoreAccessor {
    String HD21 = "//div[contains(text(), 'HD:21 kryti odchozi')]";
    String SECOND_ROW_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 SECOND_ROW_TRANSACTION_AMOUNT_KEY = "SECOND_ROW_TRANSACTION_AMOUNT_KEY";
    String ROW_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 SECOND_ROW_TRANSACTION_ID_XPATH = "(" + ROW_TRANSACTION_ID_XPATH + ")[1]";
    String SECOND_ROW_TRANSACTION_ID_KEY = "SECOND_ROW_TRANSACTION_ID_KEY";
    String THIRD_ROW_TRANSACTION_ID_XPATH = "(" + ROW_TRANSACTION_ID_XPATH + ")[2]";
    String THIRD_ROW_TRANSACTION_ID_KEY = "THIRD_ROW_TRANSACTION_ID_KEY";
    String FORTH_ROW_TRANSACTION_ID_XPATH = "(" + ROW_TRANSACTION_ID_XPATH + ")[3]";
    String FORTH_ROW_TRANSACTION_ID_KEY = "FORTH_ROW_TRANSACTION_ID_KEY";
    String FIFTH_ROW_TRANSACTION_ID_XPATH = "(" + ROW_TRANSACTION_ID_XPATH + ")[4]";
    String FIFTH_ROW_TRANSACTION_ID_KEY = "FIFTH_ROW_TRANSACTION_ID_KEY";
    String SIXTH_ROW_TRANSACTION_ID_XPATH = "(" + ROW_TRANSACTION_ID_XPATH + ")[5]";
    String SIXTH_ROW_TRANSACTION_ID_KEY = "SIXTH_ROW_TRANSACTION_ID_KEY";
    String TRANSACTION_BY_TYPE_ID_KEY = "TRANSACTION_BY_TYPE_ID_KEY";
    String TRANSACTION_BY_TYPE_ID_XPATH = "(//div[text()='%s']/../preceding-sibling::td)[3]";
    String RECORD_DETAIL = "//div[contains(@class,'x-hide-offsets')][last()]/following-sibling::div//a[text() = 'Detail']";
    String REFRESH_BUTTON = "(//button[contains(@class,'loading')])[2]";
    String REFRESH_BUTTON_LIFE_CYCLE = "(//button[contains(@class,'loading')])[4]";
    String CLOSE_TAB = "//a[@class='x-tab-strip-close']";

    @Click(HD21)
    PaymentEngineSearchTransactionDetailLifeCycle clickOnHD21();

    @Click(RECORD_DETAIL)
    PaymentEngineSearchTransactionDetail clickOnHD21Detail();

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

    @CustomAction
    default PaymentEngineSearchTransactionDetailLifeCycle waitForRowStatus(Harness harness, String transactionData, TransactionReasonPAE status) {
        PaymentEngineUtils.waitForElementPresence(harness, String.format("//div[text()='" + transactionData
                + "']/../following-sibling::td/div[text()='%s']", status.getStatus()), REFRESH_BUTTON_LIFE_CYCLE);
        return null;
    }

    @CustomAction
    default PaymentEngineSearchTransactionDetailLifeCycle waitForFifthRow(Harness harness) {
        PaymentEngineUtils.waitForElementPresence(harness, FIFTH_ROW_TRANSACTION_ID_XPATH, REFRESH_BUTTON_LIFE_CYCLE);
        return null;
    }

    @StoreElementContent(storeKey = SECOND_ROW_TRANSACTION_ID_KEY, value = SECOND_ROW_TRANSACTION_ID_XPATH, by = Lookup.XPATH)
    PaymentEngineSearchTransactionDetailLifeCycle storeSecondRowTransactionId();

    @StoreElementContent(storeKey = SECOND_ROW_TRANSACTION_AMOUNT_KEY, value = SECOND_ROW_TRANSACTION_AMOUNT_XPATH, by = Lookup.XPATH)
    PaymentEngineSearchTransactionDetailLifeCycle storeSecondRowTransactionAmount();

    @StoreElementContent(storeKey = THIRD_ROW_TRANSACTION_ID_KEY, value = THIRD_ROW_TRANSACTION_ID_XPATH, by = Lookup.XPATH)
    PaymentEngineSearchTransactionDetailLifeCycle storeThirdRowTransactionId();

    @StoreElementContent(storeKey = FORTH_ROW_TRANSACTION_ID_KEY, value = FORTH_ROW_TRANSACTION_ID_XPATH, by = Lookup.XPATH)
    PaymentEngineSearchTransactionDetailLifeCycle storeForthRowTransactionId();

    @StoreElementContent(storeKey = FIFTH_ROW_TRANSACTION_ID_KEY, value = FIFTH_ROW_TRANSACTION_ID_XPATH, by = Lookup.XPATH)
    PaymentEngineSearchTransactionDetailLifeCycle storeFifthRowTransactionId();

    @StoreElementContent(storeKey = SIXTH_ROW_TRANSACTION_ID_KEY, value = SIXTH_ROW_TRANSACTION_ID_XPATH, by = Lookup.XPATH)
    PaymentEngineSearchTransactionDetailLifeCycle storeSixthRowTransactionId();

    @StoreElementContent(storeKey = TRANSACTION_BY_TYPE_ID_KEY, value = TRANSACTION_BY_TYPE_ID_XPATH, by = Lookup.XPATH, isStringDynamicXpath = true)
    PaymentEngineSearchTransactionDetailLifeCycle storeTransactionIdByType(String transactionType);

    @Click(SECOND_ROW_TRANSACTION_ID_XPATH)
    PaymentEngineSearchTransactionDetailLifeCycle clickOnSecondRowTransaction();

    @Click(RECORD_DETAIL)
    PaymentEngineSearchTransactionDetail clickOnSecondRowTransactionDetail();

    @Click(CLOSE_TAB)
    PaymentEngineHomePage closeTab();
}
