// =============================================================================
// Types
// =============================================================================

export interface Obligation {
  id: string
  title: string
  description: string
  source: string
  source_article: string
  deadline: string | null
  status: 'pending' | 'in-progress' | 'completed' | 'overdue'
  priority: 'critical' | 'high' | 'medium' | 'low'
  responsible: string
  linked_systems: string[]
  linked_vendor_ids?: string[]
  assessment_id?: string
  rule_code?: string
  notes?: string
  created_at?: string
  updated_at?: string
}

export interface ObligationStats {
  pending: number
  in_progress: number
  overdue: number
  completed: number
  total: number
  critical: number
  high: number
}

export interface ObligationFormData {
  title: string
  description: string
  source: string
  source_article: string
  deadline: string
  status: string
  priority: string
  responsible: string
  linked_systems: string
  linked_vendor_ids: string
  notes: string
}

export const EMPTY_FORM: ObligationFormData = {
  title: '',
  description: '',
  source: 'DSGVO',
  source_article: '',
  deadline: '',
  status: 'pending',
  priority: 'medium',
  responsible: '',
  linked_systems: '',
  linked_vendor_ids: '',
  notes: '',
}

export const API = '/api/sdk/v1/compliance/obligations'
export const UCCA_API = '/api/sdk/v1/ucca/obligations'

// =============================================================================
// Status helpers
// =============================================================================

export const PRIORITY_COLORS: Record<string, string> = {
  critical: 'bg-red-100 text-red-700',
  high:     'bg-orange-100 text-orange-700',
  medium:   'bg-yellow-100 text-yellow-700',
  low:      'bg-green-100 text-green-700',
}

export const PRIORITY_LABELS: Record<string, string> = {
  critical: 'Kritisch',
  high:     'Hoch',
  medium:   'Mittel',
  low:      'Niedrig',
}

export const STATUS_COLORS: Record<string, string> = {
  pending:      'bg-gray-100 text-gray-600',
  'in-progress':'bg-blue-100 text-blue-700',
  completed:    'bg-green-100 text-green-700',
  overdue:      'bg-red-100 text-red-700',
}

export const STATUS_LABELS: Record<string, string> = {
  pending:      'Ausstehend',
  'in-progress':'In Bearbeitung',
  completed:    'Abgeschlossen',
  overdue:      'Ueberfaellig',
}

export const STATUS_NEXT: Record<string, string> = {
  pending:      'in-progress',
  'in-progress':'completed',
  completed:    'pending',
  overdue:      'in-progress',
}

export const REGULATION_CHIPS = [
  { key: 'all', label: 'Alle' },
  { key: 'DSGVO', label: 'DSGVO' },
  { key: 'AI Act', label: 'AI Act' },
  { key: 'NIS2', label: 'NIS2' },
  { key: 'BDSG', label: 'BDSG' },
  { key: 'TTDSG', label: 'TTDSG' },
  { key: 'DSA', label: 'DSA' },
  { key: 'Data Act', label: 'Data Act' },
  { key: 'DORA', label: 'DORA' },
  { key: 'EU-Maschinen', label: 'EU-Maschinen' },
]

export function mapPriority(p: string): 'critical' | 'high' | 'medium' | 'low' {
  const map: Record<string, 'critical' | 'high' | 'medium' | 'low'> = {
    kritisch: 'critical', hoch: 'high', mittel: 'medium', niedrig: 'low',
    critical: 'critical', high: 'high', medium: 'medium', low: 'low',
  }
  return map[p?.toLowerCase()] || 'medium'
}
