"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.registerTopicTools = registerTopicTools;
const api = __importStar(require("../../../api/topics"));
const schemas_1 = require("./schemas");
function registerTopicTools(server) {
    // mirrors GET /api/topics
    server.registerTool('list_topics', {
        title: 'List Topics',
        description: 'List topics in the event catalog with optional category and search filters.',
        inputSchema: schemas_1.listTopicsSchema,
    }, async (args) => {
        const result = await api.listTopics(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/topics/by-name/:topic
    server.registerTool('get_topic', {
        title: 'Get Topic',
        description: 'Get a single topic by name, including schema and example payload.',
        inputSchema: schemas_1.getTopicSchema,
    }, async (args) => {
        const result = await api.getTopic(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/topics
    server.registerTool('create_topic', {
        title: 'Create Topic',
        description: 'Register a new topic in the event catalog. Topics document what ' +
            'events are published so agents can discover and subscribe.',
        inputSchema: schemas_1.createTopicSchema,
    }, async (args) => {
        const result = await api.createTopic(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/topics/by-name/:topic
    server.registerTool('update_topic', {
        title: 'Update Topic',
        description: 'Update a topic in the event catalog.',
        inputSchema: schemas_1.updateTopicSchema,
    }, async (args) => {
        const result = await api.updateTopic(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/topics/by-name/:topic
    server.registerTool('delete_topic', {
        title: 'Delete Topic',
        description: 'Delete a topic from the catalog (system topics are protected).',
        inputSchema: schemas_1.deleteTopicSchema,
    }, async (args) => {
        const result = await api.deleteTopic(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) }] };
    });
}
