export interface SeedURL {
  id: string
  url: string
  category: string
  category_id?: string
  name: string
  description: string
  trustBoost: number
  enabled: boolean
  lastCrawled?: string
  documentCount?: number
  source_type?: string
  scope?: string
  state?: string
  crawl_depth?: number
  crawl_frequency?: string
}

export interface CrawlStats {
  totalDocuments: number
  totalSeeds: number
  lastCrawlTime?: string
  crawlStatus: 'idle' | 'running' | 'error'
  documentsPerCategory: Record<string, number>
  documentsPerDocType: Record<string, number>
  avgTrustScore: number
}

export interface Category {
  id: string
  name: string
  display_name?: string
  description: string
  icon: string
  sort_order?: number
  is_active?: boolean
}

export interface ApiSeed {
  id: string
  url: string
  name: string
  description: string | null
  category: string | null
  category_display_name: string | null
  source_type: string
  scope: string
  state: string | null
  trust_boost: number
  enabled: boolean
  crawl_depth: number
  crawl_frequency: string
  last_crawled_at: string | null
  last_crawl_status: string | null
  last_crawl_docs: number
  total_documents: number
  created_at: string
  updated_at: string
}

// Default categories (fallback if API fails)
export const DEFAULT_CATEGORIES: Category[] = [
  { id: 'federal', name: 'federal', display_name: 'Bundesebene', description: 'KMK, BMBF, Bildungsserver', icon: '🏛️' },
  { id: 'states', name: 'states', display_name: 'Bundesländer', description: 'Ministerien, Landesbildungsserver', icon: '🗺️' },
  { id: 'science', name: 'science', display_name: 'Wissenschaft', description: 'Bertelsmann, PISA, IGLU, TIMSS', icon: '🔬' },
  { id: 'universities', name: 'universities', display_name: 'Hochschulen', description: 'Universitäten, Fachhochschulen, Pädagogische Hochschulen', icon: '🎓' },
  { id: 'legal', name: 'legal', display_name: 'Recht & Schulgesetze', description: 'Schulgesetze, Erlasse, Verordnungen, Datenschutzrecht', icon: '⚖️' },
  { id: 'portals', name: 'portals', display_name: 'Bildungsportale', description: 'Lehrer-Online, 4teachers, ZUM', icon: '📚' },
  { id: 'authorities', name: 'authorities', display_name: 'Schulbehörden', description: 'Regierungspräsidien, Schulämter', icon: '📋' },
]

// Default empty stats (loaded from API)
export const DEFAULT_STATS: CrawlStats = {
  totalDocuments: 0,
  totalSeeds: 0,
  lastCrawlTime: undefined,
  crawlStatus: 'idle',
  documentsPerCategory: {},
  documentsPerDocType: {},
  avgTrustScore: 0,
}

// Convert API seed to frontend format
export function apiSeedToFrontend(seed: ApiSeed): SeedURL {
  return {
    id: seed.id,
    url: seed.url,
    name: seed.name,
    description: seed.description || '',
    category: seed.category || 'federal',
    category_id: undefined,
    trustBoost: seed.trust_boost,
    enabled: seed.enabled,
    lastCrawled: seed.last_crawled_at || undefined,
    documentCount: seed.total_documents,
    source_type: seed.source_type,
    scope: seed.scope,
    state: seed.state || undefined,
    crawl_depth: seed.crawl_depth,
    crawl_frequency: seed.crawl_frequency,
  }
}
