"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.registerBotAccountTools = registerBotAccountTools;
const api = __importStar(require("../../../api/bot-accounts"));
const schemas_1 = require("./schemas");
function registerBotAccountTools(server) {
    // mirrors GET /api/bot-accounts
    server.registerTool('list_bot_accounts', {
        title: 'List Bot Accounts',
        description: 'List all bot (service) accounts with pagination.',
        inputSchema: schemas_1.listBotsSchema,
    }, async (args) => {
        const result = await api.listBots(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/bot-accounts/:id
    server.registerTool('get_bot_account', {
        title: 'Get Bot Account',
        description: 'Get a single bot account by ID.',
        inputSchema: schemas_1.getBotSchema,
    }, async (args) => {
        const result = await api.getBot(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/bot-accounts
    server.registerTool('create_bot_account', {
        title: 'Create Bot Account',
        description: 'Create a new bot (service) account with optional roles. ' +
            'Bot accounts can run workflows and hold API keys.',
        inputSchema: schemas_1.createBotSchema,
    }, async (args) => {
        const result = await api.createBot(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/bot-accounts/:id
    server.registerTool('update_bot_account', {
        title: 'Update Bot Account',
        description: 'Update a bot account (display name, description, status).',
        inputSchema: schemas_1.updateBotSchema,
    }, async (args) => {
        const result = await api.updateBot(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/bot-accounts/:id
    server.registerTool('delete_bot_account', {
        title: 'Delete Bot Account',
        description: 'Delete a bot account and all its API keys.',
        inputSchema: schemas_1.deleteBotSchema,
    }, async (args) => {
        const result = await api.deleteBot(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/bot-accounts/:id/api-keys
    server.registerTool('create_bot_api_key', {
        title: 'Create Bot API Key',
        description: 'Generate a new API key for a bot account. Returns the raw key ' +
            'ONCE — it cannot be retrieved again.',
        inputSchema: schemas_1.createBotApiKeySchema,
    }, async (args) => {
        const result = await api.createBotKey(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/bot-accounts/:id/api-keys/:keyId
    server.registerTool('revoke_bot_api_key', {
        title: 'Revoke Bot API Key',
        description: 'Revoke (delete) an API key for a bot account.',
        inputSchema: schemas_1.revokeBotKeySchema,
    }, async (args) => {
        const result = await api.revokeBotKey({ keyId: args.key_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) }] };
    });
}
