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

export const warningsCommand: CommandModule = {
  data: new SlashCommandBuilder()
    .setName("warnings")
    .setDescription("사용자 경고 내역을 확인합니다")
    .addUserOption((opt) => opt.setName("user").setDescription("대상 유저").setRequired(true)),
  async execute(interaction) {
    if (!interaction.guildId) return;
    const user = interaction.options.getUser("user", true);
    const rows = await moderationService.getWarnings(interaction.guildId, user.id);
    if (rows.length === 0) {
      await interaction.reply("경고 내역이 없습니다.");
      return;
    }
    const text = rows.map((r, i) => `${i + 1}. ${r.reason} (${r.createdAt.toISOString().slice(0, 10)})`).join("\n");
    await interaction.reply(`경고 내역 <@${user.id}>:\n${text}`);
  },
};
