#' Estimate Cox proportional hazards model for threshold breach
#'
#' @param surv_profile Data frame from vowr_survival_merge()
#' @return A fitted Cox proportional hazards model
#' @export
vowr_cox_model <- function(surv_profile) {

  required <- c("time_days", "status", "mean_wait", "volatility", "total_backlog")

  missing_cols <- setdiff(required, names(surv_profile))

  if (length(missing_cols) > 0) {
    stop(
      "Missing required columns: ",
      paste(missing_cols, collapse = ", ")
    )
  }

  model_data <- stats::na.omit(
    surv_profile[, required]
  )

  fit <- survival::coxph(
    survival::Surv(time_days, status) ~ mean_wait + volatility + total_backlog,
    data = model_data
  )

  return(fit)
}
