/**
 * Compliance, risk management, AI Act, obligations, DSFA, TOM, retention,
 * VVT, legal documents, cookie banner, consent, DSR, and escalation types.
 *
 * These are the core domain data structures referenced by SDKState.
 */

import type {
  RiskSeverity,
  RequirementStatus,
  ControlType,
  ImplementationStatus,
  EvidenceType,
  RiskLikelihood,
  RiskImpact,
  RiskStatus,
  MitigationType,
  AIActRiskCategory,
  DSFAStatus,
  CookieBannerStyle,
  CookieBannerPosition,
  CookieBannerTheme,
  CommandType,
} from './enums'

// =============================================================================
// COMPLIANCE
// =============================================================================

export interface ServiceModule {
  id: string
  name: string
  description: string
  regulations: string[]
  criticality: RiskSeverity
  processesPersonalData: boolean
  hasAIComponents: boolean
}

export interface Requirement {
  id: string
  regulation: string
  article: string
  title: string
  description: string
  criticality: RiskSeverity
  applicableModules: string[]
  status: RequirementStatus
  controls: string[]
}

export interface Control {
  id: string
  name: string
  description: string
  type: ControlType
  category: string
  implementationStatus: ImplementationStatus
  effectiveness: RiskSeverity
  evidence: string[]
  owner: string | null
  dueDate: Date | null
}

export interface Evidence {
  id: string
  controlId: string
  type: EvidenceType
  name: string
  description: string
  fileUrl: string | null
  validFrom: Date
  validUntil: Date | null
  uploadedBy: string
  uploadedAt: Date
}

export interface ChecklistItem {
  id: string
  requirementId: string
  title: string
  description: string
  status: 'PENDING' | 'PASSED' | 'FAILED' | 'NOT_APPLICABLE'
  notes: string
  verifiedBy: string | null
  verifiedAt: Date | null
}

// =============================================================================
// RISK MANAGEMENT
// =============================================================================

export interface RiskMitigation {
  id: string
  description: string
  type: MitigationType
  status: 'PLANNED' | 'IN_PROGRESS' | 'COMPLETED'
  effectiveness: number // 0-100
  controlId: string | null
}

export interface Risk {
  id: string
  title: string
  description: string
  category: string
  likelihood: RiskLikelihood
  impact: RiskImpact
  severity: RiskSeverity
  inherentRiskScore: number
  residualRiskScore: number
  status: RiskStatus
  mitigation: RiskMitigation[]
  owner: string | null
  relatedControls: string[]
  relatedRequirements: string[]
}

// =============================================================================
// AI ACT & OBLIGATIONS
// =============================================================================

export interface AIActObligation {
  id: string
  article: string
  title: string
  description: string
  deadline: Date | null
  status: 'PENDING' | 'IN_PROGRESS' | 'COMPLETED'
}

export interface AIActResult {
  riskCategory: AIActRiskCategory
  systemType: string
  obligations: AIActObligation[]
  assessmentDate: Date
  assessedBy: string
  justification: string
}

export interface Obligation {
  id: string
  regulation: string
  article: string
  title: string
  description: string
  deadline: Date | null
  penalty: string | null
  status: 'PENDING' | 'IN_PROGRESS' | 'COMPLETED'
  responsible: string | null
}

// =============================================================================
// DSFA
// =============================================================================

export interface DSFASection {
  id: string
  title: string
  content: string
  status: 'DRAFT' | 'COMPLETED'
  order: number
}

export interface DSFAApproval {
  id: string
  approver: string
  role: string
  status: 'PENDING' | 'APPROVED' | 'REJECTED'
  comment: string | null
  approvedAt: Date | null
}

export interface DSFA {
  id: string
  status: DSFAStatus
  version: number
  sections: DSFASection[]
  approvals: DSFAApproval[]
  createdAt: Date
  updatedAt: Date
}

// =============================================================================
// TOMs & RETENTION
// =============================================================================

export interface TOM {
  id: string
  category: string
  name: string
  description: string
  type: 'TECHNICAL' | 'ORGANIZATIONAL'
  implementationStatus: ImplementationStatus
  priority: RiskSeverity
  responsiblePerson: string | null
  implementationDate: Date | null
  reviewDate: Date | null
  evidence: string[]
}

export interface RetentionPolicy {
  id: string
  dataCategory: string
  description: string
  legalBasis: string
  retentionPeriod: string
  deletionMethod: string
  exceptions: string[]
}

// =============================================================================
// VVT (Processing Register)
// =============================================================================

export interface ProcessingActivity {
  id: string
  name: string
  purpose: string
  legalBasis: string
  dataCategories: string[]
  dataSubjects: string[]
  recipients: string[]
  thirdCountryTransfers: boolean
  retentionPeriod: string
  technicalMeasures: string[]
  organizationalMeasures: string[]
}

// =============================================================================
// LEGAL DOCUMENTS
// =============================================================================

export interface LegalDocument {
  id: string
  type: 'AGB' | 'PRIVACY_POLICY' | 'TERMS_OF_USE' | 'IMPRINT' | 'COOKIE_POLICY'
  title: string
  content: string
  version: string
  status: 'DRAFT' | 'PUBLISHED' | 'ARCHIVED'
  publishedAt: Date | null
  createdAt: Date
  updatedAt: Date
}

// =============================================================================
// COOKIE BANNER
// =============================================================================

export interface Cookie {
  id: string
  name: string
  provider: string
  purpose: string
  expiry: string
  type: 'NECESSARY' | 'FUNCTIONAL' | 'ANALYTICS' | 'MARKETING'
}

export interface CookieCategory {
  id: string
  name: string
  description: string
  required: boolean
  cookies: Cookie[]
}

export interface CookieBannerTexts {
  title: string
  description: string
  acceptAll: string
  rejectAll: string
  settings: string
  save: string
}

export interface CookieBannerGeneratedCode {
  html: string
  css: string
  js: string
}

export interface CookieBannerConfig {
  impressumUrl?: string
  id: string
  style: CookieBannerStyle
  position: CookieBannerPosition
  theme: CookieBannerTheme
  texts: CookieBannerTexts
  categories: CookieCategory[]
  generatedCode: CookieBannerGeneratedCode | null
}

// =============================================================================
// CONSENT & DSR
// =============================================================================

export interface ConsentRecord {
  id: string
  userId: string
  documentId: string
  documentVersion: string
  consentType: string
  granted: boolean
  grantedAt: Date
  revokedAt: Date | null
  ipAddress: string | null
  userAgent: string | null
}

export interface DSRRequest {
  id: string
  type: 'ACCESS' | 'RECTIFICATION' | 'ERASURE' | 'PORTABILITY' | 'RESTRICTION' | 'OBJECTION'
  status: 'RECEIVED' | 'VERIFIED' | 'PROCESSING' | 'COMPLETED' | 'REJECTED'
  requesterEmail: string
  requesterName: string
  requestedAt: Date
  dueDate: Date
  completedAt: Date | null
  notes: string
}

export interface DSRConfig {
  id: string
  enabled: boolean
  portalUrl: string
  emailTemplates: Record<string, string>
  automatedResponses: boolean
  verificationRequired: boolean
}

// =============================================================================
// ESCALATIONS
// =============================================================================

export interface EscalationWorkflow {
  id: string
  name: string
  description: string
  triggerConditions: string[]
  steps: EscalationStep[]
  enabled: boolean
}

export interface EscalationStep {
  id: string
  order: number
  action: string
  assignee: string
  timeLimit: string // ISO 8601 Duration
  escalateOnTimeout: boolean
}

// =============================================================================
// COMMAND BAR & USER PREFERENCES
// =============================================================================

export interface CommandSuggestion {
  id: string
  type: CommandType
  label: string
  description: string
  shortcut?: string
  icon?: string
  action: () => void | Promise<void>
  relevanceScore: number
}

export interface CommandHistory {
  id: string
  query: string
  type: CommandType
  timestamp: Date
  success: boolean
}

export interface UserPreferences {
  language: 'de' | 'en'
  theme: 'light' | 'dark' | 'system'
  compactMode: boolean
  showHints: boolean
  autoSave: boolean
  autoValidate: boolean
  allowParallelWork: boolean
}
