# Function for running the same model with multiple methods
# Used within tests
allMethods <- c("rca", "uca", "ca", "dblcent", "mplus", "pind")
allNativeMethods <- allMethods[allMethods != "mplus"]
fastMethods <- c("rca", "uca", "dblcent", "pind")

runMultipleMethods <- function(model.syntax,
                               data,
                               methods = allNativeMethods,
                               ...) {
  estimates <- structure(vector("list", length = length(methods)),
                         names = methods)
  for (method in methods) {
    estimates[[method]] <- tryCatch(
      modsem(model.syntax, data, method, ...),
      warning = function(w) {
        mod_msg_warn(paste0("Warning in ", method, "\n", conditionMessage(w), "\n"))
        modsem(model.syntax, data, method, ...)
      },
      error = function(e) {
        mod_msg_warn(paste0("Error in ", method, "\n", conditionMessage(e)))
        NA
      }
    )
  }
  estimates
}
