import { SlashCommandBuilder, ChatInputCommandInteraction } from 'discord.js';
import { SlashCommand } from '../../utils/types';
import { prisma } from '../../database/index';

const command: SlashCommand = {
  guildOnly: true,
  data: new SlashCommandBuilder()
    .setName('ticketstatus')
    .setDescription('Ändert den Status des aktuellen Tickets.')
    .addStringOption((opt) =>
      opt
        .setName('status')
        .setDescription('Neuer Status')
        .addChoices(
          { name: 'Neu', value: 'neu' },
          { name: 'In Bearbeitung', value: 'in_bearbeitung' },
          { name: 'Warten auf User', value: 'warten_auf_user' },
          { name: 'Erledigt', value: 'erledigt' }
        )
        .setRequired(true)
    ),
  async execute(interaction: ChatInputCommandInteraction) {
    const status = interaction.options.getString('status', true) as any;
    const ticket = await prisma.ticket.findFirst({ where: { channelId: interaction.channelId } });
    if (!ticket) {
      await interaction.reply({ content: 'Kein Ticket in diesem Kanal.', ephemeral: true });
      return;
    }
    await prisma.ticket.update({ where: { id: ticket.id }, data: { status } });
    await interaction.reply({ content: `Ticket-Status geändert zu **${status}**.` });
  }
};

export default command;
