export interface User {
  id: string;
  email: string;
  company_name: string;
  plan: 'free' | 'starter' | 'business' | 'agency' | 'enterprise';
  is_admin: boolean;
  chatbot_count?: number;
  conversations_used?: number;
}

export interface Subscription {
  plan: string;
  status: string;
  current_period_end?: string;
  chatbots_published: number;
  conversations_used: number;
}

export interface Chatbot {
  id: string;
  company_id: string;
  name: string;
  description: string;
  system_prompt: string;
  model: string;
  temperature: number;
  max_tokens: number;
  primary_color: string;
  welcome_message: string;
  logo_url?: string;
  category?: string;
  industry?: string;
  languages: string[];
  visibility: string;
  is_published: boolean;
  average_rating: number;
  show_branding: boolean;
  lead_capture_enabled: boolean;
  lead_capture_fields: string[];
  lead_capture_trigger: string;
  handoff_enabled: boolean;
  handoff_message: string;
  handoff_email: string;
  handoff_keywords: string[];
  booking_enabled?: boolean;
  document_count?: number;
  conversation_count?: number;
  created_at?: string;
}

export interface Document {
  id: string;
  chatbot_id: string;
  file_name: string;
  file_type: string;
  file_size: number;
  chunk_count: number;
  status: 'pending' | 'processing' | 'completed' | 'failed';
  error_message?: string;
  created_at?: string;
}

export interface URLSource {
  id: string;
  chatbot_id: string;
  url: string;
  status: 'pending' | 'processing' | 'completed' | 'failed';
  page_title?: string;
  chunk_count?: number;
  error_message?: string;
}

export interface Message {
  id: string;
  conversation_id: string;
  role: 'user' | 'assistant';
  content: string;
  sources?: MessageSource[];
  model?: string;
  confidence_score?: number;
  is_handoff?: boolean;
  created_at?: string;
}

export interface MessageSource {
  document_name: string;
  chunk_text: string;
  score: number;
  page_number?: number;
}

export interface Conversation {
  id: string;
  chatbot_id: string;
  session_id: string;
  language?: string;
  message_count: number;
  created_at?: string;
  last_message?: string;
  chatbot_name?: string;
}

export interface Lead {
  id: string;
  chatbot_id: string;
  conversation_id?: string;
  email?: string;
  name?: string;
  phone?: string;
  company?: string;
  created_at?: string;
  chatbot_name?: string;
}

export interface MarketplaceChatbot {
  id: string;
  name: string;
  description: string;
  category?: string;
  industry?: string;
  languages: string[];
  average_rating: number;
  logo_url?: string;
  primary_color: string;
  conversation_count?: number;
  company_name?: string;
}

export interface AnalyticsOverview {
  total_conversations: number;
  total_messages: number;
  total_chatbots: number;
  published_chatbots: number;
  unique_sessions: number;
  conversations_this_month: number;
  avg_messages_per_conversation: number;
  average_rating: number | null;
  plan: string;
  conversations_limit: number;
  conversations_used: number;
  chatbots: ChatbotAnalytics[];
}

export interface DailyConversation {
  date: string;
  count: number;
}

export interface TopQuery {
  query: string;
  count: number;
}

export interface ChatbotAnalytics {
  chatbot_id: string;
  chatbot_name: string;
  conversations: number;
  messages: number;
  avg_confidence: number;
  total_conversations: number;
  unique_sessions: number;
  total_messages: number;
  average_rating: number | null;
  total_ratings: number;
  conversations_today: number;
  conversations_this_week: number;
  conversations_this_month: number;
  daily_conversations: DailyConversation[];
  top_queries: TopQuery[];
  languages_used: Record<string, number>;
  peak_hour: number | null;
  unanswered_count: number;
  unanswered_queries: TopQuery[];
  feedback_positive: number;
  feedback_negative: number;
}

export interface Campaign {
  id: string;
  chatbot_id: string;
  title: string;
  message: string;
  status: 'draft' | 'sending' | 'sent' | 'failed';
  recipients_count: number;
  sent_count: number;
  created_at?: string;
  sent_at?: string;
}

export interface Appointment {
  id: string;
  chatbot_id: string;
  customer_name: string;
  customer_contact: string;
  service?: string;
  notes?: string;
  slot_start: string;
  slot_end: string;
  status: 'pending' | 'confirmed' | 'cancelled' | 'completed';
  created_at?: string;
}

export interface BusinessHoursEntry {
  day_of_week: number;
  is_open: boolean;
  open_time: string;
  close_time: string;
  slot_duration_minutes: number;
}

export interface ChannelConnection {
  id: string;
  chatbot_id: string;
  channel: 'telegram' | 'whatsapp';
  bot_username?: string;
  wa_keyword?: string;
  is_active: boolean;
}

export interface AIModel {
  id: string;
  name: string;
  provider: string;
  available: boolean;
  upgrade_required?: string;
}

export interface PaginatedResponse<T> {
  items: T[];
  total: number;
  page: number;
  limit: number;
}
