///|
/// Severity assigned to an audit finding.
pub(all) enum Severity {
  Info
  Warning
  Error
} derive(Eq, Debug)

///|
/// A MoonBit module dependency discovered in the module manifest.
pub(all) struct Dependency {
  name : String
  version : String
} derive(Eq, Debug)

///|
/// Metadata parsed from `moon.mod` or legacy `moon.mod.json`.
pub(all) struct Project {
  name : String
  version : String
  license : String
  repository : String
  dependencies : Array[Dependency]
} derive(Eq, Debug)

///|
/// One actionable release-readiness or compliance observation.
pub(all) struct Finding {
  severity : Severity
  code : String
  path : String
  message : String
} derive(Eq, Debug)

///|
/// File-system facts collected by the CLI and audited by the pure library.
pub(all) struct ScanFacts {
  project : Project
  files : Array[String]
  moonbit_source_lines : Int
  license_text : String?
} derive(Eq, Debug)

///|
/// Complete deterministic result of a MoonSeal audit.
pub(all) struct AuditReport {
  project : Project
  findings : Array[Finding]
  moonbit_source_lines : Int
  score : Int
} derive(Eq, Debug)

///|
pub fn Severity::label(self : Severity) -> String {
  match self {
    Info => "INFO"
    Warning => "WARN"
    Error => "ERROR"
  }
}

///|
pub fn AuditReport::error_count(self : AuditReport) -> Int {
  self.findings.fold(init=0, (count, finding) => {
    if finding.severity == Error {
      count + 1
    } else {
      count
    }
  })
}

///|
pub fn AuditReport::warning_count(self : AuditReport) -> Int {
  self.findings.fold(init=0, (count, finding) => {
    if finding.severity == Warning {
      count + 1
    } else {
      count
    }
  })
}

///|
pub fn AuditReport::is_ready(self : AuditReport) -> Bool {
  self.error_count() == 0
}