import type { AutocompleteInteraction, ChatInputCommandInteraction, ClientEvents, SlashCommandBuilder, SlashCommandOptionsOnlyBuilder, SlashCommandSubcommandsOnlyBuilder } from "discord.js";
import { LootType, EffectType } from "./constants";
import { DrizzleClient } from "../db/DrizzleClient";

export interface Command {
    data: SlashCommandBuilder | SlashCommandOptionsOnlyBuilder | SlashCommandSubcommandsOnlyBuilder;
    execute: (interaction: ChatInputCommandInteraction) => Promise<void> | void;
    autocomplete?: (interaction: AutocompleteInteraction) => Promise<void> | void;
    category?: string;
    beta?: boolean;
    featureFlag?: string;
}

export interface Event<K extends keyof ClientEvents> {
    name: K;
    once?: boolean;
    execute: (...args: ClientEvents[K]) => Promise<void> | void;
}

export type ItemEffect =
    | { type: EffectType.ADD_XP; amount: number }
    | { type: EffectType.ADD_BALANCE; amount: number }
    | { type: EffectType.XP_BOOST; multiplier: number; durationSeconds?: number; durationMinutes?: number; durationHours?: number }
    | { type: EffectType.TEMP_ROLE; roleId: string; durationSeconds?: number; durationMinutes?: number; durationHours?: number }
    | { type: EffectType.REPLY_MESSAGE; message: string }
    | { type: EffectType.COLOR_ROLE; roleId: string }
    | { type: EffectType.LOOTBOX; pool: LootTableItem[] };

export interface LootTableItem {
    type: LootType;
    weight: number;
    amount?: number; // For CURRENCY, XP
    itemId?: number; // For ITEM
    minAmount?: number; // Optional range for CURRENCY/XP
    maxAmount?: number; // Optional range for CURRENCY/XP
    message?: string; // Optional custom message for this outcome
}

export interface ItemUsageData {
    consume: boolean;
    effects: ItemEffect[];
}

export type DbClient = typeof DrizzleClient;
export type Transaction = Parameters<Parameters<DbClient['transaction']>[0]>[0];
