#' Run complete Volatility-Oriented Waiting-time Risk workflow
#'
#' @param data A data frame from vowr_import()
#' @param wait_threshold Waiting-time breach threshold. Default is 18 weeks.
#' @param vol_percentile Volatility percentile for risk flagging. Default is 0.90.
#'
#' @return A list containing profile, flagged data, risk plot, survival output,
#' survival profile, Cox model, and Kaplan-Meier plot by risk group.
#'
#' @export
vowr_workflow <- function(data, wait_threshold = 18, vol_percentile = 0.90) {

  profile <- vowr_profile(data)

  flagged <- vowr_flag(
    profile = profile,
    wait_threshold = wait_threshold,
    vol_percentile = vol_percentile
  )

  risk_plot <- vowr_plot(flagged)

  survival <- vowr_survival(
    data = data,
    threshold = wait_threshold
  )

  survival_profile <- vowr_survival_merge(
    surv_result = survival,
    profile = profile,
    flagged = flagged
  )

  cox_model <- vowr_cox_model(survival_profile)

  km_risk_plot <- vowr_km_by_risk(survival_profile)

  return(list(
    profile = profile,
    flagged = flagged,
    risk_plot = risk_plot,
    survival = survival,
    survival_profile = survival_profile,
    cox_model = cox_model,
    km_risk_plot = km_risk_plot
  ))
}
