package cz.moneta.test.dsl.payment_engine;

import cz.moneta.test.dsl.payment_engine.home.PaymentEngineHomePage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.payment_engine.PaymentEngineEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.payment_engine.PaymentEngineDetailAccountPage.*;

@Wait({BUTTON_DETAIL_FOR_ACCOUNT_ID, ACCOUNT_ITEM_XPATH, HISTORY_OF_ACCOUNT_ITEM})
public interface PaymentEngineDetailAccountPage extends WebFlow<PaymentEngineDetailAccountPage>, StoreAccessor {
    String BUTTON_DETAIL_FOR_ACCOUNT_ID = "//button[@class='x-btn-text' and contains(text(), 'Detail pro Účet ID')]";
    String ACCOUNT_ITEM_XPATH = "//span[text()='Účet']";
    String HISTORY_OF_ACCOUNT_ITEM = "//span[text()='Historie účtu']";
    String DISPO_BALANCE = "//input[@name='dispoBalance']";
    String DISPO_BALANCE_VALUE_KEY = "DISPO_BALANCE_VALUE";
    String ACC_BALANCE = "//input[@name='accBalance']";
    String ACC_BALANCE_VALUE_KEY = "ACC_BALANCE_VALUE";
    String ACCOUNT_STATE = "//input[@name='status']";
    String CLOSE_TAB = "//a[@class = 'x-tab-strip-close']";

    @CustomAction
    default PaymentEngineDetailAccountPage getDispoBalance() {
        PaymentEngineEndpoint endpoint = getEndpoint(PaymentEngineEndpoint.class);
        String value = endpoint.getAttribute(DISPO_BALANCE, Lookup.XPATH, "value");
        storeGlobal(DISPO_BALANCE_VALUE_KEY, value);
        return null;
    }

    @CustomAction
    default PaymentEngineDetailAccountPage getAccBalance() {
        PaymentEngineEndpoint endpoint = getEndpoint(PaymentEngineEndpoint.class);
        String value = endpoint.getAttribute(ACC_BALANCE, Lookup.XPATH, "value");
        storeGlobal(ACC_BALANCE_VALUE_KEY, value);
        return null;
    }

    @CustomAction
    default PaymentEngineDetailAccountPage getAccountState() {
        PaymentEngineEndpoint endpoint = getEndpoint(PaymentEngineEndpoint.class);
        String value = endpoint.getAttribute(ACCOUNT_STATE, Lookup.XPATH, "value");
        storeGlobal(ACCOUNT_STATE, value);
        return null;
    }

    @Click(value = CLOSE_TAB, andWait = @Wait(explicitWaitSeconds = 1))
    PaymentEngineHomePage closeTab();
}