test_that("ild_diagnose lmer bundle has denser data, design, fit, predictive sections", {
  d <- ild_simulate(n_id = 6, n_obs_per = 5, seed = 400)
  x <- ild_prepare(d, id = "id", time = "time")
  x <- ild_center(x, y)
  fit <- ild_lme(y ~ y_bp + y_wp + (1 | id), data = x, ar1 = FALSE, warn_no_ar1 = FALSE)
  b <- ild_diagnose(fit, data = x)
  expect_true(!is.null(b$data$cohort))
  expect_true(!is.null(b$data$obs_per_id))
  expect_true(!is.null(b$data$outcome_summaries))
  expect_true(!is.null(b$design$flags))
  expect_true(!is.null(b$design$time_coverage))
  expect_equal(b$design$occasion_imbalance, b$data$obs_per_id)
  expect_true(!is.null(b$fit$optimizer$reml))
  expect_true(!is.null(b$fit$random_effects_structure$theta))
  expect_true(!is.null(b$fit$residual_correlation))
  expect_true(!is.null(b$fit$rank$fixed_effects_X))
  expect_true(!is.null(b$predictive$obs_metrics$n))
  expect_true(!is.null(b$predictive$n))
  expect_true(!is.null(b$predictive$mean_residual))
  expect_true(!is.null(b$predictive$max_abs_error))
  expect_true(!is.null(b$missingness$summary) || !is.null(b$missingness$note))
})

test_that("ild_diagnose causal_detail adds weight_detail when .ipw present", {
  d <- ild_simulate(n_id = 5, n_obs_per = 4, seed = 401)
  x <- ild_prepare(d, id = "id", time = "time")
  x <- ild_center(x, y)
  x$.ipw <- rep(1, nrow(x))
  fit <- ild_lme(y ~ y_bp + y_wp + (1 | id), data = x, ar1 = FALSE, warn_no_ar1 = FALSE)
  b <- ild_diagnose(fit, data = x, causal_detail = TRUE)
  expect_true(!is.null(b$causal$weight_detail))
  expect_true(!is.null(b$causal$weight_detail$quantiles))
})
