///|
pub(all) enum RiskLevel {
  Low
  Medium
  High
  Critical
} derive(Debug, Eq, Compare)

///|
pub impl Show for RiskLevel with fn output(self, logger) {
  match self {
    Low => logger.write_string("low")
    Medium => logger.write_string("medium")
    High => logger.write_string("high")
    Critical => logger.write_string("critical")
  }
}

///|
pub fn risk_level(finding : Finding) -> RiskLevel {
  match finding.kind {
    IdNumber | MedicalRecord | Insurance => Critical
    PersonName | Phone | Email | Address => High
    Date | Organization => Medium
    Custom(_) => if finding.confidence >= 90 { High } else { Low }
  }
}

///|
pub fn highest_risk(findings : Array[Finding]) -> RiskLevel {
  let mut level : RiskLevel = Low
  for finding in findings {
    let current = risk_level(finding)
    if current > level {
      level = current
    }
  }
  level
}

///|
pub fn risk_summary(findings : Array[Finding]) -> Map[String, Int] {
  let summary : Map[String, Int] = Map([])
  for finding in findings {
    let key = "\{risk_level(finding)}"
    summary[key] = summary.get_or_default(key, 0) + 1
  }
  summary
}