import { createCommand } from "@shared/lib/utils";
import { SlashCommandBuilder, PermissionFlagsBits } from "discord.js";
import { moderationService } from "@shared/modules/moderation/moderation.service";
import { getCasesListEmbed } from "@/modules/moderation/moderation.view";
import { withCommandErrorHandling } from "@lib/commandUtils";

export const notes = createCommand({
    data: new SlashCommandBuilder()
        .setName("notes")
        .setDescription("View all staff notes for a user")
        .addUserOption(option =>
            option
                .setName("user")
                .setDescription("The user to check notes for")
                .setRequired(true)
        )
        .setDefaultMemberPermissions(PermissionFlagsBits.Administrator),

    execute: async (interaction) => {
        await withCommandErrorHandling(
            interaction,
            async () => {
                const targetUser = interaction.options.getUser("user", true);

                // Get all notes for the user
                const userNotes = await moderationService.getUserNotes(targetUser.id);

                // Display the notes
                await interaction.editReply({
                    embeds: [getCasesListEmbed(
                        userNotes,
                        `📝 Staff Notes for ${targetUser.username}`,
                        userNotes.length === 0 ? undefined : `Total notes: **${userNotes.length}**`
                    )]
                });
            },
            { ephemeral: true }
        );
    }
});
