#' Summary of Generalized Heckman Model
#'
#' @description
#' Print estimates of the parameters of the Generalized Heckman model using Maximum Likelihood Estimation.
#'
#' @param object An object of class \code{HeckmanGe}.
#' @param ... Additional arguments (currently unused).
#'
#' @return
#' Prints the summary output including coefficient tables and model fit statistics.
#'
#' @export summary.HeckmanGe
#' @export
summary.HeckmanGe <- function(object, ...) {
  prop_sigmaHG <- object$prop_sigmaHG
  coeffsHG <- object$coefficients
  counts <- object$counts
  loglik <- object$loglik
  NObs <- object$nObs
  nParam <- object$nParam
  df <- object$df
  NXS <- object$NXS
  NXO <- object$NXO
  N0 <- object$N0
  N1 <- object$N1
  aic <- object$aic
  bic <- object$bic
  NE <- object$NE
  NV <- object$NV

  idxS <- seq_len(NXS)
  idxO <- seq.int(NXS + 1L, NXS + NXO)
  idxE <- seq.int(NXS + NXO + 1L, NXS + NXO + NE)
  idxV <- seq.int(NXS + NXO + NE + 1L, NXS + NXO + NE + NV)

  tb1 <- miscTools::coefTable(coeffsHG[idxS], prop_sigmaHG[idxS], df = df)
  tb2 <- miscTools::coefTable(coeffsHG[idxO], prop_sigmaHG[idxO], df = df)
  tb3 <- miscTools::coefTable(coeffsHG[idxE], prop_sigmaHG[idxE], df = df)
  tb4 <- miscTools::coefTable(coeffsHG[idxV], prop_sigmaHG[idxV], df = df)

  cat("\n")
  cat("--------------------------------------------------------------\n")
  cat("       Generalized Heckman Model (Package: ssmodels)          \n")
  cat("--------------------------------------------------------------\n")
  cat("Maximum Likelihood estimation \n")
  cat("optim function with method BFGS - iterations number:", counts, "\n")
  cat("Log-Likelihood:", loglik, "\n")
  cat("AIC:", aic, "BIC:", bic, "\n")
  cat("Number of observations:", NObs, "(", N0, "censored and", N1, "observed )\n")
  cat(nParam, "free parameters ( df =", df, ")\n")
  cat("--------------------------------------------------------------\n")

  cat("Probit selection equation:\n")
  printCoefmat(tb1, signif.stars = TRUE, signif.legend = FALSE, digits = 4)
  cat("--------------------------------------------------------------\n")

  cat("Outcome equation:\n")
  printCoefmat(tb2, signif.stars = TRUE, signif.legend = FALSE, digits = 4)
  cat("--------------------------------------------------------------\n")

  cat("Dispersion terms:\n")
  printCoefmat(tb3, signif.stars = TRUE, signif.legend = FALSE, digits = 4)
  cat("--------------------------------------------------------------\n")

  cat("Correlation terms:\n")
  printCoefmat(tb4, signif.stars = TRUE, signif.legend = TRUE, digits = 4)
  cat("--------------------------------------------------------------\n")
}
