"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.downloadStepSchema = exports.awaitUploadsStepSchema = exports.setFilesStepSchema = void 0;
const zod_1 = require("zod");
const common_1 = require("../common");
const shared_1 = require("./shared");
const fileUploadDescriptorSchema = zod_1.z.object({
    id: zod_1.z.string().optional(),
    name: zod_1.z.string().optional(),
    size: zod_1.z.number().optional(),
    type: zod_1.z.string().optional(),
    url: zod_1.z.string().optional(),
});
exports.setFilesStepSchema = shared_1.stepWithBrowserFindSchema
    .extend({
    files: zod_1.z.array(fileUploadDescriptorSchema),
})
    .describe('Set files on a file input element for upload');
exports.awaitUploadsStepSchema = common_1.baseStepDescriptorSchema
    .passthrough()
    .describe('Wait for pending file uploads to complete');
const fileNameMatchModeEnum = zod_1.z.enum([
    'equals',
    'contains',
    'starts_with',
    'ends_with',
    'matches_regex',
]);
const detectedDownloadMetadataSchema = zod_1.z
    .object({
    file_mime_type: zod_1.z.string().optional(),
    file_name: zod_1.z.string().optional(),
    file_size_bytes: zod_1.z.number().optional(),
})
    .passthrough();
const sizeBytesSchema = zod_1.z.union([zod_1.z.number(), zod_1.z.string().regex(/^-?\d+$/)]);
exports.downloadStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    fileName: zod_1.z
        .string()
        .optional()
        .describe('Expected file name (or pattern based on fileNameMatchMode)'),
    mimeType: zod_1.z.string().optional(),
    fileMd5: zod_1.z.string().optional(),
    fileSha256: zod_1.z.string().optional(),
    sizeBytes: sizeBytesSchema.optional(),
    sizeBytesMax: sizeBytesSchema.optional(),
    sizeBytesMin: sizeBytesSchema.optional(),
    tabIdentifier: zod_1.z.string().optional(),
    aiPrompt: shared_1.aiPromptSchema
        .optional()
        .describe('AI prompt to evaluate the downloaded file content'),
    fileNameMatchMode: fileNameMatchModeEnum.optional(),
    detected: detectedDownloadMetadataSchema.optional(),
})
    .passthrough()
    .describe('Assert that a file download occurred with expected properties');
