#' Confidence interval for an aedl object
#'
#' @param object An object of class `"aedl"`.
#' @param parm Unused; included for S3 compatibility.
#' @param level Confidence level. Currently must match the level used when
#'   fitting `object`; a different level requires refitting.
#' @param ... Unused.
#'
#' @return A two-column matrix with confidence limits.
#' @export
confint.aedl <- function(object, parm = NULL, level = NULL, ...) {
  if (!inherits(object, "aedl")) {
    stop("object must inherit from class 'aedl'.", call. = FALSE)
  }
  if (!is.null(level) && !isTRUE(all.equal(level, object$conf.level))) {
    stop("Refitting is required to use a different confidence level.",
         call. = FALSE)
  }

  ci <- matrix(c(object$ci.lb, object$ci.ub), nrow = 1)
  colnames(ci) <- c("2.5 %", "97.5 %")
  rownames(ci) <- "theta"

  if (!is.null(object$conf.level)) {
    alpha <- 1 - object$conf.level
    pct <- c(alpha / 2, 1 - alpha / 2) * 100
    colnames(ci) <- paste0(format(pct, trim = TRUE), " %")
  }

  ci
}
