import { REST, Routes } from "discord.js";

import type { AppConfig } from "../config.js";
import { TEAM_COMMAND_NAME } from "../commands/team.js";
import { teamSlashCommand } from "./team-command.js";

export async function registerCommands(config: AppConfig): Promise<void> {
  const rest = new REST({ version: "10" }).setToken(config.token);
  const route = config.guildId
    ? Routes.applicationGuildCommands(config.clientId, config.guildId)
    : Routes.applicationCommands(config.clientId);

  await rest.put(route, { body: [teamSlashCommand.toJSON()] });

  const scope = config.guildId ? `서버(${config.guildId})` : "전체 서버";
  console.log(`[명령 등록] ${scope}에 /${TEAM_COMMAND_NAME} 명령을 등록했습니다.`);
}
