"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.registerSlashCommand = registerSlashCommand;
exports.unregisterSlashCommand = unregisterSlashCommand;
exports.handleSlashCommand = handleSlashCommand;
exports.getRegisteredCommands = getRegisteredCommands;
const commands = new Map();
function registerSlashCommand(command) {
    commands.set(command.name, command);
}
function unregisterSlashCommand(name) {
    commands.delete(name);
}
async function handleSlashCommand(input) {
    const trimmed = input.trim();
    if (!trimmed.startsWith("/")) {
        return { handled: false };
    }
    const parts = trimmed.slice(1).split(/\s+/);
    const commandName = parts[0]?.toLowerCase();
    const args = parts.slice(1);
    if (!commandName) {
        return { handled: false };
    }
    const command = commands.get(commandName);
    if (!command) {
        return {
            // for now - return false
            handled: false,
            error: `Unknown command: /${commandName}`,
        };
    }
    try {
        return await command.handler(args, trimmed);
    }
    catch (err) {
        return {
            handled: true,
            error: err instanceof Error ? err.message : "Command failed",
        };
    }
}
function getRegisteredCommands() {
    return Array.from(commands.values());
}
//# sourceMappingURL=slash-commands.js.map