// =============================================================================
// RISK MATRIX HELPERS
// =============================================================================

import type { DSFARiskLevel } from './enums-constants'

export interface RiskMatrixCell {
  likelihood: 'low' | 'medium' | 'high'
  impact: 'low' | 'medium' | 'high'
  level: DSFARiskLevel
  score: number
}

export const RISK_MATRIX: RiskMatrixCell[] = [
  // Low likelihood
  { likelihood: 'low', impact: 'low', level: 'low', score: 10 },
  { likelihood: 'low', impact: 'medium', level: 'low', score: 20 },
  { likelihood: 'low', impact: 'high', level: 'medium', score: 40 },
  // Medium likelihood
  { likelihood: 'medium', impact: 'low', level: 'low', score: 20 },
  { likelihood: 'medium', impact: 'medium', level: 'medium', score: 50 },
  { likelihood: 'medium', impact: 'high', level: 'high', score: 70 },
  // High likelihood
  { likelihood: 'high', impact: 'low', level: 'medium', score: 40 },
  { likelihood: 'high', impact: 'medium', level: 'high', score: 70 },
  { likelihood: 'high', impact: 'high', level: 'very_high', score: 90 },
]

export function calculateRiskLevel(
  likelihood: 'low' | 'medium' | 'high',
  impact: 'low' | 'medium' | 'high'
): { level: DSFARiskLevel; score: number } {
  const cell = RISK_MATRIX.find(c => c.likelihood === likelihood && c.impact === impact)
  return cell ? { level: cell.level, score: cell.score } : { level: 'medium', score: 50 }
}
