export class SlashCommandRegistry {
    specs;
    byName = new Map();
    constructor(specs = []) {
        this.specs = [];
        this.registerMany(specs);
    }
    register(spec) {
        const names = [spec.name, ...spec.aliases].map((name) => name.toLowerCase());
        for (const name of names) {
            if (!name.startsWith("/") && !name.startsWith(":")) {
                throw new Error(`Invalid slash command name: ${name}`);
            }
            if (this.byName.has(name)) {
                throw new Error(`Duplicate slash command name: ${name}`);
            }
        }
        this.specs.push(spec);
        for (const name of names)
            this.byName.set(name, spec);
    }
    registerMany(specs) {
        for (const spec of specs)
            this.register(spec);
    }
    find(command) {
        return this.byName.get(command.toLowerCase());
    }
    resolve(parsed) {
        return this.find(parsed.command);
    }
    list() {
        return this.specs;
    }
}
export function createSlashCommandRegistry(specs) {
    return new SlashCommandRegistry(specs);
}
