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('ticketpriority')
    .setDescription('Setzt die Priorität des aktuellen Tickets.')
    .addStringOption((opt) =>
      opt
        .setName('level')
        .setDescription('Priorität')
        .addChoices(
          { name: 'Low', value: 'low' },
          { name: 'Normal', value: 'normal' },
          { name: 'High', value: 'high' }
        )
        .setRequired(true)
    ),
  async execute(interaction: ChatInputCommandInteraction) {
    const channelId = interaction.channelId;
    const ticket = await prisma.ticket.findFirst({ where: { channelId } });
    if (!ticket) {
      await interaction.reply({ content: 'Kein Ticket in diesem Kanal.', ephemeral: true });
      return;
    }
    const level = interaction.options.getString('level', true) as 'low' | 'normal' | 'high';
    await prisma.ticket.update({ where: { id: ticket.id }, data: { priority: level } });
    await interaction.reply({ content: `Ticket-Priorität gesetzt auf **${level}**.` });
  }
};

export default command;
