"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.StepType = exports.StepStatus = exports.CONDITIONAL_TYPE_ELSEIF = exports.CONDITIONAL_TYPE_IF = exports.ConditionalType = void 0;
exports.isStepStatusSuccessful = isStepStatusSuccessful;
exports.stepIsDownloadStep = stepIsDownloadStep;
exports.stepIsEchoStep = stepIsEchoStep;
exports.isAssertionStep = isAssertionStep;
exports.stepIsStepWithAssertion = stepIsStepWithAssertion;
exports.stepTypeSupportsOnFailure = stepTypeSupportsOnFailure;
exports.isCreateVariableStep = isCreateVariableStep;
exports.isEvaluateJSStep = isEvaluateJSStep;
exports.isEchoStep = isEchoStep;
exports.isSendHttpRequestStep = isSendHttpRequestStep;
exports.isDatabaseQueryStep = isDatabaseQueryStep;
exports.isMultiOutputVariablesStep = isMultiOutputVariablesStep;
exports.isStepWithFind = isStepWithFind;
exports.isStepWithTab = isStepWithTab;
exports.isStepWithReusableFlow = isStepWithReusableFlow;
exports.isStepGroupStep = isStepGroupStep;
exports.isStepWithVariable = isStepWithVariable;
exports.isStepWithVariables = isStepWithVariables;
exports.isConditionalStep = isConditionalStep;
exports.isAnyConditionalControlFlowStep = isAnyConditionalControlFlowStep;
exports.isIfOrElseIfStep = isIfOrElseIfStep;
exports.isElseStep = isElseStep;
exports.isEndStep = isEndStep;
exports.isMablStepAdapter = isMablStepAdapter;
exports.isStepWithSnippet = isStepWithSnippet;
exports.isStepWithMobileCliStep = isStepWithMobileCliStep;
exports.compareIndices = compareIndices;
exports.indexLessThan = indexLessThan;
exports.indexLessThanOrEqualTo = indexLessThanOrEqualTo;
exports.indexGreaterThan = indexGreaterThan;
exports.indexGreaterThanOrEqualTo = indexGreaterThanOrEqualTo;
exports.indexEqual = indexEqual;
var ConditionalType;
(function (ConditionalType) {
    ConditionalType["ELSEIF"] = "ELSEIF";
    ConditionalType["IF"] = "IF";
})(ConditionalType || (exports.ConditionalType = ConditionalType = {}));
exports.CONDITIONAL_TYPE_IF = 'IF';
exports.CONDITIONAL_TYPE_ELSEIF = 'ELSEIF';
var StepStatus;
(function (StepStatus) {
    StepStatus["Failed"] = "Failed";
    StepStatus["NestedSkipped"] = "NestedSkipped";
    StepStatus["NotImplemented"] = "NotImplemented";
    StepStatus["Passed"] = "Passed";
    StepStatus["Pending"] = "Pending";
    StepStatus["Skipped"] = "Skipped";
})(StepStatus || (exports.StepStatus = StepStatus = {}));
function isStepStatusSuccessful(status) {
    return status === StepStatus.Passed || status === StepStatus.Skipped;
}
var StepType;
(function (StepType) {
    StepType["ACCESSIBILITY_CHECK"] = "accessibility-check";
    StepType["ASSERTION"] = "assertion";
    StepType["ASSERT_VARIABLE"] = "assert-variable";
    StepType["AWAIT_DOWNLOAD"] = "await_download";
    StepType["AWAIT_TAB"] = "await-tab";
    StepType["AWAIT_UPLOAD"] = "await-uploads";
    StepType["CLEAR_COOKIES"] = "clear-cookies";
    StepType["CLICK"] = "click";
    StepType["CLICK_HOLD"] = "click_hold";
    StepType["CONDITIONAL_ELSE"] = "conditional_else";
    StepType["CONDITIONAL_END"] = "conditional_end";
    StepType["CREATE_VARIABLE"] = "create_variable";
    StepType["DATABASE_QUERY"] = "database_query";
    StepType["DOUBLE_CLICK"] = "double_click";
    StepType["DOWNLOAD"] = "download";
    StepType["DOWNLOAD_PDF"] = "download-pdf";
    StepType["ECHO"] = "echo";
    StepType["ENTER_AUTH_CODE"] = "enter_auth_code";
    StepType["ENTER_TEXT"] = "enter_text";
    StepType["EVALUATE_JS"] = "evaluate-js";
    StepType["EXECUTE_FLOW"] = "execute_flow";
    StepType["EXECUTE_STEP_GROUP"] = "execute_step_group";
    StepType["HIDE_KEYBOARD"] = "hide_keyboard";
    StepType["HOVER"] = "hover";
    StepType["KEYPRESS"] = "keypress";
    StepType["NAVIGATE_BACK"] = "navigate_back";
    StepType["NAVIGATE_HOME"] = "navigate_home";
    StepType["NAVIGATION"] = "navigation";
    StepType["OPEN_APP"] = "open-app";
    StepType["OPEN_DEEP_LINK"] = "deep-link";
    StepType["OPEN_EMAIL"] = "open-email";
    StepType["PREPARE_SESSION"] = "prepare-session";
    StepType["PUSH_FILE"] = "push-file";
    StepType["RELEASE"] = "release";
    StepType["REMOVE_COOKIE"] = "remove-cookie";
    StepType["RIGHT_CLICK"] = "right_click";
    StepType["SCROLL"] = "scroll";
    StepType["SELECT"] = "select";
    StepType["SEND_HTTP_REQUEST"] = "send-http-request";
    StepType["SET_COOKIE"] = "set-cookie";
    StepType["SET_FILES"] = "set-files";
    StepType["SET_ORIENTATION"] = "set_orientation";
    StepType["SET_VIEWPORT"] = "viewport";
    StepType["SWITCH_CONTEXT"] = "switch-context-to";
    StepType["TAP"] = "tap";
    StepType["VIEWPORT"] = "viewport";
    StepType["VISIT_URL"] = "visit_url";
    StepType["WAIT"] = "wait";
})(StepType || (exports.StepType = StepType = {}));
function stepIsDownloadStep(step) {
    return step.stepType === StepType.DOWNLOAD;
}
function stepIsEchoStep(step) {
    const { stepType } = step;
    return stepType === StepType.ECHO;
}
function isAssertionStep(step) {
    if (!step) {
        return false;
    }
    const { stepType } = step;
    return stepType === StepType.ASSERTION;
}
function stepIsStepWithAssertion(step) {
    if (!step) {
        return false;
    }
    const { stepType } = step;
    return (stepType === StepType.ASSERTION || stepType === StepType.ASSERT_VARIABLE);
}
function stepTypeSupportsOnFailure(step) {
    return (stepIsStepWithAssertion(step) &&
        !step.wrapInConditional &&
        !step.findOptions?.waitUntil);
}
function isCreateVariableStep(value) {
    return value?.stepType === StepType.CREATE_VARIABLE && value.variable;
}
function isEvaluateJSStep(value) {
    return value?.stepType === StepType.EVALUATE_JS && value.javaScript;
}
function isEchoStep(step) {
    return stepIsEchoStep(step);
}
function isSendHttpRequestStep(value) {
    return value?.stepType === StepType.SEND_HTTP_REQUEST;
}
function isDatabaseQueryStep(value) {
    return value?.stepType === StepType.DATABASE_QUERY;
}
function isMultiOutputVariablesStep(value) {
    return isDatabaseQueryStep(value) || isSendHttpRequestStep(value);
}
function isStepWithFind(value) {
    return value?.stepType && value?.findDescriptor;
}
function isStepWithTab(value) {
    return value?.stepType && value?.tabSelector;
}
function isStepWithReusableFlow(value) {
    return value?.stepType === StepType.EXECUTE_FLOW;
}
function isStepGroupStep(value) {
    return value?.stepType === StepType.EXECUTE_STEP_GROUP;
}
function isStepWithVariable(value) {
    return value?.stepType && value.variable;
}
function isStepWithVariables(value) {
    return value?.stepType && Array.isArray(value.variables);
}
function isConditionalStep(value) {
    return value?.stepType && value.wrapInConditional === true;
}
function isAnyConditionalControlFlowStep(value) {
    if (!value?.stepType) {
        return false;
    }
    if (value.wrapInConditional === true) {
        return true;
    }
    return (value.stepType === StepType.CONDITIONAL_ELSE ||
        value.stepType === StepType.CONDITIONAL_END);
}
function isIfOrElseIfStep(value) {
    return value?.wrapInConditional === true;
}
function isElseStep(value) {
    return value?.stepType === StepType.CONDITIONAL_ELSE;
}
function isEndStep(value) {
    return value?.stepType === StepType.CONDITIONAL_END;
}
function isMablStepAdapter(value) {
    return value?.mablStep;
}
function isStepWithSnippet(step) {
    return typeof step.getSnippetInvariantId === 'function';
}
function isStepWithMobileCliStep(step) {
    return typeof step.generateMobileCliStep === 'function';
}
function compareIndices(left, right, numberComparator) {
    for (let i = 0; i <= Math.max(left.length, right.length); i++) {
        const leftValue = left?.[i] ?? -1;
        const rightValue = right?.[i] ?? -1;
        if (leftValue !== rightValue || i === left.length || i === right.length) {
            return numberComparator(leftValue, rightValue);
        }
    }
    return false;
}
function indexLessThan(left, right) {
    return compareIndices(left, right, (leftIndex, rightIndex) => leftIndex < rightIndex);
}
function indexLessThanOrEqualTo(left, right) {
    return compareIndices(left, right, (leftIndex, rightIndex) => leftIndex <= rightIndex);
}
function indexGreaterThan(left, right) {
    return compareIndices(left, right, (leftIndex, rightIndex) => leftIndex > rightIndex);
}
function indexGreaterThanOrEqualTo(left, right) {
    return compareIndices(left, right, (leftIndex, rightIndex) => leftIndex >= rightIndex);
}
function indexEqual(left, right) {
    return compareIndices(left, right, (leftIndex, rightIndex) => leftIndex === rightIndex);
}
