import {
  applyCommandDescription,
  applyOptionDescription,
  localizedChoice
} from '@nexumi/shared';
import { PermissionFlagsBits, SlashCommandBuilder } from 'discord.js';

// Discord forbids mixing SUB_COMMAND_GROUP and SUB_COMMAND siblings.
// SPEC `/ticket panel create` is represented as subcommand `panel_create`.
export const ticketCommandData = applyCommandDescription(
  new SlashCommandBuilder()
    .setName('ticket')
    .setDefaultMemberPermissions(PermissionFlagsBits.ManageGuild)
    .addSubcommand((s) =>
      applyCommandDescription(s.setName('panel_create'), 'ticket.panel.create.description')
        .addStringOption((o) =>
          applyOptionDescription(o.setName('name').setRequired(true), 'ticket.panel.create.options.name')
        )
        .addStringOption((o) =>
          applyOptionDescription(
            o.setName('description'),
            'ticket.panel.create.options.description'
          )
        )
    )
    .addSubcommand((s) =>
      applyCommandDescription(s.setName('category_create'), 'ticket.category.create.description')
        .addStringOption((o) =>
          applyOptionDescription(
            o.setName('name').setRequired(true),
            'ticket.category.create.options.name'
          )
        )
        .addRoleOption((o) =>
          applyOptionDescription(
            o.setName('support_role').setRequired(true),
            'ticket.category.create.options.support_role'
          )
        )
    )
    .addSubcommand((s) =>
      applyCommandDescription(s.setName('close'), 'ticket.close.description').addStringOption((o) =>
        applyOptionDescription(o.setName('reason'), 'ticket.close.options.reason')
      )
    )
    .addSubcommand((s) => applyCommandDescription(s.setName('claim'), 'ticket.claim.description'))
    .addSubcommand((s) =>
      applyCommandDescription(s.setName('add'), 'ticket.add.description').addUserOption((o) =>
        applyOptionDescription(o.setName('user').setRequired(true), 'ticket.common.options.user')
      )
    )
    .addSubcommand((s) =>
      applyCommandDescription(s.setName('remove'), 'ticket.remove.description').addUserOption((o) =>
        applyOptionDescription(o.setName('user').setRequired(true), 'ticket.common.options.user')
      )
    )
    .addSubcommand((s) =>
      applyCommandDescription(s.setName('rename'), 'ticket.rename.description').addStringOption((o) =>
        applyOptionDescription(o.setName('name').setRequired(true), 'ticket.rename.options.name')
      )
    )
    .addSubcommand((s) =>
      applyCommandDescription(s.setName('priority'), 'ticket.priority.description').addStringOption(
        (o) =>
          applyOptionDescription(o.setName('level').setRequired(true), 'ticket.priority.options.level')
            .addChoices(
              localizedChoice('ticket.priority.choice.low', 'LOW'),
              localizedChoice('ticket.priority.choice.normal', 'NORMAL'),
              localizedChoice('ticket.priority.choice.high', 'HIGH'),
              localizedChoice('ticket.priority.choice.urgent', 'URGENT')
            )
      )
    ),
  'ticket.description'
);
