import { SlashCommandBuilder, PermissionFlagsBits, ChatInputCommandInteraction } from 'discord.js';
import { SlashCommand } from '../../utils/types';
import { context } from '../../config/context';

const command: SlashCommand = {
  guildOnly: true,
  data: new SlashCommandBuilder()
    .setName('unmute')
    .setDescription('Hebt einen Timeout auf.')
    .addUserOption((opt) => opt.setName('user').setDescription('Nutzer').setRequired(true))
    .setDefaultMemberPermissions(PermissionFlagsBits.ModerateMembers),
  async execute(interaction: ChatInputCommandInteraction) {
    if (!interaction.guild) return;
    const user = interaction.options.getUser('user', true);
    const member = await interaction.guild.members.fetch(user.id).catch(() => null);
    if (!member) {
      await interaction.reply({ content: 'Mitglied nicht gefunden.', ephemeral: true });
      return;
    }
    await member.timeout(null).catch(() => null);
    await interaction.reply({ content: `${user.tag} ist nun entmuted.` });
    context.logging.logAction(user, 'Unmute', undefined, interaction.guild);
  }
};

export default command;
