####**********************************************************************
####  autoplot.gg_* S3 methods.
####
####  Thin wrappers that delegate to the corresponding plot.gg_*() method,
####  letting users call ggplot2::autoplot() in pipe-friendly workflows
####  and inside patchwork / cowplot compositions.
####
####  Each method accepts ... and passes it straight through to plot.gg_*
####  so all existing plot arguments remain available.
####**********************************************************************

#' @importFrom ggplot2 autoplot
NULL

#' \code{autoplot} methods for \pkg{ggRandomForests} data objects
#'
#' These let you call \code{ggplot2::autoplot()} on any \code{gg_*} object
#' \pkg{ggRandomForests} returns. Each is a thin wrapper around the matching
#' \code{plot.gg_*()} S3 method, and \code{...} passes straight through, so
#' every argument those plot methods take is still available here.
#'
#' @param object A \code{gg_*} data object (see Details).
#' @param ... Additional arguments passed to the underlying
#'   \code{plot.gg_*()} method.
#'
#' @return A \code{ggplot} object.
#'
#' @details
#' The following \code{gg_*} classes are supported:
#' \describe{
#'   \item{\code{gg_error}}{OOB error vs. number of trees}
#'   \item{\code{gg_vimp}}{Variable importance ranking}
#'   \item{\code{gg_rfsrc}}{Predicted vs. observed values}
#'   \item{\code{gg_variable}}{Marginal dependence}
#'   \item{\code{gg_partial}}{Partial dependence (via \code{plot.variable})}
#'   \item{\code{gg_partial_rfsrc}}{Partial dependence (via \code{partial.rfsrc})}
#'   \item{\code{gg_partial_varpro}}{Partial dependence (via \code{varPro})}
#'   \item{\code{gg_partialpro}}{Partial dependence via \code{varPro} (deprecated alias)}
#'   \item{\code{gg_varpro}}{Variable importance from \code{varPro}}
#'   \item{\code{gg_roc}}{ROC curve}
#'   \item{\code{gg_survival}}{Survival / cumulative hazard curves}
#'   \item{\code{gg_brier}}{Time-resolved Brier score and CRPS}
#' }
#'
#' @name autoplot.gg
#'
#' @examples
#' \donttest{
#' library(ggplot2)
#' set.seed(42)
#' rf <- randomForestSRC::rfsrc(Ozone ~ ., data = na.omit(airquality),
#'                               ntree = 50, importance = TRUE,
#'                               tree.err = TRUE)
#' autoplot(gg_error(rf))
#' autoplot(gg_vimp(rf))
#' }
NULL

#' @rdname autoplot.gg
#' @export
autoplot.gg_error <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_vimp <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_rfsrc <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_variable <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_partial <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_partial_rfsrc <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_partialpro <- function(object, ...) {
  ## Deprecated-class shim: re-dispatch to autoplot.gg_partial_varpro.
  class(object) <- c("gg_partial_varpro", setdiff(class(object), "gg_partialpro"))
  autoplot.gg_partial_varpro(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_partial_varpro <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_roc <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_survival <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_brier <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_varpro <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_udependent <- function(object, ...) {
  plot(object, ...)
}

#' @rdname autoplot.gg
#' @export
autoplot.gg_isopro <- function(object, ...) {
  plot(object, ...)
}
