export interface Conversation {
  id: string
  conversation_id?: string
  visitor_id: string
  conversation_title?: string | null
  page_title: string | null
  page_url: string | null
  bot_name?: string | null
  source_label?: string | null
  status: ConversationStatus
  messages_count: number
  is_lead: boolean
  started_at: string
  last_message_at: string | null
  metadata: Record<string, unknown> | null
  // Added for conversation detail - session_data contains the messages
  session_data?: SessionMessage[] | { messages: SessionMessage[] } | null
  context_data?: Record<string, unknown> | null
  widgets_used?: string[] | null
  /** AI-generated conversation summary */
  ai_summary?: string | null
}

// Message format as stored in session_data
export interface SessionMessage {
  role: 'user' | 'bot' | 'assistant' | 'system'
  content: string
  timestamp?: string
}

export type ConversationStatus = 'active' | 'closed' | 'archived'

export interface Message {
  id: number
  conversation_id: string
  role: 'user' | 'bot' | 'system'
  content: string
  tokens_used: number | null
  widgets: Widget[] | null
  metadata: Record<string, unknown> | null
  created_at: string
}

export interface Widget {
  type: string
  data: Record<string, unknown>
}

export interface ConversationsResponse {
  success: boolean
  data: {
    conversations: Conversation[]
    pagination: {
      page: number
      per_page: number
      total: number
      total_pages: number
    }
  }
}

export interface ConversationMeeting {
  id: number
  meeting_date: string
  start_time: string
  end_time: string
  customer_name: string
  title: string
  status: string
  ai_summary?: string | null
}

export interface ConversationDetailResponse {
  success: boolean
  data: {
    conversation: Conversation
    messages?: Message[]
    lead?: {
      id: string
      name: string | null
      email: string | null
      phone: string | null
    } | null
    meetings?: ConversationMeeting[]
  }
}



