/**
 * Agent Mode Types
 * Types for the AI-powered API documentation assistant
 */

import type { BrainfishRESTRequest } from '../types'

// Chat message types
export interface AgentMessage {
  id: string
  role: 'user' | 'assistant' | 'system'
  content: string
  createdAt: Date
  toolInvocations?: ToolInvocation[]
}

export interface ToolInvocation {
  toolCallId: string
  toolName: string
  args: Record<string, unknown>
  result?: unknown
  state: 'pending' | 'result' | 'error'
}

// Endpoint index for AI context
export interface EndpointIndex {
  id: string
  name: string
  method: string
  path: string
  description: string | null
  parameters: string[]
  hasBody: boolean
  tags: string[]
}

// Prefill data from agent
export interface PrefillData {
  params?: Array<{ key: string; value: string }>
  headers?: Array<{ key: string; value: string }>
  body?: string
  pathVariables?: Array<{ key: string; value: string }>
}

// Agent context state
export interface AgentState {
  mode: 'agent' | 'docs'
  messages: AgentMessage[]
  isLoading: boolean
  currentEndpoint: BrainfishRESTRequest | null
}

// Tool definitions
export type AgentToolName = 
  | 'search_endpoints'
  | 'navigate_to_endpoint'
  | 'prefill_parameters'
  | 'get_endpoint_details'
  | 'get_current_request'
  | 'check_request_validity'
  | 'send_request'
  | 'switch_to_notes'
  | 'list_notes'
  | 'open_file'
  | 'create_folder'
  | 'create_file'
  | 'write_file'
  | 'delete_file'

// Request validation result
export interface RequestValidationResult {
  isValid: boolean
  endpoint: {
    id: string
    name: string
    method: string
    path: string
  }
  validation: {
    pathParams: {
      required: string[]
      filled: string[]
      missing: string[]
    }
    queryParams: {
      required: string[]
      filled: string[]
      missing: string[]
    }
    body: {
      required: boolean
      hasContent: boolean
      requiredFields: string[]
      missingFields: string[]
    }
    auth: {
      required: boolean
      configured: boolean
      type: string | null
    }
  }
  summary: string
}

// Search results
export interface EndpointSearchResult {
  endpoint: EndpointIndex
  score: number
  matchReason: string
}

// Navigation action
export interface NavigationAction {
  endpointId: string
  reason: string
}
