import { type ChatInputCommandInteraction } from 'discord.js';
import { t } from '@nexumi/shared';
import type { Locale } from '@nexumi/shared';

export async function requirePermission(
  interaction: ChatInputCommandInteraction,
  permission: bigint,
  locale: Locale
): Promise<boolean> {
  const member = interaction.memberPermissions;
  if (!member?.has(permission)) {
    await interaction.reply({
      content: t(locale, 'generic.noPermission'),
      ephemeral: true
    });
    return false;
  }

  if (!interaction.guild?.members.me?.permissions.has(permission)) {
    await interaction.reply({
      content: t(locale, 'generic.botMissingPermission').replace(
        '{permission}',
        permission.toString()
      ),
      ephemeral: true
    });
    return false;
  }

  return true;
}
