/**
 * Reporting Module Types
 *
 * TypeScript definitions for the Executive Reporting module.
 * Provides compliance KPIs, risk overview, deadlines, and activity tracking
 * for top management and compliance officers.
 */

// =============================================================================
// RISK LEVELS
// =============================================================================

export type RiskLevel = 'LOW' | 'MEDIUM' | 'HIGH' | 'CRITICAL'
export type DeadlineSeverity = 'INFO' | 'WARNING' | 'URGENT' | 'OVERDUE'

export const RISK_LEVEL_INFO: Record<RiskLevel, { label: string; color: string; bgColor: string; borderColor: string }> = {
  LOW: { label: 'Niedrig', color: 'text-green-700', bgColor: 'bg-green-100', borderColor: 'border-green-200' },
  MEDIUM: { label: 'Mittel', color: 'text-yellow-700', bgColor: 'bg-yellow-100', borderColor: 'border-yellow-200' },
  HIGH: { label: 'Hoch', color: 'text-orange-700', bgColor: 'bg-orange-100', borderColor: 'border-orange-200' },
  CRITICAL: { label: 'Kritisch', color: 'text-red-700', bgColor: 'bg-red-100', borderColor: 'border-red-200' },
}

export const DEADLINE_SEVERITY_INFO: Record<DeadlineSeverity, { label: string; color: string; bgColor: string }> = {
  INFO: { label: 'Info', color: 'text-blue-700', bgColor: 'bg-blue-100' },
  WARNING: { label: 'Warnung', color: 'text-yellow-700', bgColor: 'bg-yellow-100' },
  URGENT: { label: 'Dringend', color: 'text-orange-700', bgColor: 'bg-orange-100' },
  OVERDUE: { label: 'Ueberfaellig', color: 'text-red-700', bgColor: 'bg-red-100' },
}

// =============================================================================
// MODULE SUMMARIES
// =============================================================================

export interface DSGVOSummary {
  processingActivities: number
  activeProcessings: number
  tomsImplemented: number
  tomsPlanned: number
  tomsTotal: number
  completionPercent: number
  openDSRs: number
  overdueDSRs: number
  dsfasCompleted: number
  retentionPolicies: number
}

export interface VendorSummary {
  totalVendors: number
  activeVendors: number
  byRiskLevel: Record<string, number>
  pendingReviews: number
  expiredContracts: number
}

export interface IncidentSummary {
  totalIncidents: number
  openIncidents: number
  criticalIncidents: number
  notificationsPending: number
  avgResolutionHours: number
}

export interface WhistleblowerSummary {
  totalReports: number
  openReports: number
  overdueAcknowledgments: number
  overdueFeedbacks: number
  avgResolutionDays: number
}

export interface AcademySummary {
  totalCourses: number
  totalEnrollments: number
  completionRate: number
  overdueCount: number
  avgCompletionDays: number
}

// =============================================================================
// RISK & DEADLINES
// =============================================================================

export interface ModuleRisk {
  module: string
  level: RiskLevel
  score: number
  issues: number
}

export interface RiskOverview {
  overallLevel: RiskLevel
  moduleRisks: ModuleRisk[]
  openFindings: number
  criticalFindings: number
}

export interface Deadline {
  module: string
  type: string
  description: string
  dueDate: string
  daysLeft: number
  severity: DeadlineSeverity
}

export interface ActivityEntry {
  timestamp: string
  module: string
  action: string
  description: string
  userId?: string
}

// =============================================================================
// EXECUTIVE REPORT (Main Response)
// =============================================================================

export interface ExecutiveReport {
  generatedAt: string
  tenantId: string
  complianceScore: number

  dsgvo: DSGVOSummary
  vendors: VendorSummary
  incidents: IncidentSummary
  whistleblower: WhistleblowerSummary
  academy: AcademySummary

  riskOverview: RiskOverview
  upcomingDeadlines: Deadline[]
  recentActivity: ActivityEntry[]
}

// =============================================================================
// COMPACT SCORE RESPONSE
// =============================================================================

export interface ComplianceScoreResponse {
  complianceScore: number
  riskLevel: RiskLevel
  generatedAt: string
}

// =============================================================================
// HELPER FUNCTIONS
// =============================================================================

export function getRiskLevelInfo(level: RiskLevel) {
  return RISK_LEVEL_INFO[level]
}

export function getDeadlineSeverityInfo(severity: DeadlineSeverity) {
  return DEADLINE_SEVERITY_INFO[severity]
}

export function getScoreColor(score: number): string {
  if (score >= 80) return 'text-green-600'
  if (score >= 60) return 'text-yellow-600'
  if (score >= 40) return 'text-orange-600'
  return 'text-red-600'
}

export function getScoreBgColor(score: number): string {
  if (score >= 80) return 'bg-green-500'
  if (score >= 60) return 'bg-yellow-500'
  if (score >= 40) return 'bg-orange-500'
  return 'bg-red-500'
}
