package cz.moneta.test.dsl.newib.accounts;

import cz.moneta.test.dsl.newib.NewIbPageFlow;
import cz.moneta.test.dsl.newib.components.HorizontalMainMenu;
import cz.moneta.test.dsl.newib.components.VerticalMainMenu;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ib.NewIbEndpoint;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Lookup;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.newib.accounts.HistoryTab.*;

@Wait({ALL_TAB_XPATH, COMMING_TAB_XPATH, OUTGOING_TAB_XPATH, BLOCKING_TAB_XPATH, ENTERING_TAB_XPATH, STANDING_ORDER_TAB_XPATH, OUTSTANDING_TAB_XPATH})
public interface HistoryTab extends NewIbPageFlow<HistoryTab>, AccountsTabs, HorizontalMainMenu, VerticalMainMenu, StoreAccessor {

    // History pills menu
    String ALL_TAB_XPATH = "//button[text()='Vše']";
    String COMMING_TAB_XPATH = "//button[text()='Příchozí']";
    String OUTGOING_TAB_XPATH = "//button[text()='Odchozí']";
    String BLOCKING_TAB_XPATH = "//button[text()='Blokace']";
    String ENTERING_TAB_XPATH = "//button[text()='Zadané']";
    String STANDING_ORDER_TAB_XPATH = "//button[text()='Trvalé příkazy']";
    String OUTSTANDING_TAB_XPATH = "//button[text()='Neprovedené']";

    // Items on history tab page
    String SEARCH_FIELD_XPATH = "//input[@data-testid='history-fulltext']";
    String ADVANCE_SEARCH_BUTTON_XPATH = "//button[@data-testid='advanced-search']";
    String MORE_TRANSACTIONS_BUTTON_XPATH = "//button[@data-testid='show-more-transactions']";
    String TRANSACTION_XPATH = "//span[text()='%s']//following-sibling::div[text()='%s'][1]";
    String TRANSACTION_WITH_CONTAINS_XPATH = "//span[text()='%s']//following-sibling::div[contains(text(), '%s')][1]";

    @CustomAction
    default CurrentAccountPage checkTransaction(String toAccount, String amount) {
        NewIbEndpoint newIbEndpoint = getEndpoint(NewIbEndpoint.class);
        newIbEndpoint.isElementPresent(String.format(TRANSACTION_XPATH, toAccount, amount), Lookup.XPATH);
        return null;
    }

    @CustomAction
    default CurrentAccountPage checkCreditPaymentTransaction(String recipientPhoneNumber, String amount) {
        NewIbEndpoint newIbEndpoint = getEndpoint(NewIbEndpoint.class);
        newIbEndpoint.isElementPresent(String.format(TRANSACTION_WITH_CONTAINS_XPATH, recipientPhoneNumber, amount), Lookup.XPATH);
        return null;
    }
}
