"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.registerAgentTools = registerAgentTools;
const api = __importStar(require("../../../api/agents"));
const schemas_1 = require("./schemas");
function registerAgentTools(server) {
    // mirrors GET /api/agents
    server.registerTool('list_agents', {
        title: 'List Agents',
        description: 'List agent automations with optional status and knowledge domain filters. ' +
            'Returns agents with subscription counts and topic lists.',
        inputSchema: schemas_1.listAgentsSchema,
    }, async (args) => {
        const result = await api.listAgents(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/agents/:id
    server.registerTool('get_agent', {
        title: 'Get Agent',
        description: 'Get a single agent automation by ID, including aggregated stats ' +
            '(knowledge entry count, escalation count).',
        inputSchema: schemas_1.getAgentSchema,
    }, async (args) => {
        const result = await api.getAgent(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 POST /api/agents
    server.registerTool('create_agent', {
        title: 'Create Agent',
        description: 'Create a new agent automation with identity, goals, rules, ' +
            'optional schedules, and event subscriptions.',
        inputSchema: schemas_1.createAgentSchema,
    }, async (args) => {
        const result = await api.createAgent(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 PUT /api/agents/:id
    server.registerTool('update_agent', {
        title: 'Update Agent',
        description: 'Update an existing agent automation.',
        inputSchema: schemas_1.updateAgentSchema,
    }, async (args) => {
        const result = await api.updateAgent(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 DELETE /api/agents/:id
    server.registerTool('delete_agent', {
        title: 'Delete Agent',
        description: 'Delete an agent automation and all its subscriptions.',
        inputSchema: schemas_1.deleteAgentSchema,
    }, async (args) => {
        const result = await api.deleteAgent(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) }] };
    });
}
