/**
 * Voice Agent Analytics Types
 */

export interface CallAnalytics {
  totalCalls: number;
  avgDurationSeconds: number;
  successRate: number; // 0-100
  appointmentsBooked: number;
  missedCalls: number;
  escalatedCalls: number;
  peakHours: PeakHoursData[];
  sentimentBreakdown: SentimentBreakdown;
  conversionFunnel: ConversionFunnel;
  dailyBreakdown: DailyCallBreakdown[];
}

export interface PeakHoursData {
  hour: number; // 0-23
  day: string; // monday, tuesday, etc.
  callCount: number;
}

export interface SentimentBreakdown {
  positive: number;
  neutral: number;
  negative: number;
}

export interface ConversionFunnel {
  totalCalls: number;
  answered: number;
  engaged: number; // conversation lasted > 30s
  intentIdentified: number;
  bookingAttempted: number;
  bookingCompleted: number;
}

export interface DailyCallBreakdown {
  date: string; // ISO date string
  totalCalls: number;
  avgDuration: number;
  appointmentsBooked: number;
  sentiment: SentimentBreakdown;
}

export interface ConversationDetail {
  id: string;
  callId: string;
  agentId: string;
  customerPhone?: string;
  customerName?: string;
  startTime: string;
  endTime?: string;
  durationSeconds: number;
  status: 'started' | 'ended' | 'failed';
  transcript: TranscriptEntry[];
  sentiment?: string;
  bookingCreated?: boolean;
  bookingId?: string;
  callOutcome?: string;
  escalated?: boolean;
  metadata?: Record<string, unknown>;
}

export interface TranscriptEntry {
  speaker: 'agent' | 'user';
  text: string;
  timestamp: string;
}

export interface AnalyticsExportOptions {
  startDate: string;
  endDate: string;
  format: 'csv' | 'json';
  includeTranscripts?: boolean;
}
