export interface MTTRDataPoint {
  date: string
  mttr_minutes: number
  session_count: number
}

export interface DomainBreakdown {
  domain: string
  total: number
  resolved: number
  escalated: number
  resolution_rate: number
}

export interface ConfidenceBreakdown {
  guided_sessions: number
  guided_resolution_rate: number
  exploring_sessions: number
  exploring_resolution_rate: number
  discovery_sessions: number
  discovery_resolution_rate: number
}

export interface DomainCoverage {
  domain: string
  flow_count: number
  session_count: number
  guided_rate: number
}

export interface KnowledgeCoverage {
  total_flows: number
  ai_generated_flows: number
  total_proposals_pending: number
  proposals_approved_this_period: number
  proposals_rejected_this_period: number
  coverage_by_domain: DomainCoverage[]
}

export interface PsaMetrics {
  ticket_link_rate: number
  auto_push_success_rate: number
  auto_push_retry_success_rate: number
  total_time_entries_logged: number
  total_hours_logged: number
}

export interface FlowPilotDashboard {
  period: string
  total_sessions: number
  resolved_sessions: number
  escalated_sessions: number
  abandoned_sessions: number
  resolution_rate: number
  avg_steps_to_resolution: number
  avg_session_duration_minutes: number
  avg_rating: number | null
  mttr_minutes: number | null
  mttr_trend: MTTRDataPoint[]
  sessions_by_domain: DomainBreakdown[]
  confidence_breakdown: ConfidenceBreakdown
  knowledge_coverage: KnowledgeCoverage
  psa_metrics: PsaMetrics | null
}

export interface KnowledgeGap {
  gap_type: string
  domain: string | null
  severity: 'high' | 'medium' | 'low'
  title: string
  description: string
  evidence: Record<string, unknown>
  suggested_action: string
}

export interface KnowledgeGapReport {
  generated_at: string
  gaps: KnowledgeGap[]
}

// Phase 5 — Coverage
export interface CoverageDomainRow {
  domain: string
  flow_count: number
  session_count: number
  resolution_rate: number
  escalation_rate: number
  guided_rate: number
  avg_resolution_minutes: number | null
}

export interface CoverageResponse {
  domains: CoverageDomainRow[]
  unmapped_session_count: number
  total_domains: number
}

// Phase 5 — Flow Quality
export interface FlowQualityRow {
  flow_id: string
  name: string
  tree_type: string
  usage_count: number
  success_rate: number | null
  last_matched_at: string | null
  avg_confidence: number | null
  quality_score: number
}

export interface FlowQualityResponse {
  flows: FlowQualityRow[]
  top_performers: FlowQualityRow[]
  needs_attention: FlowQualityRow[]
}

// Phase 5 — Enhanced PSA
export interface PsaFunnel {
  total_sessions: number
  linked_to_ticket: number
  doc_pushed: number
  time_entry_logged: number
}

export interface PsaDailyTrend {
  date: string
  entries: number
  hours: number
}

export interface EnhancedPsaMetrics {
  total_time_entries: number
  total_hours_logged: number
  avg_hours_per_session: number
  push_funnel: PsaFunnel
  daily_trend: PsaDailyTrend[]
}
