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

const command: SlashCommand = {
  guildOnly: true,
  data: new SlashCommandBuilder()
    .setName('close')
    .setDescription('Schließt das aktuelle Ticket.')
    .addStringOption((opt) => opt.setName('reason').setDescription('Grund')),
  async execute(interaction: ChatInputCommandInteraction) {
    const reason = interaction.options.getString('reason') ?? undefined;
    const ok = await context.tickets.closeTicket(interaction, reason);
    if (!ok) {
      await interaction.reply({ content: 'Kein Ticket in diesem Kanal gefunden.', ephemeral: true });
      return;
    }
    await interaction.reply({ content: 'Ticket geschlossen.' });
  }
};

export default command;
