///|
pub fn SourceBundle::average_line_length(self : SourceBundle) -> Int {
  if self.total_lines() == 0 {
    0
  } else {
    self.total_characters() / self.total_lines()
  }
}

///|
pub fn SourceBundle::file_with_most_code(self : SourceBundle) -> SourceSummary? {
  let summaries = self.summaries()
  if summaries.length() == 0 {
    return None
  }
  let mut best = summaries[0]
  for summary in summaries {
    if summary.code_lines > best.code_lines {
      best = summary
    }
  }
  Some(best)
}

///|
pub fn SourceBundle::empty_files(self : SourceBundle) -> Array[String] {
  let result : Array[String] = []
  for file in self.files {
    if file.text().trim().is_empty() {
      result.push(file.name())
    }
  }
  result
}

///|
pub fn SourceBundle::comment_only_files(self : SourceBundle) -> Array[String] {
  let result : Array[String] = []
  for summary in self.summaries() {
    if summary.code_lines == 0 && summary.comment_lines > 0 {
      result.push(summary.file_name)
    }
  }
  result
}

///|
pub fn SourceBundle::file_count_with_extension(
  self : SourceBundle,
  extension : String,
) -> Int {
  let mut count = 0
  for file in self.files {
    if file.name().has_suffix(extension) {
      count += 1
    }
  }
  count
}

///|
pub fn SourceBundle::quality_summary(self : SourceBundle) -> String {
  "average_line_length=" +
  self.average_line_length().to_string() +
  ", empty_files=" +
  self.empty_files().length().to_string() +
  ", comment_only_files=" +
  self.comment_only_files().length().to_string() +
  ", max_line_length=" +
  self.max_line_length().to_string()
}