#' @title Acquisition Function Mean
#'
#' @include AcqFunction.R
#' @name mlr_acqfunctions_mean
#'
#' @templateVar id mean
#' @template section_dictionary_acqfunctions
#'
#' @description
#' Posterior Mean.
#'
#' @family Acquisition Function
#' @export
#' @examples
#' if (requireNamespace("mlr3learners") &
#'     requireNamespace("DiceKriging") &
#'     requireNamespace("rgenoud")) {
#'   library(bbotk)
#'   library(paradox)
#'   library(mlr3learners)
#'   library(data.table)
#'
#'   fun = function(xs) {
#'     list(y = xs$x ^ 2)
#'   }
#'   domain = ps(x = p_dbl(lower = -10, upper = 10))
#'   codomain = ps(y = p_dbl(tags = "minimize"))
#'   objective = ObjectiveRFun$new(fun = fun, domain = domain, codomain = codomain)
#'
#'   instance = OptimInstanceBatchSingleCrit$new(
#'     objective = objective,
#'     terminator = trm("evals", n_evals = 5))
#'
#'   instance$eval_batch(data.table(x = c(-6, -5, 3, 9)))
#'
#'   learner = default_gp()
#'
#'   surrogate = srlrn(learner, archive = instance$archive)
#'
#'   acq_function = acqf("mean", surrogate = surrogate)
#'
#'   acq_function$surrogate$update()
#'   acq_function$update()
#'   acq_function$eval_dt(data.table(x = c(-1, 0, 1)))
#' }
AcqFunctionMean = R6Class(
  "AcqFunctionMean",
  inherit = AcqFunction,

  public = list(
    #' @description
    #' Creates a new instance of this [R6][R6::R6Class] class.
    #'
    #' @param surrogate (`NULL` | [SurrogateLearner]).
    initialize = function(surrogate = NULL) {
      super$initialize(
        "acq_mean",
        surrogate = surrogate,
        requires_predict_type_se = FALSE,
        surrogate_class = "SurrogateLearner",
        direction = "same",
        label = "Posterior Mean",
        man = "mlr3mbo::mlr_acqfunctions_mean"
      )
    }
  ),

  private = list(
    .fun = function(xdt) {
      p = self$surrogate$predict(xdt)
      data.table(acq_mean = p$mean)
    }
  )
)

mlr_acqfunctions$add("mean", AcqFunctionMean)
