/** Argument definition for a slash command */
export interface CommandArgDef {
  name: string;
  type: 'string' | 'enum';
  optional: boolean;
  /** For enum type, the allowed values */
  values?: string[];
  description?: string;
}

/** A single command definition served by the gateway */
export interface CommandDef {
  /** Command name without slash prefix, e.g. "model" */
  name: string;
  /** Short aliases, e.g. ["m"] */
  aliases: string[];
  /** Human-readable description */
  description: string;
  /** Argument schema */
  args?: CommandArgDef[];
  /** Nested subcommands (e.g. provider → login, logout) */
  subcommands?: CommandDef[];
  /** Origin of this command */
  scope: 'core' | 'agent' | 'skill' | 'plugin' | 'admin';
  /** Where the command executes */
  execution: 'local' | 'socket' | 'rest' | 'hybrid';
  /** Whether this command is currently available */
  available: boolean;
}

/** Full command manifest pushed from gateway to TUI */
export interface CommandManifest {
  commands: CommandDef[];
  skills: SkillCommandDef[];
  /** Manifest version — TUI compares to detect changes */
  version: number;
}

/** Skill registered as /skill:name */
export interface SkillCommandDef {
  /** Skill name (used as /skill:{name}) */
  name: string;
  description: string;
  /** Whether the skill is currently loaded and available */
  available: boolean;
}

/** Payload for commands:manifest event */
export interface CommandManifestPayload {
  manifest: CommandManifest;
}

/** Payload for system:reload broadcast */
export interface SystemReloadPayload {
  commands: CommandDef[];
  skills: SkillCommandDef[];
  providers: string[];
  message: string;
}

/** Client request to execute a slash command via socket */
export interface SlashCommandPayload {
  conversationId: string;
  command: string;
  args?: string;
  /** One-time server-issued approval for a privileged command execution. */
  approvalId?: string;
}

/** Server response to a request to approve a privileged slash command. */
export interface SlashCommandApprovalResultPayload {
  conversationId: string;
  command: string;
  success: boolean;
  approvalId?: string;
  expiresAt?: string;
  message?: string;
}

/** Server response to a slash command */
export interface SlashCommandResultPayload {
  conversationId: string;
  command: string;
  success: boolean;
  message?: string;
  data?: Record<string, unknown>;
}

/** Parsed slash command (TUI-side, not a socket type) */
export interface ParsedCommand {
  /** Command name without slash, e.g. "model", "skill:brave-search" */
  command: string;
  /** Arguments string or null */
  args: string | null;
  /** Full raw input string */
  raw: string;
}
