/**
 * SDK Catalog Manager - Type Definitions
 */

// All catalog IDs in the system
export type CatalogId =
  | 'dsfa-risks'
  | 'dsfa-mitigations'
  | 'ai-risks'
  | 'ai-mitigations'
  | 'prohibited-ai-practices'
  | 'vvt-templates'
  | 'loeschfristen-templates'
  | 'vendor-templates'
  | 'country-risk-profiles'
  | 'legal-bases'
  | 'retention-periods'
  | 'eu-legal-frameworks'
  | 'national-legal-frameworks'
  | 'gdpr-enforcement-cases'
  | 'wp248-criteria'
  | 'sdm-goals'
  | 'dsfa-authority-resources'

// Module grouping
export type CatalogModule = 'dsfa' | 'vvt' | 'vendor' | 'ai_act' | 'reference'

// Field types for dynamic forms
export type CatalogFieldType = 'text' | 'textarea' | 'number' | 'select' | 'multiselect' | 'boolean' | 'tags'

export interface CatalogFieldSchema {
  key: string
  label: string
  type: CatalogFieldType
  required: boolean
  placeholder?: string
  description?: string
  options?: { value: string; label: string }[]
  helpText?: string
  min?: number
  max?: number
  step?: number
}

export interface CatalogMeta {
  id: CatalogId
  name: string
  description: string
  module: CatalogModule
  icon: string // lucide icon name
  systemCount: number
  allowCustom: boolean
  idField: string // which field is the unique ID (e.g. 'id', 'templateId', 'code')
  nameField: string // which field is the display name (e.g. 'title', 'name', 'dataObjectName')
  descriptionField?: string // which field holds description
  categoryField?: string // optional grouping field
  fields: CatalogFieldSchema[]
  searchableFields: string[]
}

// A custom catalog entry added by the user
export interface CustomCatalogEntry {
  id: string // Generated UUID
  catalogId: CatalogId
  data: Record<string, unknown>
  createdAt: string // ISO date
  updatedAt: string // ISO date
  createdBy?: string
}

// All custom entries, keyed by CatalogId
export type CustomCatalogs = Partial<Record<CatalogId, CustomCatalogEntry[]>>

// Combined view entry (system or custom)
export interface CatalogEntry {
  id: string
  catalogId: CatalogId
  source: 'system' | 'custom'
  data: Record<string, unknown>
  displayName: string
  displayDescription?: string
  category?: string
}

// Stats for a single catalog
export interface CatalogStats {
  catalogId: CatalogId
  systemCount: number
  customCount: number
  totalCount: number
}

// Stats for all catalogs
export interface CatalogOverviewStats {
  totalCatalogs: number
  totalSystemEntries: number
  totalCustomEntries: number
  totalEntries: number
  byModule: Record<CatalogModule, { catalogs: number; entries: number }>
}

// Module labels
export const CATALOG_MODULE_LABELS: Record<CatalogModule, string> = {
  dsfa: 'DSFA & Risiken',
  vvt: 'VVT & Loeschfristen',
  vendor: 'Auftragsverarbeitung',
  ai_act: 'AI Act',
  reference: 'Referenzdaten',
}

// Module icons (lucide names)
export const CATALOG_MODULE_ICONS: Record<CatalogModule, string> = {
  dsfa: 'ShieldAlert',
  vvt: 'FileText',
  vendor: 'Building2',
  ai_act: 'Bot',
  reference: 'BookOpen',
}
