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

const registerEvents = ({ client }) => {

  client.player.on('trackStart', (queue, track) => {

    const nowPlayingEmbed = new EmbedBuilder()
      .setTitle('Now Playing')
      .setColor(process.env.EMBED_COLOR)
      .setDescription(`[${track.title}](${track.url})`)
      .addFields(
        { name: 'Requested By', value: `${track.requestedBy}`, inline: true },
        { name: 'Duration', value: track.duration, inline: true },
        { name: 'Queue', value: `${queue.tracks.length} song(s)`, inline: true },
        { name: 'Author', value: track.author, inline: true },
        { name: 'Source', value: track.source, inline: true },
        { name: 'Volume', value: `${queue.options.initialVolume}%`, inline: true },
        { name: 'Filters', value: queue.getFiltersEnabled().join('\n') || 'No filters active', inline: false },
      )
      .setThumbnail(track.thumbnail)
      .setTimestamp();

    queue.metadata.channel.send({ embeds: [nowPlayingEmbed] });
  });

  client.player.on('error', (queue, error) => {
    console.log(error);
  });
};

module.exports = { registerEvents };
