calc_report_amended_score <- function(report_dates) {
  report_dates |>
    mutate(
      amended_score = amended_score(amended, report_id, received_image, received_data, cover_date_filed),
      .by = c(sboe_id, year, doc_name)
    )
}

amended_score <- function(amended, report_id, received_image, received_data, cover_date_filed) {
  x_amended <- as.integer(amended)

  has_and_is_max <- function(x) {
    if (all(is.na(x))) return(rep(0, length(x)))
    ret <- x == max(x, na.rm = TRUE)
    ret[is.na(ret)] <- FALSE
    as.integer(ret)
  }

  max_na_safe <- function(x) {
    if (all(is.na(x))) NA_Date_ else max(x, na.rm = TRUE)
  }

  the_dates <- tibble::tibble(received_image, received_data, cover_date_filed)
  row_max_date <- apply(the_dates, 1, max_na_safe)

  has_max_receievd_data <- has_and_is_max(received_data)
  has_max_date_filed <- has_and_is_max(cover_date_filed)

  (x_amended * 7) + # the amended check mark beats all else
    has_and_is_max(report_id) +
    has_and_is_max(received_image) +
    has_max_receievd_data +
    has_max_date_filed +
    (has_max_receievd_data & has_max_date_filed) +
    has_and_is_max(row_max_date)
}
