/**
 * RAG & Legal Corpus Management - Type Definitions
 */

export interface RegulationStatus {
  code: string
  name: string
  fullName: string
  type: string
  chunkCount: number
  expectedRequirements: number
  sourceUrl: string
  status: 'ready' | 'empty' | 'error'
}

export interface CollectionStatus {
  collection: string
  totalPoints: number
  vectorSize: number
  status: string
  regulations: Record<string, number>
}

export interface SearchResult {
  text: string
  regulation_code: string
  regulation_name: string
  article: string | null
  paragraph: string | null
  source_url: string
  score: number
}

export interface DsfaSource {
  source_code: string
  name: string
  full_name?: string
  organization?: string
  source_url?: string
  license_code: string
  attribution_text: string
  document_type: string
  language: string
  chunk_count?: number
}

export interface DsfaCorpusStatus {
  qdrant_collection: string
  total_sources: number
  total_documents: number
  total_chunks: number
  qdrant_points_count: number
  qdrant_status: string
}

export type RegulationCategory = 'regulations' | 'dsfa' | 'nibis' | 'templates'

export type TabId = 'overview' | 'regulations' | 'map' | 'search' | 'chunks' | 'data' | 'ingestion' | 'pipeline'

export interface CustomDocument {
  id: string
  code: string
  title: string
  filename?: string
  url?: string
  document_type: string
  uploaded_at: string
  status: 'uploaded' | 'queued' | 'fetching' | 'processing' | 'indexed' | 'error'
  chunk_count: number
  error?: string
}

export interface Validation {
  name: string
  status: 'passed' | 'warning' | 'failed' | 'not_run'
  expected: any
  actual: any
  message: string
}

export interface PipelineCheckpoint {
  phase: string
  name: string
  status: 'pending' | 'running' | 'completed' | 'failed' | 'skipped'
  started_at: string | null
  completed_at: string | null
  duration_seconds: number | null
  metrics: Record<string, any>
  validations: Validation[]
  error: string | null
}

export interface PipelineState {
  status: string
  pipeline_id: string | null
  started_at: string | null
  completed_at: string | null
  current_phase: string | null
  checkpoints: PipelineCheckpoint[]
  summary: Record<string, any>
  validation_summary?: {
    passed: number
    warning: number
    failed: number
    total: number
  }
}

export interface Regulation {
  code: string
  name: string
  fullName: string
  type: string
  expected: number
  description: string
  relevantFor: string[]
  keyTopics: string[]
  effectiveDate: string
}

export interface Industry {
  id: string
  name: string
  icon: string
  description: string
}

export interface ThematicGroup {
  id: string
  name: string
  color: string
  regulations: string[]
  description: string
}

export interface KeyIntersection {
  regulations: string[]
  topic: string
  description: string
}

export interface FutureOutlookItem {
  id: string
  name: string
  status: string
  statusLabel: string
  expectedDate: string
  description: string
  keyChanges: string[]
  affectedRegulations: string[]
  source: string
}

export interface AdditionalRegulation {
  code: string
  name: string
  fullName: string
  type: string
  status: string
  effectiveDate: string
  description: string
  relevantFor: string[]
  celex: string
  priority: string
}

export interface LegalBasisDetail {
  aspect: string
  status: string
  explanation: string
}

export interface LegalBasisInfo {
  title: string
  summary: string
  details: LegalBasisDetail[]
}

export interface TabDef {
  id: TabId
  name: string
  icon: string
}
