library(AutoMLR)

data("cancer", package = "survival", envir = environment())
lung <- get("lung", envir = environment())
lung <- stats::na.omit(lung)
lung$status <- as.integer(lung$status == 2)
lung$sample_id <- paste0("lung_", seq_len(nrow(lung)))
lung$cohort <- rep(c("Lung_A", "Lung_B"), length.out = nrow(lung))
lung <- lung[seq_len(min(80L, nrow(lung))), ]

prep <- prepare_cohort_input(
  lung,
  cohort = "cohort",
  time = "time",
  status = "status",
  id = "sample_id"
)

params <- automlr_parameters(
  algorithms = c("lasso_cox", "ridge_cox", "enet_cox", "stepwise_cox"),
  eval_times = c(180, 365, 730),
  time_unit = "days",
  stability_resamples = 2L,
  verbose = FALSE
)

fit <- fit_surv_ensemble(
  prep,
  params = params,
  min_models = 1,
  max_models = 2,
  verbose = FALSE
)

render_surv_report(
  fit,
  output_dir = file.path(tempdir(), "automlr-small-lung-report"),
  title = "AutoMLR Small Lung Report"
)

export_surv_results(
  fit,
  output_dir = file.path(tempdir(), "automlr-small-lung-export"),
  formats = c("png", "pdf"),
  top_n = 10L,
  publication = TRUE,
  summary_language = "bilingual"
)
