import {
  AutocompleteInteraction,
  CommandInteraction,
  ComponentInteraction,
  Constants,
  ModalSubmitInteraction,
  type ApplicationCommandOptionAutocomplete,
  type ApplicationCommandOptions,
  type ApplicationCommandStructure,
  type ChatInputApplicationCommandStructure,
} from '@projectdysnomia/dysnomia';
import type { CommandContext, PartialContext } from './command-context.type';

export interface CommandHandler<T extends ApplicationCommandStructure> {
  definition: T;
  execute: (interaction: ExecutableInteraction, ctx: CommandContext) => Promise<void>;
}

export type ExecutableInteraction = CommandInteraction | ModalSubmitInteraction | ComponentInteraction | AutocompleteInteraction;

export type ChatCommandDefinition = Omit<ChatInputApplicationCommandStructure, 'type'>;
export function createChatCommand(
  definition: ChatCommandDefinition,
  execute: (interaction: CommandInteraction, ctx: CommandContext) => Promise<void>,
): CommandHandler<ChatInputApplicationCommandStructure> {
  const def = definition as ChatInputApplicationCommandStructure;
  def.type = 1; // CHAT_INPUT
  return {
    definition: def,
    execute,
  };
}
