#' @tags skip_on_cran  ## (35s) to limit total check time
if (requireNamespace("glmmTMB") && getRversion() >= "4.4.0") {
library(futurize)
library(glmmTMB)
options(future.rng.onMisuse = "error")

plan(multisession)

## Adopted from example("confint.glmmTMB", package = "glmmTMB")
m <- glmmTMB(count ~ mined + (1 | site), data = Salamanders, family = nbinom2)

message("Ordinary processing:")
pr_truth <- profile(m)
print(head(pr_truth))

message("Futurized processing:")
pr <- profile(m) |> futurize_and_verify()
print(head(pr))
message("Comparing results:")
stopifnot(all.equal(pr, pr_truth))

## Skip confint() for 'glmmTMB' until has been fixed per
## https://github.com/glmmTMB/glmmTMB/issues/1268
if (FALSE) {
  ## confint.glmmTMB() via stats::confint() S3 generic dispatch
  message("Ordinary processing:")
  ci_truth <- confint(m, method = "profile")
  print(ci_truth)
  
  message("Futurized processing:")
  ci <- confint(m, method = "profile") |> futurize_and_verify()
  print(ci)
  message("Comparing results:")
  stopifnot(all.equal(ci, ci_truth))
}

plan(sequential)
} ## if (requireNamespace("glmmTMB"))
