package cz.moneta.test.dsl.ufo.operations.ufoOperations;

import cz.moneta.test.dsl.ufo.operations.search.OPS001_S001_ClientSearchPageUfoOperations;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.ufo.UfoEndpoint;
import cz.moneta.test.harness.support.web.*;

import static cz.moneta.test.dsl.ufo.operations.shared.SharedElements.LOAD_IMG_DIV_CLASS;
import static cz.moneta.test.dsl.ufo.operations.ufoOperations.SET701_S001_AuthorizationOverview.SETTINGS_HEADING_LABEL;

@Wait(value = SETTINGS_HEADING_LABEL, until = Until.VISIBLE)
public interface SET701_S001_AuthorizationOverview extends WebFlow<SET701_S001_AuthorizationOverview>, StoreAccessor {
    String SETTINGS_HEADING_LABEL = "SET701_S001_L001";
    String EMPLOYEE_ACCESS_XPATH = "//span[contains(text(), 'OPS eArch Zam')]";
    String OPS_CALLCENTRUM_BASIS_XPATH = "//span[contains(text(), 'Operations CallCentrum Zaklad')]";
    String OPS_CALLCENTRUM_FRAUD_ACCESS_XPATH = "//span[contains(text(), 'Operations CallCentrum Fraud')]";
    String SAVE_CHANGES_PRIVILAGES_BUTTON = "SET701_S001_B001";

    @CustomAction
    default SET701_S001_AuthorizationOverview doubleClickEmployeeAccess() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementsToLoad(5, Lookup.XPATH, Until.VISIBLE, EMPLOYEE_ACCESS_XPATH);
        endpoint.click(() -> EMPLOYEE_ACCESS_XPATH, Lookup.XPATH);
        endpoint.jsDoubleClick(() -> EMPLOYEE_ACCESS_XPATH, Lookup.XPATH);
        endpoint.waitForElementsToLoad(5, Lookup.CLASSNAME, Until.GONE, LOAD_IMG_DIV_CLASS);
        return null;
    }

    @CustomAction
    default SET701_S001_AuthorizationOverview doubleClickOpsCallcentrumBasisAccess() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementsToLoad(5, Lookup.XPATH, Until.VISIBLE, OPS_CALLCENTRUM_BASIS_XPATH);
        endpoint.click(() -> OPS_CALLCENTRUM_BASIS_XPATH, Lookup.XPATH);
        endpoint.jsDoubleClick(() -> OPS_CALLCENTRUM_BASIS_XPATH, Lookup.XPATH);
        endpoint.waitForElementsToLoad(5, Lookup.CLASSNAME, Until.GONE, LOAD_IMG_DIV_CLASS);
        return null;
    }

    @CustomAction
    default SET701_S001_AuthorizationOverview doubleClickOpsCallcentrumFraudAccess() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.waitForElementsToLoad(5, Lookup.XPATH, Until.VISIBLE, OPS_CALLCENTRUM_FRAUD_ACCESS_XPATH);
        endpoint.click(() -> OPS_CALLCENTRUM_FRAUD_ACCESS_XPATH, Lookup.XPATH);
        endpoint.jsDoubleClick(() -> OPS_CALLCENTRUM_FRAUD_ACCESS_XPATH, Lookup.XPATH);
        endpoint.waitForElementsToLoad(5, Lookup.CLASSNAME, Until.GONE, LOAD_IMG_DIV_CLASS);
        return null;
    }

    @Click(SAVE_CHANGES_PRIVILAGES_BUTTON)
    OPS001_S001_ClientSearchPageUfoOperations clickSaveChangeOfPrivilages();
}
