"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.waitUntilStepDescriptorSchema = exports.endStepDescriptorSchema = exports.elseStepDescriptorSchema = exports.elseIfStepDescriptorSchema = exports.ifStepDescriptorSchema = exports.assertStepDescriptorSchema = void 0;
const zod_1 = require("zod");
const common_1 = require("../common");
const condition_descriptor_1 = require("../condition-descriptor");
const extract_descriptor_1 = require("../extract-descriptor");
const count_descriptor_1 = require("../count-descriptor");
const find_descriptors_1 = require("../find-descriptors");
const shared_1 = require("./shared");
const getCurrentLocationTargetSchema = zod_1.z.object({
    kind: zod_1.z.literal('Location'),
});
const getVariableTargetSchema = zod_1.z.object({
    kind: zod_1.z.literal('GetVariable'),
    variable: zod_1.z.string(),
});
const getViewportTargetSchema = zod_1.z.object({
    kind: zod_1.z.literal('Viewport'),
});
const javaScriptTargetSchema = zod_1.z
    .object({
    javaScript: shared_1.javaScriptDescriptorSchema,
})
    .passthrough();
const assertTargetSchema = zod_1.z.union([
    getCurrentLocationTargetSchema,
    getVariableTargetSchema,
    getViewportTargetSchema,
    javaScriptTargetSchema,
    find_descriptors_1.findDescriptorSchema,
    find_descriptors_1.mobileFindDescriptorSchema,
]);
exports.assertStepDescriptorSchema = common_1.baseStepDescriptorSchema
    .extend({
    target: assertTargetSchema
        .nullable()
        .optional()
        .describe('What to evaluate -- an element, variable, current URL, viewport, or JS expression'),
    condition: zod_1.z
        .union([condition_descriptor_1.conditionDescriptorSchema, zod_1.z.string()])
        .optional()
        .describe('The condition to check (comparison, presence, truthy, or AI prompt). Legacy mobile steps may use a string reference (e.g. "AssertEquals") instead of a structured object.'),
    count: count_descriptor_1.countDescriptorSchema.optional(),
    extract: extract_descriptor_1.extractDescriptorSchema
        .optional()
        .describe('Extract a specific value from the target before asserting'),
    onFailure: shared_1.onFailureEnum
        .optional()
        .describe('What to do when the assertion fails: continue, terminate, or fail at end'),
    observationScope: zod_1.z
        .string()
        .optional()
        .describe('Scope for assertion observation (e.g., limits the assertion evaluation context)'),
})
    .passthrough()
    .describe('Assert a condition on a target (element, variable, URL, or JS expression)');
exports.ifStepDescriptorSchema = exports.assertStepDescriptorSchema.describe('Conditional branch -- evaluates a condition to decide which steps to execute');
exports.elseIfStepDescriptorSchema = exports.assertStepDescriptorSchema.describe('Additional conditional branch within an If block');
exports.elseStepDescriptorSchema = common_1.baseStepDescriptorSchema
    .passthrough()
    .describe('Default branch when no If/ElseIf conditions match');
exports.endStepDescriptorSchema = common_1.baseStepDescriptorSchema
    .passthrough()
    .describe('Closes an If/ElseIf/Else conditional block');
exports.waitUntilStepDescriptorSchema = exports.assertStepDescriptorSchema.describe('Wait until a condition becomes true, with configurable timeout');
