"use strict";
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    var desc = Object.getOwnPropertyDescriptor(m, k);
    if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
      desc = { enumerable: true, get: function() { return m[k]; } };
    }
    Object.defineProperty(o, k2, desc);
}) : (function(o, m, k, k2) {
    if (k2 === undefined) k2 = k;
    o[k2] = m[k];
}));
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
    Object.defineProperty(o, "default", { enumerable: true, value: v });
}) : function(o, v) {
    o["default"] = v;
});
var __importStar = (this && this.__importStar) || (function () {
    var ownKeys = function(o) {
        ownKeys = Object.getOwnPropertyNames || function (o) {
            var ar = [];
            for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
            return ar;
        };
        return ownKeys(o);
    };
    return function (mod) {
        if (mod && mod.__esModule) return mod;
        var result = {};
        if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
        __setModuleDefault(result, mod);
        return result;
    };
})();
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerExportTools = registerExportTools;
const api = __importStar(require("../../../api/exports"));
const schemas_1 = require("./schemas");
function registerExportTools(server) {
    // mirrors GET /api/workflow-states/jobs
    server.registerTool('list_export_jobs', {
        title: 'List Export Jobs',
        description: 'List workflow jobs with optional filtering and pagination.',
        inputSchema: schemas_1.listExportJobsSchema,
    }, async (args) => {
        const result = await api.listJobs(args);
        if (result.error) {
            return { content: [{ type: 'text', text: JSON.stringify({ error: result.error }) }], isError: true };
        }
        return { content: [{ type: 'text', text: JSON.stringify(result.data) }] };
    });
    // mirrors GET /api/workflow-states/:workflowId
    server.registerTool('export_workflow_state', {
        title: 'Export Workflow State',
        description: 'Export the full workflow state using HotMesh durable export. ' +
            'Optionally allow/block specific fields.',
        inputSchema: schemas_1.exportWorkflowStateSchema,
    }, async (args) => {
        const result = await api.exportWorkflowState({
            workflowId: args.workflow_id,
            allow: args.allow,
            block: args.block,
            values: args.values,
        });
        if (result.error) {
            return { content: [{ type: 'text', text: JSON.stringify({ error: result.error }) }], isError: true };
        }
        return { content: [{ type: 'text', text: JSON.stringify(result.data) }] };
    });
    // mirrors GET /api/workflow-states/:workflowId/execution
    server.registerTool('export_workflow_execution', {
        title: 'Export Workflow Execution',
        description: 'Export workflow state as a structured execution event history. ' +
            'Useful for debugging and workflow compilation.',
        inputSchema: schemas_1.exportWorkflowExecutionSchema,
    }, async (args) => {
        const result = await api.exportWorkflowExecution({
            workflowId: args.workflow_id,
            excludeSystem: args.excludeSystem,
            omitResults: args.omitResults,
            mode: args.mode,
            maxDepth: args.maxDepth,
        });
        if (result.error) {
            return { content: [{ type: 'text', text: JSON.stringify({ error: result.error }) }], isError: true };
        }
        return { content: [{ type: 'text', text: JSON.stringify(result.data) }] };
    });
    // mirrors GET /api/workflow-states/:workflowId/status
    server.registerTool('get_export_status', {
        title: 'Get Workflow Status',
        description: 'Return the numeric status semaphore for a workflow.',
        inputSchema: schemas_1.getExportStatusSchema,
    }, async (args) => {
        const result = await api.getWorkflowStatus({ workflowId: args.workflow_id });
        if (result.error) {
            return { content: [{ type: 'text', text: JSON.stringify({ error: result.error }) }], isError: true };
        }
        return { content: [{ type: 'text', text: JSON.stringify(result.data) }] };
    });
}
