/**
 * Agent timeline and observability types
 * Used for UI timeline visualization and backend processing
 */

import type { AgentIterationEvent, AgentToolCallEvent } from './logging'

/**
 * Sub-activity within an iteration
 * Represents reasoning, actions, or tool calls with timing
 */
export interface SubActivity {
  type: 'reasoning' | 'action' | 'tool-call'
  startTime: number
  endTime: number
  duration: number
  details: AgentIterationEvent | AgentToolCallEvent
}

/**
 * Agent iteration state
 * Aggregates lifecycle events and sub-activities for a single iteration
 */
export interface AgentIteration {
  iterationNumber: number
  status: 'running' | 'completed' | 'failed' | 'pending'
  iterationEvents: AgentIterationEvent[]
  duration?: number
  timestamp: number
  subActivities: SubActivity[]

  // Timeline visualization timing (Phase 2 - optional for backward compatibility)
  startTime?: number   // From lifecycle 'started' event
  endTime?: number     // From lifecycle 'completed'/'failed' event
}

/**
 * Agent lifecycle node state
 * Represents initialization or completion phase
 */
export interface AgentLifecycleNode {
  type: 'initialization' | 'completion'
  status: 'running' | 'completed' | 'failed' | 'pending'
  duration?: number
  timestamp?: number

  // Timeline visualization timing (Phase 2 - optional for backward compatibility)
  startTime?: number   // From lifecycle 'started' event
  endTime?: number     // From lifecycle 'completed'/'failed' event
}

/**
 * Complete agent execution data for timeline visualization
 * Parsed from execution logs
 */
export interface AgentIterationData {
  initialization: AgentLifecycleNode
  iterations: AgentIteration[]
  completion: AgentLifecycleNode
  currentIteration: number | null
  totalIterations: number
  totalDuration?: number
  status: 'running' | 'completed' | 'failed' | 'warning'
}
