/**
 * Catalog Registry — Vendor, VVT & Loeschfristen Catalogs
 */

import type { CatalogId, CatalogMeta } from '../types'
import { VVT_BASELINE_CATALOG } from '../../vvt-baseline-catalog'
import { BASELINE_TEMPLATES } from '../../loeschfristen-baseline-catalog'
import { VENDOR_TEMPLATES, COUNTRY_RISK_PROFILES } from '../../vendor-compliance/catalog/vendor-templates'

export const VENDOR_VVT_CATALOG_META: Partial<Record<CatalogId, CatalogMeta>> = {
  'vvt-templates': {
    id: 'vvt-templates',
    name: 'VVT Baseline-Vorlagen',
    description: 'Vorlagen fuer Verarbeitungstaetigkeiten',
    module: 'vvt',
    icon: 'FileText',
    systemCount: VVT_BASELINE_CATALOG.length,
    allowCustom: true,
    idField: 'templateId',
    nameField: 'name',
    descriptionField: 'description',
    categoryField: 'businessFunction',
    fields: [
      { key: 'templateId', label: 'Vorlagen-ID', type: 'text', required: true },
      { key: 'name', label: 'Name', type: 'text', required: true },
      { key: 'description', label: 'Beschreibung', type: 'textarea', required: true },
      { key: 'businessFunction', label: 'Geschaeftsbereich', type: 'select', required: true, options: [
        { value: 'hr', label: 'Personal' },
        { value: 'finance', label: 'Finanzen' },
        { value: 'sales', label: 'Vertrieb' },
        { value: 'marketing', label: 'Marketing' },
        { value: 'support', label: 'Support' },
        { value: 'it', label: 'IT' },
        { value: 'other', label: 'Sonstige' },
      ]},
      { key: 'protectionLevel', label: 'Schutzniveau', type: 'select', required: false, options: [
        { value: 'LOW', label: 'Niedrig' },
        { value: 'MEDIUM', label: 'Mittel' },
        { value: 'HIGH', label: 'Hoch' },
      ]},
    ],
    searchableFields: ['templateId', 'name', 'description', 'businessFunction'],
  },

  'loeschfristen-templates': {
    id: 'loeschfristen-templates',
    name: 'Loeschfristen-Vorlagen',
    description: 'Baseline-Vorlagen fuer Aufbewahrungsfristen',
    module: 'vvt',
    icon: 'Clock',
    systemCount: BASELINE_TEMPLATES.length,
    allowCustom: true,
    idField: 'templateId',
    nameField: 'dataObjectName',
    descriptionField: 'description',
    categoryField: 'retentionDriver',
    fields: [
      { key: 'templateId', label: 'Vorlagen-ID', type: 'text', required: true },
      { key: 'dataObjectName', label: 'Datenobjekt', type: 'text', required: true },
      { key: 'description', label: 'Beschreibung', type: 'textarea', required: true },
      { key: 'retentionDuration', label: 'Aufbewahrungsdauer', type: 'number', required: true, min: 0 },
      { key: 'retentionUnit', label: 'Einheit', type: 'select', required: true, options: [
        { value: 'days', label: 'Tage' },
        { value: 'months', label: 'Monate' },
        { value: 'years', label: 'Jahre' },
      ]},
      { key: 'deletionMethod', label: 'Loeschmethode', type: 'text', required: false },
      { key: 'responsibleRole', label: 'Verantwortlich', type: 'text', required: false },
    ],
    searchableFields: ['templateId', 'dataObjectName', 'description', 'retentionDriver'],
  },

  'vendor-templates': {
    id: 'vendor-templates',
    name: 'AV-Vorlagen',
    description: 'Vorlagen fuer Auftragsverarbeitungsvertraege',
    module: 'vendor',
    icon: 'Building2',
    systemCount: VENDOR_TEMPLATES.length,
    allowCustom: true,
    idField: 'id',
    nameField: 'name',
    descriptionField: 'description',
    categoryField: 'serviceCategory',
    fields: [
      { key: 'id', label: 'ID', type: 'text', required: true },
      { key: 'name', label: 'Name', type: 'text', required: true },
      { key: 'description', label: 'Beschreibung', type: 'textarea', required: true },
      { key: 'serviceCategory', label: 'Dienstleistungskategorie', type: 'select', required: true, options: [
        { value: 'HOSTING', label: 'Hosting' },
        { value: 'CLOUD_INFRASTRUCTURE', label: 'Cloud-Infrastruktur' },
        { value: 'ANALYTICS', label: 'Analyse' },
        { value: 'CRM', label: 'CRM' },
        { value: 'ERP', label: 'ERP' },
        { value: 'HR_SOFTWARE', label: 'HR-Software' },
        { value: 'PAYMENT', label: 'Zahlungsdienstleister' },
        { value: 'EMAIL', label: 'E-Mail' },
        { value: 'MARKETING', label: 'Marketing' },
        { value: 'SUPPORT', label: 'Support' },
        { value: 'SECURITY', label: 'Sicherheit' },
        { value: 'COMMUNICATION', label: 'Kommunikation' },
        { value: 'STORAGE', label: 'Speicher' },
        { value: 'BACKUP', label: 'Backup' },
        { value: 'CDN', label: 'CDN' },
        { value: 'ACCOUNTING', label: 'Buchhaltung' },
        { value: 'CONSULTING', label: 'Beratung' },
        { value: 'OTHER', label: 'Sonstige' },
      ]},
      { key: 'suggestedRole', label: 'Vorgeschlagene Rolle', type: 'select', required: false, options: [
        { value: 'PROCESSOR', label: 'Auftragsverarbeiter' },
        { value: 'JOINT_CONTROLLER', label: 'Gemeinsam Verantwortlicher' },
        { value: 'CONTROLLER', label: 'Eigenstaendiger Verantwortlicher' },
        { value: 'SUB_PROCESSOR', label: 'Unterauftragnehmer' },
        { value: 'THIRD_PARTY', label: 'Dritter' },
      ]},
      { key: 'suggestedDataAccess', label: 'Datenzugriff', type: 'select', required: false, options: [
        { value: 'NONE', label: 'Kein Zugriff' },
        { value: 'POTENTIAL', label: 'Potenzieller Zugriff' },
        { value: 'ADMINISTRATIVE', label: 'Administrativer Zugriff' },
        { value: 'CONTENT', label: 'Inhaltlicher Zugriff' },
      ]},
    ],
    searchableFields: ['id', 'name', 'description', 'serviceCategory', 'suggestedRole', 'commonProviders'],
  },

  'country-risk-profiles': {
    id: 'country-risk-profiles',
    name: 'Laenderrisikoprofile',
    description: 'Datenschutz-Risikobewertung nach Laendern',
    module: 'vendor',
    icon: 'Globe',
    systemCount: COUNTRY_RISK_PROFILES.length,
    allowCustom: false,
    idField: 'code',
    nameField: 'name',
    categoryField: 'riskLevel',
    fields: [
      { key: 'code', label: 'Laendercode', type: 'text', required: true },
      { key: 'name', label: 'Land', type: 'text', required: true },
      { key: 'riskLevel', label: 'Risikostufe', type: 'select', required: true, options: [
        { value: 'LOW', label: 'Niedrig' },
        { value: 'MEDIUM', label: 'Mittel' },
        { value: 'HIGH', label: 'Hoch' },
        { value: 'VERY_HIGH', label: 'Sehr hoch' },
      ]},
      { key: 'isEU', label: 'EU-Mitglied', type: 'boolean', required: false },
      { key: 'isEEA', label: 'EWR-Mitglied', type: 'boolean', required: false },
      { key: 'hasAdequacyDecision', label: 'Angemessenheitsbeschluss', type: 'boolean', required: false },
    ],
    searchableFields: ['code', 'name', 'riskLevel'],
  },
}

export const VENDOR_VVT_SYSTEM_ENTRIES: Partial<Record<CatalogId, Record<string, unknown>[]>> = {
  'vvt-templates': VVT_BASELINE_CATALOG as unknown as Record<string, unknown>[],
  'loeschfristen-templates': BASELINE_TEMPLATES as unknown as Record<string, unknown>[],
  'vendor-templates': VENDOR_TEMPLATES as unknown as Record<string, unknown>[],
  'country-risk-profiles': COUNTRY_RISK_PROFILES as unknown as Record<string, unknown>[],
}
