"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.recordWaitUntilExecutor = void 0;
const toolExecutor_types_1 = require("../toolExecutor-types");
const ConditionDescriptor_1 = require("@mablhq/test-model/types/ConditionDescriptor");
const stepCapture_1 = require("../../background/capture/stepCapture");
exports.recordWaitUntilExecutor = {
    needsFind: () => true,
    getStepType: () => 'assert',
    execute: async (payload, stateProvider, eventHandler, logger) => {
        const toolParams = payload.toolCall.toolParams;
        if (!payload.find || !payload.contextInfo) {
            logger.error('RecordWaitUntilExecutor requires find and contextInfo');
            return {
                success: false,
            };
        }
        if (toolParams?.timeoutSeconds === undefined) {
            logger.error('Invalid toolParams for RecordWaitUntilExecutor: missing timeoutSeconds');
            return {
                success: false,
            };
        }
        const step = {
            ...payload.find,
            stepType: undefined,
            listener: 'mouse-select',
            findOptions: { waitUntil: { timeoutSeconds: toolParams.timeoutSeconds } },
            assertion: {
                assertionType: ConditionDescriptor_1.AssertionConditionField.Present,
                selectionType: 'element',
                assertionTarget: 'element',
            },
        };
        return (0, toolExecutor_types_1.recordStepAndTrackResult)(() => (0, stepCapture_1.recordTrainedStep)(step, payload.contextInfo, true, undefined, stateProvider, eventHandler), 0, stateProvider, eventHandler, logger);
    },
};
