export interface OutcomeBreakdown {
  resolved: number
  escalated: number
  workaround: number
  unresolved: number
}

export interface AnalyticsSummary {
  total_sessions: number
  completed_sessions: number
  completion_rate: number
  median_duration_minutes: number
  active_engineers: number
  outcome_breakdown: OutcomeBreakdown
}

export interface TimeSeriesPoint {
  date: string
  sessions: number
  resolved: number
  escalated: number
  workaround: number
  unresolved: number
}

export interface TopFlow {
  tree_id: string
  name: string
  sessions: number
  completion_rate: number
  median_duration_minutes: number
  avg_csat?: number
}

export interface TopEngineer {
  user_id: string
  name: string
  sessions: number
  completion_rate: number
  median_duration_minutes: number
}

export interface TeamAnalyticsResponse {
  summary: AnalyticsSummary
  time_series: TimeSeriesPoint[]
  top_flows: TopFlow[]
  top_engineers: TopEngineer[]
}

export interface PersonalAnalyticsResponse {
  summary: AnalyticsSummary
  time_series: TimeSeriesPoint[]
  top_flows: TopFlow[]
}

export interface StepFeedbackSummary {
  node_id: string
  node_title: string
  helpful_yes: number
  helpful_no: number
  helpful_rate: number
  visit_count: number
  dropoff_count: number
  dropoff_rate: number
}

export interface FlowRatingItem {
  rating: number
  comment?: string
  created_at: string
}

export interface FlowAnalyticsResponse {
  summary: AnalyticsSummary
  avg_csat?: number
  total_ratings: number
  time_series: TimeSeriesPoint[]
  step_feedback: StepFeedbackSummary[]
  recent_comments: FlowRatingItem[]
}

export type AnalyticsPeriod = '7d' | '30d' | '90d'
