"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.setCookieExecutor = void 0;
const toolExecutor_types_1 = require("../toolExecutor-types");
const stepCapture_1 = require("../../background/capture/stepCapture");
const mablscript_step_types_1 = require("../../sharedUtils/mablscript-step-types");
exports.setCookieExecutor = {
    needsFind: () => false,
    getStepType: () => mablscript_step_types_1.StepType.SET_COOKIE,
    execute: async (payload, stateProvider, eventHandler, logger) => {
        const toolParams = payload.toolCall.toolParams;
        if (!toolParams?.name || !toolParams?.value) {
            logger.error('Set cookie executor requires both name and value parameters');
            return {
                success: false,
                errorMessage: 'Cookie name and value are required',
            };
        }
        const contextInfo = payload.contextInfo ?? (await stateProvider.getActiveContextInfo());
        const step = {
            action: 'record',
            listener: 'set-cookie',
            cookie: {
                name: toolParams.name,
                value: toolParams.value,
                domain: toolParams.domain,
                path: toolParams.path,
                secure: toolParams.secure,
                httpOnly: toolParams.httpOnly,
                expires: toolParams.expires,
                sameSite: toolParams.sameSite,
            },
        };
        return (0, toolExecutor_types_1.recordStepAndTrackResult)(() => (0, stepCapture_1.recordTrainedStep)(step, contextInfo, true, undefined, stateProvider, eventHandler), 0, stateProvider, eventHandler, logger);
    },
};
