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

import cz.moneta.test.dsl.ufo.operations.shared.topmenu.XXX701_SharedTopMenu;
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.UKO720_S001_QuickTaskPage.CATEGORY_SELECT;

@Wait(CATEGORY_SELECT)
public interface UKO720_S001_QuickTaskPage extends WebFlow<UKO720_S001_QuickTaskPage>, XXX701_SharedTopMenu<UKO720_S001_TaskList>, StoreAccessor {

    String TASK_ID_KEY = "TASK_ID";
    String CATEGORY_SELECT = "UKO720_S001_C047";
    String GENERATE_TASK_BUTTON = "UKO720_S001_B044";

    @Select(value = CATEGORY_SELECT, selectByOrder = true, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    UKO720_S001_QuickTaskPage selectTaskCategory(int index);

    @Click(value = GENERATE_TASK_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, until = Until.GONE, by = Lookup.CLASSNAME))
    UKO720_S001_QuickTaskPage generateQuickTask();

    @CustomAction
    default UKO720_S001_QuickTaskPage saveTaskID() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        String establishedTaskText = endpoint.getText(STATUS_LABEL).replaceAll(".*(T_\\d+) .*", "$1");
        store(TASK_ID_KEY, establishedTaskText);
        return null;
    }

}