/**
 * DSFA Massnahmenbibliothek — Helpers & Assembled Library
 */

import type { DSFAMitigationType, SDMGoal } from '../types'
import type { CatalogMitigation } from './types'
import { ACCESS_CONTROL_MITIGATIONS, INTEGRITY_MITIGATIONS } from './access-integrity'
import { AVAILABILITY_MITIGATIONS, MINIMIZATION_NONLINKAGE_MITIGATIONS } from './availability-minimization'
import { TRANSPARENCY_MITIGATIONS, INTERVENTION_MITIGATIONS, AUTOMATION_ORG_LEGAL_MITIGATIONS } from './transparency-intervention-org'

export const MITIGATION_LIBRARY: CatalogMitigation[] = [
  ...ACCESS_CONTROL_MITIGATIONS,
  ...INTEGRITY_MITIGATIONS,
  ...AVAILABILITY_MITIGATIONS,
  ...MINIMIZATION_NONLINKAGE_MITIGATIONS,
  ...TRANSPARENCY_MITIGATIONS,
  ...INTERVENTION_MITIGATIONS,
  ...AUTOMATION_ORG_LEGAL_MITIGATIONS,
]

export function getMitigationsBySDMGoal(goal: SDMGoal): CatalogMitigation[] {
  return MITIGATION_LIBRARY.filter(m => m.sdmGoals.includes(goal))
}

export function getMitigationsByType(type: DSFAMitigationType): CatalogMitigation[] {
  return MITIGATION_LIBRARY.filter(m => m.type === type)
}

export function getMitigationsForRisk(riskId: string): CatalogMitigation[] {
  return MITIGATION_LIBRARY.filter(m => m.addressesRiskIds.includes(riskId))
}

export function getCatalogMitigationById(id: string): CatalogMitigation | undefined {
  return MITIGATION_LIBRARY.find(m => m.id === id)
}

export function getMitigationsByEffectiveness(effectiveness: 'low' | 'medium' | 'high'): CatalogMitigation[] {
  return MITIGATION_LIBRARY.filter(m => m.effectiveness === effectiveness)
}

export const MITIGATION_TYPE_LABELS: Record<DSFAMitigationType, string> = {
  technical: 'Technisch',
  organizational: 'Organisatorisch',
  legal: 'Rechtlich',
}

export const SDM_GOAL_LABELS: Record<SDMGoal, string> = {
  datenminimierung: 'Datenminimierung',
  verfuegbarkeit: 'Verfuegbarkeit',
  integritaet: 'Integritaet',
  vertraulichkeit: 'Vertraulichkeit',
  nichtverkettung: 'Nichtverkettung',
  transparenz: 'Transparenz',
  intervenierbarkeit: 'Intervenierbarkeit',
}

export const EFFECTIVENESS_LABELS: Record<string, string> = {
  low: 'Gering',
  medium: 'Mittel',
  high: 'Hoch',
}
