"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.registerPipelineTools = registerPipelineTools;
const api = __importStar(require("../../../api/pipelines"));
const schemas_1 = require("./schemas");
function registerPipelineTools(server) {
    // mirrors GET /api/pipelines/entities
    server.registerTool('list_pipeline_entities', {
        title: 'List Pipeline Entities',
        description: 'List distinct entity (tool) names from pipeline jobs, supplemented ' +
            'with graph topics from compiled YAML workflows.',
        inputSchema: schemas_1.listPipelineEntitiesSchema,
    }, async (args) => {
        const result = await api.listEntities({ app_id: args.app_id || 'durable' });
        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/pipelines
    server.registerTool('list_pipeline_jobs', {
        title: 'List Pipeline Jobs',
        description: 'List pipeline jobs with optional entity, search, and status filters.',
        inputSchema: schemas_1.listPipelineJobsSchema,
    }, async (args) => {
        const result = await api.listJobs({ ...args, app_id: args.app_id || 'durable' });
        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/pipelines/:jobId/execution
    server.registerTool('get_pipeline_execution', {
        title: 'Get Pipeline Execution',
        description: 'Export execution details for a specific pipeline job.',
        inputSchema: schemas_1.getJobExecutionSchema,
    }, async (args) => {
        const result = await api.getJobExecution({
            jobId: args.job_id,
            app_id: args.app_id || 'durable',
        });
        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 POST /api/pipelines/:jobId/interrupt
    server.registerTool('interrupt_pipeline_job', {
        title: 'Interrupt Pipeline Job',
        description: 'Interrupt a running pipeline job.',
        inputSchema: schemas_1.interruptJobSchema,
    }, async (args) => {
        const result = await api.interruptJob({
            jobId: args.job_id,
            topic: args.topic,
            app_id: args.app_id || 'durable',
        });
        if (result.error) {
            return { content: [{ type: 'text', text: JSON.stringify({ error: result.error }) }], isError: true };
        }
        return { content: [{ type: 'text', text: JSON.stringify(result.data) }] };
    });
}
