const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');

module.exports = {
    category: 'utility',
    data: new SlashCommandBuilder()
        .setName('ping')
		.setDescription('Affiche la latence du bot.'),
    async execute(interaction) {
		await interaction.deferReply();
		const sent = await interaction.fetchReply();

        const apiLatency = Math.round(interaction.client.ws.ping);
		const roundTripLatency = sent.createdTimestamp - interaction.createdTimestamp;

		const { colors, emojis } = require('../../utils/constants');
		
        const embed = new EmbedBuilder()
			.setAuthor({ 
				name: `${interaction.client.user.username}`, 
				iconURL: interaction.client.user.displayAvatarURL() 
			})
			.setTitle(`${emojis.ping} Statut de la Latence`)
			.setColor(colors.utility)
            .addFields(
				{ name: '🌐 Latence API', value: `\`${apiLatency}ms\``, inline: true },
				{ name: '⏱️ Latence Round-Trip', value: `\`${roundTripLatency}ms\``, inline: true }
            )
			.setFooter({ text: `${interaction.guild.name} • ${interaction.client.user.username}`, iconURL: interaction.client.user.displayAvatarURL() })
            .setTimestamp();

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