#' Post-process Parameter Vector for Generalized Heckman Models
#'
#' @description
#' This helper assigns names to a generalized Heckman parameter vector and,
#' for intercept-only scale/correlation models, maps log(sigma) and atanh(rho)
#' to sigma and rho.
#'
#' @param theta_par Numeric vector of estimated parameters on the optimization scale.
#' @param NXS Integer. Number of covariates in the selection equation.
#' @param NXO Integer. Number of covariates in the outcome equation.
#' @param NE Integer. Number of scale parameters.
#' @param NV Integer. Number of correlation parameters.
#' @param XS Design matrix for the selection equation.
#' @param XO Design matrix for the outcome equation.
#' @param outcomeS Design matrix or variable for the scale model.
#' @param outcomeC Design matrix or variable for the correlation model.
#'
#' @return A named numeric vector.
#' @keywords internal
#' @export
postprocess_theta <- function(theta_par, NXS, NXO, NE, NV, XS, XO, outcomeS, outcomeC) {
  sigma_names <- if (NE == 1L) "sigma" else paste0("log.sigma.", seq_len(NE))
  rho_names <- if (NV == 1L) "rho" else paste0("atanh.rho.", seq_len(NV))
  param_names <- c(colnames(XS), colnames(XO), sigma_names, rho_names)
  names(theta_par) <- param_names

  idx_sigma <- seq.int(NXS + NXO + 1L, NXS + NXO + NE)
  idx_rho <- seq.int(NXS + NXO + NE + 1L, NXS + NXO + NE + NV)

  if (NE == 1L) theta_par[idx_sigma] <- exp(theta_par[idx_sigma])
  if (NV == 1L) theta_par[idx_rho] <- tanh(theta_par[idx_rho])

  theta_par
}
