"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.MOBILE_STEP_NAMES = exports.BROWSER_STEP_NAMES = void 0;
exports.registerStepSchema = registerStepSchema;
exports.getStepSchema = getStepSchema;
exports.isKnownStepType = isKnownStepType;
exports.getStepTypeNames = getStepTypeNames;
exports.getBrowserStepsUnionSchema = getBrowserStepsUnionSchema;
const zod_1 = require("zod");
const common_1 = require("./common");
const click_pointer_1 = require("./steps/click-pointer");
const text_input_1 = require("./steps/text-input");
const navigation_1 = require("./steps/navigation");
const assertions_1 = require("./steps/assertions");
const variables_js_1 = require("./steps/variables-js");
const api_data_1 = require("./steps/api-data");
const files_downloads_1 = require("./steps/files-downloads");
const cookies_browser_1 = require("./steps/cookies-browser");
const meta_steps_1 = require("./steps/meta-steps");
const mobile_1 = require("./steps/mobile");
exports.BROWSER_STEP_NAMES = [
    'AccessibilityCheck',
    'AssertEquals',
    'AssertPresent',
    'AssertNotPresent',
    'AssertDoesNotEqual',
    'AssertContains',
    'AssertDoesNotContain',
    'AssertStartsWith',
    'AssertStartsWithout',
    'AssertEndsWith',
    'AssertEndsWithout',
    'AssertGreaterThan',
    'AssertLessThan',
    'AssertGreaterThanOrEquals',
    'AssertLessThanOrEquals',
    'AssertMatchesRegex',
    'AssertAIPrompt',
    'AwaitTab',
    'AwaitUploads',
    'ClearCookies',
    'Click',
    'Click and Hold',
    'CreateVariable',
    'DatabaseQuery',
    'DoubleClick',
    'DownloadPdfStep',
    'DownloadStep',
    'Echo',
    'Else',
    'ElseIf',
    'End',
    'EnterAuthCode',
    'EnterText',
    'EvaluateFlow',
    'EvaluateJavaScript',
    'GenerateEmailAddress',
    'Hover',
    'If',
    'Navigate',
    'OpenEmail',
    'Release',
    'RemoveCookie',
    'RightClick',
    'Select',
    'SendHttpRequest',
    'SendKeys',
    'SetCookie',
    'SetFiles',
    'SetViewport',
    'StepGroup',
    'SwitchContext',
    'VisitUrl',
    'Wait',
    'WaitUntil',
];
exports.MOBILE_STEP_NAMES = [
    'CreateVariable',
    'EnterText',
    'HideKeyboard',
    'InstallApp',
    'NavigateBack',
    'NavigateHome',
    'OpenApp',
    'OpenLink',
    'PrepareSession',
    'PushFile',
    'Scroll',
    'SetOrientation',
    'Tap',
    'UninstallApp',
    'Echo',
    'Else',
    'ElseIf',
    'End',
    'EvaluateFlow',
    'EvaluateJavaScript',
    'If',
    'OpenEmail',
    'SendHttpRequest',
    'StepGroup',
    'Wait',
    'AssertEquals',
    'AssertPresent',
    'AssertNotPresent',
    'AssertDoesNotEqual',
    'AssertContains',
    'AssertDoesNotContain',
    'AssertStartsWith',
    'AssertStartsWithout',
    'AssertEndsWith',
    'AssertEndsWithout',
    'AssertGreaterThan',
    'AssertLessThan',
    'AssertGreaterThanOrEquals',
    'AssertLessThanOrEquals',
    'AssertMatchesRegex',
    'AssertAIPrompt',
    'WaitUntil',
];
const ALL_STEP_NAMES_SET = new Set([
    ...exports.BROWSER_STEP_NAMES,
    ...exports.MOBILE_STEP_NAMES,
]);
const BROWSER_STEP_NAMES_SET = new Set(exports.BROWSER_STEP_NAMES);
const MOBILE_STEP_NAMES_SET = new Set(exports.MOBILE_STEP_NAMES);
const passthroughStepSchema = common_1.baseStepDescriptorSchema.passthrough();
const stepSchemaRegistry = new Map();
for (const name of ALL_STEP_NAMES_SET) {
    stepSchemaRegistry.set(name, passthroughStepSchema);
}
stepSchemaRegistry.set('Click', click_pointer_1.clickStepSchema);
stepSchemaRegistry.set('DoubleClick', click_pointer_1.doubleClickStepSchema);
stepSchemaRegistry.set('RightClick', click_pointer_1.rightClickStepSchema);
stepSchemaRegistry.set('Hover', click_pointer_1.hoverStepSchema);
stepSchemaRegistry.set('Click and Hold', click_pointer_1.clickAndHoldStepSchema);
stepSchemaRegistry.set('Release', click_pointer_1.releaseStepSchema);
stepSchemaRegistry.set('EnterText', text_input_1.enterTextBrowserStepSchema);
stepSchemaRegistry.set('SendKeys', text_input_1.sendKeysStepSchema);
stepSchemaRegistry.set('Select', text_input_1.selectStepSchema);
stepSchemaRegistry.set('EnterAuthCode', text_input_1.enterAuthCodeStepSchema);
stepSchemaRegistry.set('VisitUrl', navigation_1.visitUrlStepSchema);
stepSchemaRegistry.set('Navigate', navigation_1.navigateStepSchema);
stepSchemaRegistry.set('AwaitTab', navigation_1.awaitTabStepSchema);
stepSchemaRegistry.set('SwitchContext', navigation_1.switchContextStepSchema);
const assertStepNames = [
    'AssertEquals',
    'AssertPresent',
    'AssertNotPresent',
    'AssertDoesNotEqual',
    'AssertContains',
    'AssertDoesNotContain',
    'AssertStartsWith',
    'AssertStartsWithout',
    'AssertEndsWith',
    'AssertEndsWithout',
    'AssertGreaterThan',
    'AssertLessThan',
    'AssertGreaterThanOrEquals',
    'AssertLessThanOrEquals',
    'AssertMatchesRegex',
    'AssertAIPrompt',
];
for (const name of assertStepNames) {
    stepSchemaRegistry.set(name, assertions_1.assertStepDescriptorSchema);
}
stepSchemaRegistry.set('If', assertions_1.ifStepDescriptorSchema);
stepSchemaRegistry.set('ElseIf', assertions_1.elseIfStepDescriptorSchema);
stepSchemaRegistry.set('Else', assertions_1.elseStepDescriptorSchema);
stepSchemaRegistry.set('End', assertions_1.endStepDescriptorSchema);
stepSchemaRegistry.set('WaitUntil', assertions_1.waitUntilStepDescriptorSchema);
stepSchemaRegistry.set('CreateVariable', variables_js_1.createVariableStepSchema);
stepSchemaRegistry.set('GenerateEmailAddress', variables_js_1.generateEmailAddressStepSchema);
stepSchemaRegistry.set('EvaluateJavaScript', variables_js_1.evaluateJavaScriptStepSchema);
stepSchemaRegistry.set('Echo', variables_js_1.echoStepSchema);
stepSchemaRegistry.set('SendHttpRequest', api_data_1.sendHttpRequestStepSchema);
stepSchemaRegistry.set('DatabaseQuery', api_data_1.databaseQueryStepSchema);
stepSchemaRegistry.set('OpenEmail', api_data_1.openEmailStepSchema);
stepSchemaRegistry.set('SetFiles', files_downloads_1.setFilesStepSchema);
stepSchemaRegistry.set('AwaitUploads', files_downloads_1.awaitUploadsStepSchema);
stepSchemaRegistry.set('DownloadStep', files_downloads_1.downloadStepSchema);
stepSchemaRegistry.set('DownloadPdfStep', files_downloads_1.downloadStepSchema);
stepSchemaRegistry.set('SetCookie', cookies_browser_1.setCookieStepSchema);
stepSchemaRegistry.set('RemoveCookie', cookies_browser_1.removeCookieStepSchema);
stepSchemaRegistry.set('ClearCookies', cookies_browser_1.clearCookiesStepSchema);
stepSchemaRegistry.set('SetViewport', cookies_browser_1.setViewportStepSchema);
stepSchemaRegistry.set('AccessibilityCheck', cookies_browser_1.accessibilityCheckStepSchema);
stepSchemaRegistry.set('Wait', cookies_browser_1.waitStepSchema);
stepSchemaRegistry.set('StepGroup', meta_steps_1.stepGroupStepSchema);
stepSchemaRegistry.set('EvaluateFlow', meta_steps_1.evaluateFlowStepSchema);
stepSchemaRegistry.set('Tap', mobile_1.tapStepSchema);
stepSchemaRegistry.set('Scroll', mobile_1.scrollStepSchema);
stepSchemaRegistry.set('SetOrientation', mobile_1.setOrientationStepSchema);
stepSchemaRegistry.set('NavigateBack', mobile_1.navigateBackStepSchema);
stepSchemaRegistry.set('NavigateHome', mobile_1.navigateHomeStepSchema);
stepSchemaRegistry.set('OpenApp', mobile_1.openAppStepSchema);
stepSchemaRegistry.set('OpenLink', mobile_1.openLinkStepSchema);
stepSchemaRegistry.set('PrepareSession', mobile_1.prepareSessionStepSchema);
stepSchemaRegistry.set('PushFile', mobile_1.pushFileStepSchema);
stepSchemaRegistry.set('InstallApp', mobile_1.installAppStepSchema);
stepSchemaRegistry.set('UninstallApp', mobile_1.uninstallAppStepSchema);
stepSchemaRegistry.set('HideKeyboard', mobile_1.hideKeyboardStepSchema);
const mobileSchemaOverrides = new Map();
mobileSchemaOverrides.set('EnterText', text_input_1.enterTextMobileStepSchema);
function registerStepSchema(stepTypeName, schema) {
    stepSchemaRegistry.set(stepTypeName, schema);
}
function getStepSchema(stepTypeName, testType) {
    if (testType === 'mobile') {
        const mobileOverride = mobileSchemaOverrides.get(stepTypeName);
        if (mobileOverride) {
            return mobileOverride;
        }
    }
    return stepSchemaRegistry.get(stepTypeName);
}
function isKnownStepType(stepTypeName, testType) {
    if (testType === 'browser') {
        return BROWSER_STEP_NAMES_SET.has(stepTypeName);
    }
    if (testType === 'mobile') {
        return MOBILE_STEP_NAMES_SET.has(stepTypeName);
    }
    return ALL_STEP_NAMES_SET.has(stepTypeName);
}
function getStepTypeNames(testType) {
    if (testType === 'browser') {
        return [...exports.BROWSER_STEP_NAMES];
    }
    if (testType === 'mobile') {
        return [...exports.MOBILE_STEP_NAMES];
    }
    return [...ALL_STEP_NAMES_SET].sort();
}
let browserStepsUnionSchemaCache;
function getBrowserStepsUnionSchema() {
    if (browserStepsUnionSchemaCache) {
        return browserStepsUnionSchemaCache;
    }
    const schemas = exports.BROWSER_STEP_NAMES.map((name) => stepSchemaRegistry.get(name));
    browserStepsUnionSchemaCache = zod_1.z.union(schemas);
    return browserStepsUnionSchemaCache;
}
