"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.hideKeyboardStepSchema = exports.uninstallAppStepSchema = exports.installAppStepSchema = exports.pushFileStepSchema = exports.prepareSessionStepSchema = exports.openLinkStepSchema = exports.openAppStepSchema = exports.navigateHomeStepSchema = exports.navigateBackStepSchema = exports.setOrientationStepSchema = exports.scrollStepSchema = exports.tapStepSchema = exports.MAX_PRESS_DURATION_MILLIS = exports.MIN_PRESS_DURATION_MILLIS = void 0;
const zod_1 = require("zod");
const common_1 = require("../common");
const find_descriptors_1 = require("../find-descriptors");
const tapTypeEnum = zod_1.z.enum(['tap', 'long']);
const coordinatesWithinElementSchema = zod_1.z.object({
    xPercent: zod_1.z.number(),
    yPercent: zod_1.z.number(),
});
exports.MIN_PRESS_DURATION_MILLIS = 500;
exports.MAX_PRESS_DURATION_MILLIS = 30_000;
exports.tapStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    find: find_descriptors_1.mobileFindDescriptorSchema,
    type: tapTypeEnum
        .optional()
        .describe('Tap type: regular tap or long press'),
    coordinatesWithinElement: coordinatesWithinElementSchema.optional(),
    pressDurationMillis: zod_1.z
        .number()
        .int()
        .min(exports.MIN_PRESS_DURATION_MILLIS)
        .max(exports.MAX_PRESS_DURATION_MILLIS)
        .optional()
        .describe(`Long-press duration in milliseconds (${exports.MIN_PRESS_DURATION_MILLIS}–${exports.MAX_PRESS_DURATION_MILLIS}). Only applies when type is "long".`),
})
    .passthrough()
    .describe('Tap on a mobile element');
const scrollDirectionEnum = zod_1.z.enum(['down', 'left', 'right', 'up']);
const coordinatePercentSchema = zod_1.z.object({
    xPercent: zod_1.z.number(),
    yPercent: zod_1.z.number(),
});
const scrollCoordinatesSchema = zod_1.z.object({
    from: coordinatePercentSchema,
    to: coordinatePercentSchema,
});
const scrollDeviceScreenSchema = common_1.baseStepDescriptorSchema
    .extend({
    scrollType: zod_1.z.literal('scroll_device_screen'),
    coordinates: scrollCoordinatesSchema,
    scrollDirection: scrollDirectionEnum,
})
    .passthrough();
const scrollToElementSchema = common_1.baseStepDescriptorSchema
    .extend({
    scrollType: zod_1.z.literal('scroll_to_element'),
    targetElementDescriptor: find_descriptors_1.mobileFindElementDescriptorSchema,
    maxScrollAttempts: zod_1.z.number(),
    scrollDirection: scrollDirectionEnum,
    coordinates: scrollCoordinatesSchema.optional(),
    find: find_descriptors_1.mobileFindElementDescriptorSchema.optional(),
})
    .passthrough();
const scrollWithinElementSchema = common_1.baseStepDescriptorSchema
    .extend({
    scrollType: zod_1.z.literal('scroll_within_element'),
    find: find_descriptors_1.mobileFindElementDescriptorSchema,
    coordinates: scrollCoordinatesSchema,
    scrollDirection: scrollDirectionEnum,
})
    .passthrough();
exports.scrollStepSchema = zod_1.z
    .discriminatedUnion('scrollType', [
    scrollDeviceScreenSchema,
    scrollToElementSchema,
    scrollWithinElementSchema,
])
    .describe('Scroll on a mobile device — on screen, to an element, or within an element');
exports.setOrientationStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    orientation: zod_1.z.enum(['LANDSCAPE', 'PORTRAIT']),
})
    .passthrough()
    .describe('Change the device orientation to landscape or portrait');
exports.navigateBackStepSchema = common_1.baseStepDescriptorSchema
    .passthrough()
    .describe('Press the device back button');
exports.navigateHomeStepSchema = common_1.baseStepDescriptorSchema
    .passthrough()
    .describe('Press the device home button');
exports.openAppStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    packageName: zod_1.z.string().optional(),
})
    .passthrough()
    .describe('Open an application on the mobile device');
exports.openLinkStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    url: zod_1.z.string(),
    packageName: zod_1.z.string(),
})
    .passthrough()
    .describe('Open a deep link URL on the mobile device');
exports.prepareSessionStepSchema = common_1.baseStepDescriptorSchema
    .passthrough()
    .describe('Initialize the mobile test session');
const pushFileSchema = zod_1.z.object({
    id: zod_1.z.string(),
    name: zod_1.z.string(),
});
const pushFileInfoSchema = zod_1.z.object({
    file: pushFileSchema,
    path: zod_1.z.string(),
});
exports.pushFileStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    files: zod_1.z.array(pushFileInfoSchema).min(1),
})
    .passthrough()
    .describe('Push files to the mobile device');
exports.installAppStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    packageName: zod_1.z.string().optional(),
})
    .passthrough()
    .describe('Install an application on the mobile device');
exports.uninstallAppStepSchema = common_1.baseStepDescriptorSchema
    .extend({
    appId: zod_1.z.string().optional(),
})
    .passthrough()
    .describe('Remove an application from the mobile device');
exports.hideKeyboardStepSchema = common_1.baseStepDescriptorSchema
    .passthrough()
    .describe('Dismiss the on-screen keyboard');
