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

const feedTypeChoices = [
  localizedChoice('feeds.choice.type.twitch', 'TWITCH'),
  localizedChoice('feeds.choice.type.youtube', 'YOUTUBE'),
  localizedChoice('feeds.choice.type.rss', 'RSS'),
  localizedChoice('feeds.choice.type.reddit', 'REDDIT')
] as const;

export const feedsCommandData = applyCommandDescription(
  new SlashCommandBuilder()
    .setName('feeds')
    .addSubcommand((sub) =>
      applyCommandDescription(sub.setName('add'), 'feeds.add.description')
        .addStringOption((o) =>
          applyOptionDescription(o.setName('type').setRequired(true), 'feeds.add.options.type').addChoices(
            ...feedTypeChoices
          )
        )
        .addStringOption((o) =>
          applyOptionDescription(o.setName('source').setRequired(true), 'feeds.add.options.source')
        )
        .addChannelOption((o) =>
          applyOptionDescription(
            o.setName('channel').addChannelTypes(ChannelType.GuildText).setRequired(true),
            'feeds.add.options.channel'
          )
        )
        .addRoleOption((o) =>
          applyOptionDescription(o.setName('role'), 'feeds.add.options.role')
        )
        .addStringOption((o) =>
          applyOptionDescription(o.setName('template'), 'feeds.add.options.template')
        )
    )
    .addSubcommand((sub) =>
      applyCommandDescription(sub.setName('remove'), 'feeds.remove.description').addStringOption((o) =>
        applyOptionDescription(o.setName('id').setRequired(true), 'feeds.remove.options.id')
      )
    )
    .addSubcommand((sub) => applyCommandDescription(sub.setName('list'), 'feeds.list.description'))
    .addSubcommand((sub) =>
      applyCommandDescription(sub.setName('test'), 'feeds.test.description').addStringOption((o) =>
        applyOptionDescription(o.setName('id').setRequired(true), 'feeds.test.options.id')
      )
    ),
  'feeds.description'
);
