/**
 * Types for the LangGraph-backed AI Agent layer.
 *
 * The backend models are `encoach.ai.agent` and `encoach.ai.tool`; the
 * controller is `backend/custom_addons/encoach_ai/controllers/agents_controller.py`.
 */

export type AgentGraphType = "simple" | "plan_review_revise" | "rag" | "react";

export type AgentResponseFormat = "text" | "json";

export type AIToolCategory =
  | "retrieval"
  | "persistence"
  | "quality"
  | "scoring"
  | "reference"
  | "other";

export interface AIToolSummary {
  id: number;
  key: string;
  name: string;
  description: string;
  category: AIToolCategory;
  schema: Record<string, unknown>;
  mutates: boolean;
  active: boolean;
}

export interface AIAgentSummary {
  id: number;
  key: string;
  name: string;
  description: string;
  model: string;
  fallback_model: string;
  temperature: number;
  max_tokens: number;
  response_format: AgentResponseFormat;
  graph_type: AgentGraphType;
  max_revisions: number;
  quality_checks: string[];
  prompt_key: string;
  tool_count: number;
  tool_keys: string[];
  active: boolean;
}

export interface AIAgent extends AIAgentSummary {
  system_prompt: string;
  tools: AIToolSummary[];
}

export interface AIAgentUpdateInput {
  name?: string;
  description?: string;
  system_prompt?: string;
  prompt_key?: string;
  model?: string;
  fallback_model?: string;
  temperature?: number;
  max_tokens?: number;
  max_revisions?: number;
  response_format?: AgentResponseFormat;
  graph_type?: AgentGraphType;
  quality_checks?: string;
  active?: boolean;
  tool_keys?: string[];
}

export interface AIAgentTestRequest {
  variables?: Record<string, unknown>;
  payload?: unknown;
  language?: string;
}

export interface AIAgentTestResponse {
  error: string;
  output: unknown;
  output_raw: string;
  tool_results: Array<{
    tool: string;
    args: unknown;
    result: unknown;
  }>;
  retrieval_hits: number;
  revisions_used: number;
  quality_issues: string[];
  iterations: number;
}
