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 PaymentEngineSearchPageLifeCycle extends WebFlow<PaymentEngineSearchPageLifeCycle>, StoreAccessor {
    String EQUIVALENT_AMOUNT_KEY = "EQUIVALENT_AMOUNT_KEY";
    String EQUIVALENT_AMOUNT_CZK_XPATH = "(//div[text()='CZK']/../preceding-sibling::td[contains(@class, 'x-grid3-td-11')]/div)[%s]";
    String EQUIVALENT_AMOUNT_EUR_XPATH = "//div[text()='EUR']/../preceding-sibling::td[contains(@class, 'x-grid3-td-11')]/div";
    String REFRESH_BUTTON_LIFE_CYCLE = "//div[@id='Vyhledávání']//div[2]/div/div/div/div/div/div[2]//div[2]//div[@class='x-toolbar x-small-editor']//button[@class='x-btn-text x-tbar-loading']";
    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 CLOSE_TAB = "//a[@class='x-tab-strip-close']";

    @Click(value = REFRESH_BUTTON_LIFE_CYCLE)
    PaymentEngineSearchPageLifeCycle refreshLifeCycle();

    @Wait(explicitWaitSeconds = 3)
    PaymentEngineSearchPageLifeCycle wait3sec();

    @Wait(explicitWaitSeconds = 5)
    PaymentEngineSearchPageLifeCycle wait5sec();

    @StoreElementContent(storeKey = EQUIVALENT_AMOUNT_KEY, value = EQUIVALENT_AMOUNT_CZK_XPATH, isStringDynamicXpath = true, by = Lookup.XPATH)
    PaymentEngineSearchPageLifeCycle storeEquivalentAmountCzk(String row);

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

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

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

    @Click(CLOSE_TAB)
    PaymentEngineHomePage closeTab();
}
