"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.echoStepSchema = exports.evaluateJavaScriptStepSchema = exports.generateEmailAddressStepSchema = exports.createVariableStepSchema = void 0;
const zod_1 = require("zod");
const common_1 = require("../common");
const find_descriptors_1 = require("../find-descriptors");
const shared_1 = require("./shared");
const emailGeneratorSchema = zod_1.z.object({
    type: zod_1.z.literal('EMAIL'),
});
const patternGeneratorSchema = zod_1.z.object({
    type: zod_1.z.literal('PATTERN'),
    pattern: zod_1.z.string(),
});
const javaScriptGeneratorSchema = zod_1.z.object({
    type: zod_1.z.literal('JAVASCRIPT'),
    javaScript: shared_1.javaScriptDescriptorSchema,
});
const attributeGeneratorSchema = zod_1.z.object({
    type: zod_1.z.literal('ATTRIBUTE'),
    attribute: zod_1.z.string(),
    find: find_descriptors_1.findElementDescriptorSchema.optional(),
});
const elementCountGeneratorSchema = zod_1.z.object({
    type: zod_1.z.literal('ELEMENT_COUNT'),
    find: find_descriptors_1.findCustomDescriptorSchema.optional(),
});
const cookieValueGeneratorSchema = zod_1.z.object({
    type: zod_1.z.literal('COOKIE_ATTRIBUTE'),
    cookieSelector: find_descriptors_1.cookieSelectorSchema,
    attribute: zod_1.z.string(),
});
const generatorSchema = zod_1.z.discriminatedUnion('type', [
    emailGeneratorSchema,
    patternGeneratorSchema,
    javaScriptGeneratorSchema,
    attributeGeneratorSchema,
    elementCountGeneratorSchema,
    cookieValueGeneratorSchema,
]);
exports.createVariableStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    name: zod_1.z
        .string()
        .describe('Variable name (referenced as {{@name}} in other steps)'),
    generator: generatorSchema.describe('How to generate the variable value'),
    find: zod_1.z
        .union([find_descriptors_1.findDescriptorSchema, find_descriptors_1.mobileFindDescriptorSchema])
        .optional(),
})
    .passthrough()
    .describe('Create a test variable from an element attribute, JS expression, email, pattern, or element count');
exports.generateEmailAddressStepSchema = exports.createVariableStepSchema.describe('Generate a unique email address as a test variable (legacy alias for CreateVariable)');
exports.evaluateJavaScriptStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    javaScript: shared_1.javaScriptDescriptorSchema,
})
    .passthrough()
    .describe('Execute a JavaScript snippet in the browser context');
exports.echoStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    value: zod_1.z.string().describe('The value to log (can contain {{@variables}})'),
})
    .passthrough()
    .describe('Log a value to the test output');
