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

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_TaskDetail.PROCESS_DOCUMENTS_BUTTON;

@Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE, waitSecondsForElement = 30)
@Wait(value = PROCESS_DOCUMENTS_BUTTON)
public interface UKO720_S001_TaskDetail extends StoreAccessor, WebFlow<UKO720_S001_TaskDetail> {

    String PROCESS_DOCUMENTS_BUTTON = "UKO720_S001_P017";
    String PROCESS_FIRST_ATTACHMENT_BUTTON = "UKO720_S001_P019-1";
    String FINISH_PROCESS_BUTTON = "UKO720_S001_B016";
    String FINISH_PROCESS_COMMENT_BUTTON = "UKO720_S001_B007";
    String EDIT_COMMENT = "UKO720_S001_M006";
    String SOLVER_SELECT = "UKO720_S001_C009";
    String NOTE_WINDOW = "UKO720_S001_M006";
    String TASK_ID = "UKO720_S001_L085";

    @CheckElementPresent(TASK_ID)
    UKO720_S001_TaskDetail checkTaskIdPresence();

    @TypeInto(value = EDIT_COMMENT)
    @Click(value = FINISH_PROCESS_COMMENT_BUTTON, andWait = @Wait(value = LOAD_IMG_DIV_CLASS, by = Lookup.CLASSNAME, until = Until.GONE))
    UKO720_S001_TaskList fillCommentAndClickAgreeFinish(String comment);

    @Click(value = FINISH_PROCESS_BUTTON)
    UKO720_S001_TaskDetail clickFinishProcess();

    @Click(value = FINISH_PROCESS_BUTTON)
    @AcceptAlert(waitSecondsForAlert = 5, expectedAlertText = "Není vytvořena odpověď pro klienta, opravdu chcete dokončit úkol?")
    UKO720_S001_TaskDetail clickFinishProcessAndAcceptFinishAlert();

    @Select(value = SOLVER_SELECT, selectByOrder = true)
    UKO720_S001_TaskDetail selectSolver(int num);

    @Select(value = SOLVER_SELECT)
    UKO720_S001_TaskDetail selectSolver(String selectValue);

    @Wait(value = NOTE_WINDOW, until = Until.VISIBLE)
    @TypeInto(NOTE_WINDOW)
    UKO720_S001_TaskDetail fillNote(String note);

    @CustomAction
    default UKO720_S001_TaskPage_Transitions clickProcessDocuments() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> PROCESS_DOCUMENTS_BUTTON);
        endpoint.focusToNewPopup(20);
        return null;
    }

    @CustomAction
    default SCH706_S001_FormSelect clickProcessFirstAttachment() {
        UfoEndpoint endpoint = getEndpoint(UfoEndpoint.class);
        endpoint.click(() -> PROCESS_FIRST_ATTACHMENT_BUTTON);
        endpoint.focusToNewPopup(40);
        return null;
    }
}