/**
 * Core type definitions for the multi-agent chat application
 */

import type { LanguageModel } from 'ai'
import type { Tool } from 'ai'

/**
 * Agent definition for Vercel AI SDK (internal - server-side)
 * Defines an agent with system prompt, tools, and LLM parameters
 */
export interface AgentDefinition {
  id: string
  name: string
  description: string
  systemPrompt: string
  tools?: Record<string, Tool<any, any>>
  temperature?: number
  maxTokens?: number
}

/**
 * Represents an AI agent that users can chat with (client-side)
 */
export interface Agent {
  id: string
  name: string
  description: string
  webhookUrl?: string  // Optional: not needed for custom agents (routed dynamically)
  isCustom?: boolean   // Flag to distinguish custom agents
}

/**
 * Represents a single message in the chat
 * Images are stored as base64 strings for transmission to the webhook
 */
export interface Message {
  id: string
  role: "user" | "assistant"
  content: string
  timestamp: Date
  isError?: boolean
  hint?: string
  images?: string[] // Base64 encoded images (user messages only)
}

/**
 * API request body for POST /api/chat
 */
export interface ChatRequest {
  message: string
  timestamp: string
  sessionId: string
  agentId: string
  images?: string[] // Optional base64 encoded images
}

/**
 * API response from POST /api/chat
 */
export interface ChatResponse {
  error?: string
  hint?: string
  response?: string
  message?: string
  toolCall?: ToolCall // Tool call from agent (e.g., create_agent_package)
}

/**
 * API response from GET /api/agents
 */
export interface AgentsResponse {
  agents: Agent[]
  error?: string
}

/**
 * Props for diff-related components
 */
export interface DiffToolProps {
  oldCode: string
  newCode: string
  title?: string
  language?: string
}

export interface DiffDisplayProps {
  oldText: string
  newText: string
  title?: string
  language?: string
}

export interface DiffLine {
  type: "added" | "removed" | "unchanged"
  content: string
  oldLineNumber?: number
  newLineNumber?: number
}

/**
 * Props for markdown renderer
 */
export interface MarkdownRendererProps {
  content: string
  className?: string
}

/**
 * Tool call from agent (e.g., Morgan creating agent packages)
 */
export interface ToolCall {
  type: "tool_call"
  name: string
  payload: AgentPackagePayload | Record<string, unknown>
}

/**
 * Agent package payload from Morgan's create_agent_package tool call
 */
export interface AgentPackagePayload {
  agentId: string
  displayName: string
  summary: string
  tags: string[]
  systemPrompt: string
  hints?: {
    recommendedIcon?: string
    whenToUse?: string
  }
}

/**
 * Pinned agent stored in localStorage
 */
export interface PinnedAgent {
  agentId: string
  displayName: string
  summary: string
  tags: string[]
  recommendedIcon?: string
  whenToUse?: string
  systemPrompt: string // Encrypted/encoded
  pinnedAt: string // ISO timestamp
  note?: string // User-provided note
}

/**
 * Custom agent for runtime use (extends Agent)
 */
export interface CustomAgent extends Agent {
  isCustom: true
  systemPrompt: string
  tags: string[]
}
