import type { TraceEvent } from '../../../types/trace'

export interface JavaScriptEvent {
  eventId: string
  name: string // EvaluateScript, v8.compile, v8.callFunction, etc.
  category: string
  url?: string
  fileName?: string
  lineNumber?: number
  columnNumber?: number
  isInlineScript: boolean
  scriptId?: string
  sampleTraceId?: string
  
  // Timing information
  timing: {
    startTime: number // ts in microseconds
    duration: number // dur in microseconds  
    threadDuration?: number // tdur in microseconds
    durationMs: number // duration in milliseconds for display
  }
  
  // V8 specific data
  v8Data?: {
    streamed?: boolean
    notStreamedReason?: string
    isolate?: string
    executionContextId?: number
  }
  
  // Raw trace event for debugging
  rawEvent: TraceEvent
}

export interface JavaScriptSummary {
  totalEvents: number
  totalExecutionTime: number // in microseconds
  totalCompilationTime: number // in microseconds
  totalEvaluationTime: number // in microseconds
  
  eventsByType: {
    compilation: number
    evaluation: number
    execution: number
    other: number
  }
  
  scriptsByUrl: Map<string, {
    url: string
    events: JavaScriptEvent[]
    totalTime: number
    isThirdParty: boolean
  }>
}