/**
 * Discord bot invite URL helpers.
 */
const DEFAULT_PERMISSIONS = "8"; // Administrator (Discord invite UI still shows the checklist)

export function getBotInviteUrl(clientId?: string | null): string | null {
  const id =
    (clientId || "").trim() ||
    (process.env.DISCORD_CLIENT_ID || "").trim() ||
    (process.env.NEXT_PUBLIC_DISCORD_CLIENT_ID || "").trim();

  if (!id) return null;

  const params = new URLSearchParams({
    client_id: id,
    permissions: process.env.DISCORD_BOT_PERMISSIONS?.trim() || DEFAULT_PERMISSIONS,
    scope: "bot applications.commands",
  });

  return `https://discord.com/oauth2/authorize?${params.toString()}`;
}
