/**
 * DSFA Risikokatalog — Helpers & Assembled Catalog
 */

import type { DSFARiskCategory, SDMGoal } from '../types'
import type { CatalogRisk } from './types'
import { CONFIDENTIALITY_RISKS, INTEGRITY_RISKS } from './confidentiality-integrity'
import { AVAILABILITY_RISKS, RIGHTS_FREEDOMS_RISKS } from './availability-rights-auto-org'

export const RISK_CATALOG: CatalogRisk[] = [
  ...CONFIDENTIALITY_RISKS,
  ...INTEGRITY_RISKS,
  ...AVAILABILITY_RISKS,
  ...RIGHTS_FREEDOMS_RISKS,
]

export function getRisksByCategory(category: DSFARiskCategory): CatalogRisk[] {
  return RISK_CATALOG.filter(r => r.category === category)
}

export function getRisksBySDMGoal(goal: SDMGoal): CatalogRisk[] {
  return RISK_CATALOG.filter(r => r.sdmGoal === goal)
}

export function getRisksByWP248Criterion(criterionCode: string): CatalogRisk[] {
  return RISK_CATALOG.filter(r => r.wp248Criteria.includes(criterionCode))
}

export function getRisksByComponent(component: string): CatalogRisk[] {
  return RISK_CATALOG.filter(r => r.applicableTo.includes(component))
}

export function getCatalogRiskById(id: string): CatalogRisk | undefined {
  return RISK_CATALOG.find(r => r.id === id)
}

export const RISK_CATEGORY_LABELS: Record<DSFARiskCategory, string> = {
  confidentiality: 'Vertraulichkeit',
  integrity: 'Integritaet',
  availability: 'Verfuegbarkeit',
  rights_freedoms: 'Rechte & Freiheiten',
}

export const COMPONENT_FAMILY_LABELS: Record<string, string> = {
  identity: 'Identitaet & Zugang',
  cloud_storage: 'Cloud-Speicher',
  web_application: 'Web-Anwendung',
  api_service: 'API-Service',
  email_service: 'E-Mail-Dienst',
  mobile_app: 'Mobile App',
  database: 'Datenbank',
  crm: 'CRM-System',
  erp: 'ERP-System',
  analytics: 'Analyse/Tracking',
  marketing: 'Marketing',
  ai_ml: 'KI / Machine Learning',
  scoring: 'Scoring / Bewertung',
  hr_system: 'HR-System',
  health_system: 'Gesundheitssystem',
  monitoring: 'Ueberwachungssystem',
  support_system: 'Support-System',
  education: 'Bildungsplattform',
  research: 'Forschung',
}
