import { PermissionFlagsBits, SlashCommandBuilder } from "discord.js";
import type { CommandModule } from "../../discord/types.js";
import { moderationService } from "../../services/moderation/moderation-service.js";

export const warnCommand: CommandModule = {
  data: new SlashCommandBuilder()
    .setName("warn")
    .setDescription("사용자에게 경고를 부여합니다")
    .setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers)
    .addUserOption((opt) => opt.setName("user").setDescription("대상 유저").setRequired(true))
    .addStringOption((opt) => opt.setName("reason").setDescription("사유").setRequired(true)),
  async execute(interaction) {
    if (!interaction.guildId) return;
    const user = interaction.options.getUser("user", true);
    const reason = interaction.options.getString("reason", true);
    const row = await moderationService.warnUser({
      guildId: interaction.guildId,
      userId: user.id,
      moderatorId: interaction.user.id,
      reason,
    });
    await interaction.reply(`경고 등록 완료 (#${row.id}) <@${user.id}> - ${reason}`);
  },
};
