const { SlashCommandBuilder, EmbedBuilder } = require('discord.js');
const { getServerMode, getEmbedColor } = require('../utils/modeHelper');

const HUG_GIFS = [
  'https://media.giphy.com/media/l2QDM9Jnim1YVILXa/giphy.gif',
  'https://media.giphy.com/media/od5H3PmEG5EVq/giphy.gif',
  'https://media.giphy.com/media/ZQN9jsRWp1M76/giphy.gif',
  'https://media.giphy.com/media/lrr9rHuoJOE0w/giphy.gif',
  'https://media.giphy.com/media/3M4NpbLCTxBqU/giphy.gif',
];

const HUG_MESSAGES = [
  '{user} gives {target} a warm hug!',
  '{user} wraps {target} in a cozy embrace!',
  '{user} hugs {target} tightly!',
  '{user} sends virtual hugs to {target}!',
  '{user} gives {target} the biggest hug ever!',
];

module.exports = {
  data: new SlashCommandBuilder()
    .setName('hug')
    .setDescription('Give someone a virtual hug')
    .addUserOption(option =>
      option.setName('user')
        .setDescription('The user to hug')
        .setRequired(true)
    ),

  async execute(interaction, supabase, client) {
    const targetUser = interaction.options.getUser('user');
    const mode = await getServerMode(supabase, interaction.guildId);

    const gif = HUG_GIFS[Math.floor(Math.random() * HUG_GIFS.length)];
    const message = HUG_MESSAGES[Math.floor(Math.random() * HUG_MESSAGES.length)]
      .replace('{user}', interaction.user.toString())
      .replace('{target}', targetUser.toString());

    const embed = new EmbedBuilder()
      .setColor(0xFFB6C1)
      .setDescription(`🤗 ${message}`)
      .setImage(gif)
      .setTimestamp();

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