"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.CURSOR_MARKER = void 0;
exports.parseTaskFromEchoStep = parseTaskFromEchoStep;
exports.parseTaskFromStep = parseTaskFromStep;
exports.convertStepToSuccessContext = convertStepToSuccessContext;
exports.getSupportedTools = getSupportedTools;
exports.makeStepDescriptionForStartTask = makeStepDescriptionForStartTask;
const mablApi_1 = require("../../mablApi");
const GET_RECENT_DOWNLOAD = 'get_recent_download';
const mablscript_step_types_1 = require("./mablscript-step-types");
const generation_types_1 = require("./generation-types");
function parseTaskFromEchoStep(step) {
    return (0, mablscript_step_types_1.isEchoStep)(step) && step.message.startsWith(generation_types_1.START_TASK_PREFIX)
        ? step.message.slice(generation_types_1.START_TASK_PREFIX.length).trim()
        : undefined;
}
function parseTaskFromStep(step) {
    if ((0, mablscript_step_types_1.isStepGroupStep)(step)) {
        return step.description;
    }
    return undefined;
}
function convertStepToSuccessContext(step) {
    if (!step) {
        return undefined;
    }
    return {
        stepDescription: step.step,
        stepType: step.stepType,
        userDescription: step.userDescription,
    };
}
function getSupportedTools(options) {
    return [
        mablApi_1.ExecuteToolName.AskForHelp,
        mablApi_1.ExecuteToolName.Assert,
        mablApi_1.ExecuteToolName.AssertElement,
        mablApi_1.ExecuteToolName.AssertVariable,
        mablApi_1.ExecuteToolName.AssertUrl,
        mablApi_1.ExecuteToolName.AssertCookie,
        mablApi_1.ExecuteToolName.Click,
        mablApi_1.ExecuteToolName.ClickAndHold,
        mablApi_1.ExecuteToolName.Release,
        mablApi_1.ExecuteToolName.CountElements,
        mablApi_1.ExecuteToolName.CreateOrSetVariable,
        mablApi_1.ExecuteToolName.EnterAuthCode,
        mablApi_1.ExecuteToolName.EnterText,
        mablApi_1.ExecuteToolName.Flow,
        mablApi_1.ExecuteToolName.Hover,
        mablApi_1.ExecuteToolName.Scroll,
        mablApi_1.ExecuteToolName.PreexistingSnippet,
        mablApi_1.ExecuteToolName.Javascript,
        mablApi_1.ExecuteToolName.Snippet,
        mablApi_1.ExecuteToolName.SwitchTab,
        mablApi_1.ExecuteToolName.VisitUrl,
        mablApi_1.ExecuteToolName.Wait,
        mablApi_1.ExecuteToolName.WaitUntil,
        mablApi_1.ExecuteToolName.CreateMablMailbox,
        mablApi_1.ExecuteToolName.OpenMablEmail,
        mablApi_1.ExecuteToolName.OpenPdf,
        mablApi_1.ExecuteToolName.AssertDownload,
        GET_RECENT_DOWNLOAD,
        mablApi_1.ExecuteToolName.UploadFile,
        mablApi_1.ExecuteToolName.StartStepGroup,
        mablApi_1.ExecuteToolName.EndTest,
        mablApi_1.ExecuteToolName.PlaySteps,
        mablApi_1.ExecuteToolName.MoveCursor,
        mablApi_1.ExecuteToolName.MoveSteps,
        mablApi_1.ExecuteToolName.DeleteSteps,
        mablApi_1.ExecuteToolName.Echo,
        mablApi_1.ExecuteToolName.ReloadPage,
        mablApi_1.ExecuteToolName.SetViewport,
        mablApi_1.ExecuteToolName.DatabaseQuery,
        mablApi_1.ExecuteToolName.Else,
        mablApi_1.ExecuteToolName.EndIf,
        mablApi_1.ExecuteToolName.TestAssertStep,
        mablApi_1.ExecuteToolName.SendHttpRequest,
        mablApi_1.ExecuteToolName.ClearCookies,
        mablApi_1.ExecuteToolName.RemoveCookie,
        mablApi_1.ExecuteToolName.SetCookie,
        ...(options?.isLocalTrainer ? [] : [mablApi_1.ExecuteToolName.ValidateTest]),
        ...(options?.accessibilityChecksEnabled
            ? [mablApi_1.ExecuteToolName.AccessibilityCheck]
            : []),
    ];
}
function makeStepDescriptionForStartTask(task) {
    return `Start new task: ${task}`;
}
exports.CURSOR_MARKER = '<< CURSOR >>';
