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

import cz.moneta.test.dsl.hypos.components.Menu;
import cz.moneta.test.dsl.hypos.pages.cadaster.CadasterNavigationPage;
import cz.moneta.test.dsl.hypos.pages.contract.hyposutils.TestDrawVerificationPage;
import cz.moneta.test.dsl.hypos.pages.hypokalkulacka.HypokalkulackaPage;
import cz.moneta.test.dsl.hypos.pages.hypokom.HypokomSearchPage;
import cz.moneta.test.dsl.hypos.pages.mpt.MptPage;
import cz.moneta.test.dsl.hypos.pages.realty.RealtyMenuPage;
import cz.moneta.test.dsl.hypos.pages.structure.StructurePage;
import cz.moneta.test.dsl.hypos.pages.tasklist.TaskListPage;
import cz.moneta.test.harness.context.StoreAccessor;
import cz.moneta.test.harness.endpoints.hypos.HyposEndpoint;
import cz.moneta.test.harness.support.web.CheckElementPresent;
import cz.moneta.test.harness.support.web.CustomAction;
import cz.moneta.test.harness.support.web.Select;
import cz.moneta.test.harness.support.web.Until;
import cz.moneta.test.harness.support.web.Wait;

import static cz.moneta.test.dsl.hypos.pages.HyposLoginPage.SECONDARY_PROFILE_SELECT;

@Wait(value = SECONDARY_PROFILE_SELECT, until = Until.VISIBLE)
public interface HyposLoginPage extends HyposPageFlow<HyposLoginPage>, Menu, StoreAccessor {
    String SECONDARY_PROFILE_SELECT = "//select[@name='secondary_profile']";
    String HYPOS_LOGIN_BUTTON = "//a[text()='HYPOS přihlášení']";

    @Select(value = SECONDARY_PROFILE_SELECT, andWait = @Wait(value = SECONDARY_PROFILE_SELECT, until = Until.VISIBLE))
    HyposLoginPage selectSecondaryProfile(int profile);

    @CheckElementPresent(SECONDARY_PROFILE_SELECT)
    HyposLoginPage checkSecondaryProfile();

    @CheckElementPresent(HYPOS_LOGIN_BUTTON)
    HyposLoginPage checkLoginButton();

    @CustomAction
    default HypokomSearchPage switchToHypokom() {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        endpoint.changePath("Hypos/hypokom.php");
        return null;
    }

    @CustomAction
    default HyposMainPage switchToHyposMainPage() {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        endpoint.changePath("Hypos/main.php");
        endpoint.switchToFrame(MAIN_FRAME_XPATH);
        return null;
    }

    @CustomAction
    default HypokalkulackaPage switchToHypokalkulacka() {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        endpoint.changePath("Hypos/calc.php?cmd=calc.edit");
        return null;
    }

    @CustomAction
    default TestDrawVerificationPage switchToTestDrawVerificationPage() {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        endpoint.changePath("test-draw-ver.php");
        return null;
    }

    @CustomAction
    default MptPage switchToMptPage() {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        endpoint.changePath("Hypos/sestavy.php?cmd=mpt.list");
        return null;
    }

    @CustomAction
    default StructurePage switchToStructurePage() {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        endpoint.changePath("Hypos/sestavy.php?cmd=main");
        return null;
    }

    @CustomAction
    default CadasterNavigationPage switchToCadasterPage() {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        endpoint.changePath("Hypos/realty.php?cmd=cadaster.navigation");
        return null;
    }

    @CustomAction
    default RealtyMenuPage switchToRealtyPage() {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        endpoint.changePath("Hypos/realty.php?cmd=realty.menu");
        return null;
    }

    @CustomAction
    default TaskListPage switchToTaskListPage() {
        HyposEndpoint endpoint = getEndpoint(HyposEndpoint.class);
        endpoint.changePath("complaints.php?cmd=complaints.list");
        return null;
    }
}