///|
pub struct BundleSummary {
  report_count : Int
  publishable_count : Int
  blocking_count : Int
  input_count : Int
  result_count : Int
  warning_count : Int
  source_count : Int
} derive(Debug, Eq)

///|
pub fn ReportBundle::summary(self : ReportBundle) -> BundleSummary {
  let metrics = self.metrics()
  {
    report_count: metrics.report_count,
    publishable_count: metrics.publishable_count,
    blocking_count: metrics.blocking_count,
    input_count: metrics.input_count,
    result_count: metrics.result_count,
    warning_count: metrics.warning_count,
    source_count: metrics.source_count,
  }
}

///|
pub fn ReportBundle::contains_hazard(self : ReportBundle) -> Bool {
  let mut found = false
  for report in self.reports {
    for warning in report.warnings {
      if warning.severity == Hazard {
        found = true
      }
    }
  }
  found
}

///|
pub fn ReportBundle::summary_markdown(self : ReportBundle) -> String {
  let summary = self.summary()
  let lines : Array[String] = [
    "# \{self.title}",
    "",
    "| Metric | Value |",
    "| --- | ---: |",
    "| Reports | \{summary.report_count} |",
    "| Publishable | \{summary.publishable_count} |",
    "| Reports needing review | \{summary.blocking_count} |",
    "| Inputs | \{summary.input_count} |",
    "| Results | \{summary.result_count} |",
    "| Warnings | \{summary.warning_count} |",
    "| Sources | \{summary.source_count} |",
  ]
  for report in self.reports {
    lines.push("")
    lines.push("## \{report.title}")
    lines.push("")
    lines.push(
      if report.is_publishable() {
        "Status: publishable"
      } else {
        "Status: review required"
      },
    )
  }
  lines.join("\n")
}