// =============================================================================
// SUB-TYPES & SECTION PROGRESS
// =============================================================================

import type { DSFARiskCategory, DSFAMitigationType, DSFAMitigationStatus } from './enums-constants'

export interface DSFARisk {
  id: string
  category: DSFARiskCategory
  description: string
  likelihood: 'low' | 'medium' | 'high'
  impact: 'low' | 'medium' | 'high'
  risk_level: string
  affected_data: string[]
}

export interface DSFAMitigation {
  id: string
  risk_id: string
  description: string
  type: DSFAMitigationType
  status: DSFAMitigationStatus
  implemented_at?: string
  verified_at?: string
  residual_risk: 'low' | 'medium' | 'high'
  tom_reference?: string
  responsible_party: string
}

export interface DSFAReviewComment {
  id: string
  section: number
  comment: string
  created_by: string
  created_at: string
  resolved: boolean
}

export interface DSFASectionProgress {
  section_0_complete: boolean  // Schwellwertanalyse
  section_1_complete: boolean  // Systematische Beschreibung
  section_2_complete: boolean  // Notwendigkeit & Verhältnismäßigkeit
  section_3_complete: boolean  // Risikobewertung
  section_4_complete: boolean  // Abhilfemaßnahmen
  section_5_complete: boolean  // Betroffenenperspektive (optional)
  section_6_complete: boolean  // DSB & Behördenkonsultation
  section_7_complete: boolean  // Fortschreibung & Review
  section_8_complete?: boolean  // KI-Anwendungsfälle (optional)
}

// =============================================================================
// SCHWELLWERTANALYSE / VORABPRÜFUNG (Art. 35 Abs. 1 DSGVO)
// =============================================================================

export interface DSFAThresholdAnalysis {
  id: string
  dsfa_id?: string
  performed_at: string
  performed_by: string

  // WP248 Kriterien-Bewertung
  criteria_assessment: Array<{
    criterion_id: string  // K1-K9
    applies: boolean
    justification: string
  }>

  // Art. 35 Abs. 3 Prüfung
  art35_abs3_assessment: Array<{
    case_id: string  // a, b, c
    applies: boolean
    justification: string
  }>

  // Ergebnis
  dsfa_required: boolean
  decision_justification: string

  // Dokumentation der Entscheidung (gem. DSK Kurzpapier Nr. 5)
  documented: boolean
  documentation_reference?: string
}

// =============================================================================
// BETROFFENENPERSPEKTIVE (Art. 35 Abs. 9 DSGVO)
// =============================================================================

export interface DSFAStakeholderConsultation {
  id: string
  stakeholder_type: 'data_subjects' | 'representatives' | 'works_council' | 'other'
  stakeholder_description: string
  consultation_date?: string
  consultation_method: 'survey' | 'interview' | 'workshop' | 'written' | 'other'
  summary: string
  concerns_raised: string[]
  addressed_in_dsfa: boolean
  response_documentation?: string
}

// =============================================================================
// ART. 36 KONSULTATIONSPFLICHT
// =============================================================================

export interface DSFAConsultationRequirement {
  high_residual_risk: boolean
  consultation_required: boolean  // Art. 36 Abs. 1 DSGVO
  consultation_reason?: string
  authority_notified: boolean
  notification_date?: string
  authority_response?: string
  authority_recommendations?: string[]
  waiting_period_observed: boolean  // 8 Wochen gem. Art. 36 Abs. 2
}

// =============================================================================
// FORTSCHREIBUNG / REVIEW (Art. 35 Abs. 11 DSGVO)
// =============================================================================

export interface DSFAReviewTrigger {
  id: string
  trigger_type: 'scheduled' | 'risk_change' | 'new_technology' | 'new_purpose' | 'incident' | 'regulatory' | 'other'
  description: string
  detected_at: string
  detected_by: string
  review_required: boolean
  review_completed: boolean
  review_date?: string
  changes_made: string[]
}

export interface DSFAReviewSchedule {
  next_review_date: string
  review_frequency_months: number
  last_review_date?: string
  review_responsible: string
}
