package cz.moneta.test.dsl.forte.components;

import cz.moneta.test.dsl.forte.pages.appointments.*;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.forte.ForteEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.forte.components.AppointmentsMenu.LEFT_PANEL;

@Wait(LEFT_PANEL)
public interface AppointmentsMenu extends RoleSelection<AppointmentsMainPage>, Builder, StoreAccessor {

    // Menu for ForteRoles.APP_ADMIN
    String ROLES_ADMINISTRATION = LEFT_PANEL + "//a[@href='/appointments/role/']";
    String PRODUCT_TYPES = LEFT_PANEL + "//a[@href='/appointments/producttype/']";
    String LIST_OF_EMPTY_SLOTS = LEFT_PANEL + "//a[@href='/appointments/branchplaces/']";

    // Menu for ForteRoles.BANKER
    String APPOINTMENTS_NOT_ASSIGNED = "//a[@href='/appointments/notassigned/']";
    String BRANCH_SELECT = "//select[@id='frmselectBranchSimpleForm-branch']";
    String BRANCH_SELECT_OPTION = BRANCH_SELECT + "//option[contains(text(),'%s')]";
    String BRANCH_SELECT_ADD_OM = BRANCH_SELECT + "//option[@value='add']";

    // Menu for ForteRoles.APP_ADMIN
    @Click(ROLES_ADMINISTRATION)
    RolesAdministrationPage clickRolesAdministration();

    @Click(PRODUCT_TYPES)
    ProductTypesPage clickProductTypes();

    @Click(LIST_OF_EMPTY_SLOTS)
    ListOfEmptySlotsPage clickListOfEmptySlots();

    // Menu for ForteRoles.BANKER
    @Click(APPOINTMENTS_NOT_ASSIGNED)
    NotSignedAppointments clickNotAssignedAppointments();

    @Click(BRANCH_SELECT)
    @Click(value = BRANCH_SELECT_OPTION, isStringDynamicXpath = true)
    AppointmentsMainPage selectOm(String omName);

    @CustomAction
    default SelectOMPage clickAddOM() {
        ForteEndpoint endpoint = getEndpoint(ForteEndpoint.class);
        endpoint.click(() -> BRANCH_SELECT);
        endpoint.waitForElementsToLoad(5, BRANCH_SELECT_ADD_OM);
        endpoint.click(() -> BRANCH_SELECT_ADD_OM);
        return null;
    }
}