const { SlashCommandBuilder, EmbedBuilder, GuildVerificationLevel } = require('discord.js');
const { colors, emojis } = require('../../utils/constants');

const verificationLevels = {
    [GuildVerificationLevel.None]: 'Aucune',
    [GuildVerificationLevel.Low]: 'Faible',
    [GuildVerificationLevel.Medium]: 'Moyenne',
    [GuildVerificationLevel.High]: 'Élevée',
    [GuildVerificationLevel.VeryHigh]: 'Très Élevée'
};

module.exports = {
    category: 'info',
    data: new SlashCommandBuilder()
        .setName('serverinfo')
        .setDescription('Affiche les informations du serveur.'),
    async execute(interaction) {
        const guild = interaction.guild;
        const owner = await guild.fetchOwner();

        const embed = new EmbedBuilder()
            .setAuthor({ 
                name: guild.name, 
                iconURL: guild.iconURL({ dynamic: true }) || undefined 
            })
            .setTitle(`${emojis.server} Informations du Serveur`)
            .setColor(colors.info)
            .setThumbnail(guild.iconURL({ dynamic: true, size: 256 }) || null)
            .addFields(
                { name: '👑 Propriétaire', value: `${owner.user.toString()}\n\`${owner.user.tag}\``, inline: true },
                { name: `${emojis.id} ID`, value: `\`${guild.id}\``, inline: true },
                { name: `${emojis.calendar} Créé le`, value: `<t:${Math.floor(guild.createdTimestamp / 1000)}:F>`, inline: true },
                { name: '👥 Membres', value: `\`${guild.memberCount.toLocaleString()}\``, inline: true },
                { name: '💬 Canaux', value: `\`${guild.channels.cache.size}\``, inline: true },
                { name: '😀 Emojis', value: `\`${guild.emojis.cache.size}\``, inline: true },
                { name: '🎭 Rôles', value: `\`${guild.roles.cache.size}\``, inline: true },
                { name: '✅ Vérification', value: `\`${verificationLevels[guild.verificationLevel] || 'Inconnue'}\``, inline: true },
                { name: '🔒 Sécurité', value: guild.mfaLevel === 1 ? '`Élevé (2FA)`' : '`Normal`', inline: true }
            )
            .setFooter({ text: `${guild.name} • ${interaction.client.user.username}`, iconURL: interaction.client.user.displayAvatarURL() })
            .setTimestamp();

        if (guild.description) {
            embed.setDescription(guild.description);
        }

        if (guild.banner) {
            embed.setImage(guild.bannerURL({ dynamic: true, size: 1024 }));
        }

        await interaction.reply({ embeds: [embed] });
    },
};