"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.createMablMailboxExecutor = void 0;
const toolExecutor_types_1 = require("../toolExecutor-types");
const mablscriptFind_1 = require("@mablhq/test-model/mablscriptFind");
const stepCapture_1 = require("../../background/capture/stepCapture");
const variable_constants_1 = require("../../sharedUtils/variable-constants");
exports.createMablMailboxExecutor = {
    needsFind: () => false,
    getStepType: () => 'create_mabl_mailbox',
    execute: async (payload, stateProvider, eventHandler, logger) => {
        const toolParams = payload.toolCall.toolParams;
        if (!toolParams || !isCreateMablMailboxParams(toolParams)) {
            logger.error('Create mabl mailbox executor requires variableName parameter');
            return {
                success: false,
            };
        }
        const variableName = `user.${toolParams.variableName}`;
        const variable = {
            variableType: mablscriptFind_1.VariableType.MABL_MAILBOX,
            name: variableName,
            humanizedName: toolParams.variableName,
            value: variable_constants_1.EMPTY_VARIABLE_VALUE_PLACEHOLDER,
            flowStepIndex: [],
            source: mablscriptFind_1.LegacyVariableSource.TEMPLATE,
            readOnly: false,
            maskDisplay: false,
        };
        const variableAction = {
            action: 'set-variable',
            listener: 'set-variable',
            variable,
        };
        const contextInfo = await stateProvider.getActiveContextInfo();
        eventHandler.saveVariable(variable);
        const result = await (0, toolExecutor_types_1.recordStepAndTrackResult)(() => (0, stepCapture_1.recordTrainedStep)(variableAction, contextInfo, true, payload.toolCall.toolDescription, stateProvider, eventHandler), 0, stateProvider, eventHandler, logger);
        return {
            ...result,
            variable_name: toolParams.variableName,
            variable_value: variable_constants_1.EMPTY_VARIABLE_VALUE_PLACEHOLDER,
        };
    },
};
function isCreateMablMailboxParams(toolParams) {
    return typeof toolParams?.variableName === 'string';
}
