package cz.moneta.test.dsl.cashman.pages;

import cz.moneta.test.dsl.cashman.pages.menu_OM.CashmanOMCzkPragueList;
import cz.moneta.test.dsl.cashman.pages.menu_OM.CashmanOMNewOrderPage;
import cz.moneta.test.dsl.cashman.pages.menu_deposit.CashmanDepositCzkPrague;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.cashman.CashmanEndpoint;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Wait;
import cz.moneta.test.harness.support.web.WebFlow;

import static cz.moneta.test.dsl.cashman.pages.CashmanHomePage.LOGO;

@Wait(LOGO)
public interface CashmanHomePage extends WebFlow<CashmanHomePage>, StoreAccessor {
    String LOGO = "//img[ @alt='CashMan']";
    String OM = "//a[@class='nav-link dropdown-toggle'][contains(text(),' OM')]";
    String OM_NEW_ORDER = "//a[@href='/nova-objednavka-om']";
    String OM_CZK_PRAGUE = "//a[@href='/om-orders?idDeposit=1&orderEditType=CZK']";
    String DEPOSIT = "//a[@class='nav-link dropdown-toggle'][contains(text(),' Depozitum')]";
    String DEPOSIT_CZK_PRAGUE = "//a[@href='/depo-CZK?idDeposit=1']";

    @CustomAction
    default void clickOnItem(String partOfMenuXpath, String itemXpath) {
        CashmanEndpoint endpoint = getEndpoint(CashmanEndpoint.class);
        endpoint.click(() -> partOfMenuXpath);
        endpoint.click(() -> itemXpath);
    }

    @CustomAction
    default CashmanOMNewOrderPage clickOnOMAndChooseNewOrder() {
        clickOnItem(OM, OM_NEW_ORDER);
        return null;
    }

    @CustomAction
    default CashmanOMCzkPragueList clickOnOMAndChooseCzkPrague() {
        clickOnItem(OM, OM_CZK_PRAGUE);
        return null;
    }

    @CustomAction
    default CashmanDepositCzkPrague clickOnDepositAndChooseCzkPrague() {
        clickOnItem(DEPOSIT, DEPOSIT_CZK_PRAGUE);
        return null;
    }
}