export type ApiLLMProviderType =
  | "openai"
  | "anthropic"
  | "mistral"
  | "azure_openai"
  | "azure_ai_anthropic"
  | "aws_bedrock"
  | "google_gemini"
  | "groq"
  | "deepseek"
  | "openrouter"
  | "together"
  | "fireworks"
  | "xai"
  | "ollama"
  | "ollama_cloud"
  | "custom"

export interface ApiLLMProvider {
  id: string
  name: string
  type?: ApiLLMProviderType
  base_url: string
  api_key?: string
  default_model: string
}

export interface ApiLLMSettings {
  default_provider_id: string
  providers: ApiLLMProvider[]
  contact_discovery_model?: string
  contact_discovery_provider_id?: string
}

export interface ApiLLMModelsResponse {
  models: string[]
}

export type ApiSearchProviderType =
  | "brave"
  | "bing"
  | "duckduckgo"
  | "searxng"
  | "custom"

export interface ApiSearchProvider {
  id: string
  name: string
  type: ApiSearchProviderType
  api_key?: string
  base_url?: string
  query_param?: string
  auth_header?: string
  results_path?: string
  title_field?: string
  url_field?: string
  description_field?: string
}

export interface ApiSearchSettings {
  default_provider_id: string
  providers: ApiSearchProvider[]
}

export interface ApiDiscoveredEmail {
  email: string
  display_name: string
  roles?: string[]
  message_count: number
}

export interface ApiDiscoveredSignature {
  id: string
  message_id?: string
  signature_text: string
  message_date: string
  confidence: number
}

export interface ApiEnrichedContactData {
  first_name?: string
  last_name?: string
  company?: string
  department?: string
  job_title?: string
  emails?: { value: string; label: string }[]
  phones?: { value: string; label: string }[]
  addresses?: {
    street?: string
    city?: string
    region?: string
    postal_code?: string
    country?: string
    label: string
  }[]
  website?: string
  social_profiles?: { value: string; label: string }[]
  notes?: string
}

export interface ApiDiscoveredProfile {
  id: string
  display_name: string
  primary_email: string
  all_emails: ApiDiscoveredEmail[]
  message_count: number
  sent_count: number
  received_count: number
  spam_count: number
  forwarded_count: number
  is_mailing_list: boolean
  is_disposable: boolean
  is_spam_heavy: boolean
  classification_reason?: string
  linked_contact_uid?: string
  enrichment_status: 'pending' | 'enriching' | 'enriched' | 'skipped' | 'failed'
  enriched_data?: ApiEnrichedContactData
  status: 'suggested' | 'accepted' | 'rejected' | 'ignored' | 'blocked'
  signatures?: ApiDiscoveredSignature[]
  detected_in_accounts?: ApiAccountDetection[]
  last_message_at?: string
}

export interface ApiEnrichmentSuggestion {
  id: string
  profile_id?: string
  target_contact_uid?: string
  suggestion_type: 'new_contact' | 'enrich_contact'
  field_path: string
  suggested_value: string
  suggested_label: string
  confidence: number
  status: 'pending' | 'accepted' | 'rejected'
  profile?: ApiDiscoveredProfile
}

export interface ApiAccountDetection {
  account_id: string
  account_email: string
  account_name: string
  message_count: number
}

export interface ApiDiscoveryScan {
  id: string
  status: 'pending' | 'running' | 'completed' | 'failed'
  phase: 'pending' | 'scanning_messages' | 'building_profiles' | 'enriching' | 'done'
  messages_scanned: number
  total_messages: number
  profiles_found: number
  profiles_total: number
  progress_percent: number
  error_message?: string
  started_at: string
  updated_at: string
  completed_at?: string
}

export interface ApiDiscoveryOtherPage {
  groups: ApiDiscoveredProfileGroup[]
  total: number
  limit: number
  offset: number
  has_more: boolean
}

export interface ApiDiscoveredProfileGroup {
  group_key: string
  profile_ids: string[]
  display_name: string
  primary_email: string
  message_count: number
  profile: ApiDiscoveredProfile
  profiles?: ApiDiscoveredProfile[]
}

export interface ApiDiscoveryCounts {
  other_contacts: number
  suggestions: number
  ignored: number
  blocked: number
}

export interface ApiDispositionEmails {
  emails: string[]
}
