///|
pub enum BundleSelection {
  AllReports
  PublishableOnly
  NeedsReview
} derive(Debug, Eq)

///|
pub fn bundle_selections() -> Array[BundleSelection] {
  [AllReports, PublishableOnly, NeedsReview]
}

///|
pub fn ReportBundle::reports(self : ReportBundle) -> Array[ChemReport] {
  self.reports.copy()
}

///|
pub fn ReportBundle::find_title(
  self : ReportBundle,
  title : String,
) -> ChemReport? {
  for report in self.reports {
    if report.title == title {
      break Some(report)
    }
  } nobreak {
    None
  }
}

///|
pub fn ReportBundle::select(
  self : ReportBundle,
  selection : BundleSelection,
) -> Array[ChemReport] {
  let selected : Array[ChemReport] = []
  for report in self.reports {
    let selected_report = match selection {
      AllReports => true
      PublishableOnly => report.is_publishable()
      NeedsReview => !report.is_publishable()
    }
    if selected_report {
      selected.push(report)
    }
  }
  selected
}

///|
pub fn ReportBundle::merge(
  self : ReportBundle,
  other : ReportBundle,
) -> ReportBundle {
  let reports = self.reports.copy()
  for report in other.reports {
    reports.push(report)
  }
  report_bundle("{self.title} + {other.title}", reports)
}

///|
pub fn ReportBundle::titles(self : ReportBundle) -> Array[String] {
  [
    for report in self.reports => report.title
  ]
}