/**
 * Finding Types
 *
 * Types for compliance findings from contract reviews:
 * - Finding classification (type, category, severity)
 * - Citation references to source documents
 * - Finding workflow (status, resolution)
 */

import type { LocalizedText } from './types-common'

// ==========================================
// ENUMS - FINDINGS
// ==========================================

export type FindingType =
  | 'OK'                  // Anforderung erfuellt
  | 'GAP'                 // Luecke/fehlend
  | 'RISK'                // Risiko identifiziert
  | 'UNKNOWN'             // Nicht eindeutig

export type FindingCategory =
  | 'AVV_CONTENT'         // Art. 28 Abs. 3 Mindestinhalte
  | 'SUBPROCESSOR'        // Unterauftragnehmer-Regelung
  | 'INCIDENT'            // Incident-Meldepflichten
  | 'AUDIT_RIGHTS'        // Audit-/Inspektionsrechte
  | 'DELETION'            // Loeschung/Rueckgabe
  | 'TOM'                 // Technische/Org. Massnahmen
  | 'TRANSFER'            // Drittlandtransfer
  | 'LIABILITY'           // Haftung/Indemnity
  | 'SLA'                 // Verfuegbarkeit
  | 'DATA_SUBJECT_RIGHTS' // Betroffenenrechte
  | 'CONFIDENTIALITY'     // Vertraulichkeit
  | 'INSTRUCTION'         // Weisungsgebundenheit
  | 'TERMINATION'         // Vertragsbeendigung
  | 'GENERAL'             // Allgemein

export type FindingSeverity = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'

export type FindingStatus =
  | 'OPEN'
  | 'IN_PROGRESS'
  | 'RESOLVED'
  | 'ACCEPTED'
  | 'FALSE_POSITIVE'

// ==========================================
// INTERFACES - FINDINGS
// ==========================================

export interface Citation {
  documentId: string
  versionId?: string
  page: number
  startChar: number
  endChar: number
  quotedText: string
  quoteHash: string // SHA-256 zur Verifizierung
}

export interface Finding {
  id: string
  tenantId: string
  contractId: string
  vendorId: string

  // Klassifikation
  type: FindingType
  category: FindingCategory
  severity: FindingSeverity

  // Inhalt
  title: LocalizedText
  description: LocalizedText
  recommendation?: LocalizedText

  // Citations (Textstellen-Belege)
  citations: Citation[]

  // Verknuepfung
  affectedRequirement?: string // z.B. "Art. 28 Abs. 3 lit. a DSGVO"
  triggeredControls: string[] // Control-IDs

  // Workflow
  status: FindingStatus
  assignee?: string
  dueDate?: Date
  resolution?: string
  resolvedAt?: Date

  createdAt: Date
  updatedAt: Date
}
