// /discord-install-url command - Show the bot install URL for current mode.
// In gateway mode this URL includes state credentials and must stay private.
import { MessageFlags } from 'discord.js';
import { getBotTokenWithMode } from '../database.js';
import { SILENT_MESSAGE_FLAGS } from '../discord-utils.js';
import { generateDiscordInstallUrlForBot } from '../install-url.js';
export async function handleDiscordInstallUrlCommand({ command, }) {
    const bot = await getBotTokenWithMode();
    if (!bot) {
        await command.reply({
            content: 'No bot configured yet. Run `kimaki` in your terminal first.',
            flags: MessageFlags.Ephemeral | SILENT_MESSAGE_FLAGS,
        });
        return;
    }
    const installUrl = generateDiscordInstallUrlForBot({
        appId: bot.appId,
        mode: bot.mode,
        clientId: bot.clientId,
        clientSecret: bot.clientSecret,
    });
    if (installUrl instanceof Error) {
        await command.reply({
            content: `Failed to build install URL: ${installUrl.message}`,
            flags: MessageFlags.Ephemeral | SILENT_MESSAGE_FLAGS,
        });
        return;
    }
    const privacyLine = bot.mode === 'gateway'
        ? 'This URL contains your gateway credentials. Do not share it.'
        : 'Use this URL to install your bot in another server.';
    await command.reply({
        content: `${privacyLine}\n${installUrl}`,
        flags: MessageFlags.Ephemeral | SILENT_MESSAGE_FLAGS,
    });
}
