#' +.PriorsmcmcComposite is a general function to set priors for MHalgoGen()
#' @title Set priors for MHalgoGen()
#' @author Marc Girondot \email{marc.girondot@@gmail.com}
#' @return Return a data.frame with the formatted priors
#' @param prior1 The first prior.
#' @param prior2 The second prior.
#' @description Construct priors for MHalgoGen()\cr
#' A check is done to verify that parameter names are not duplicated.
#' @family mcmcComposite functions
#' @examples
#' \dontrun{
#' library(HelpersMG)
#' Priors <- setPriors1(Name="a0", Prior1=0, Prior2=1, Density="dunif", 
#'                      SDProp=0.1, Min=0, Max=1, Init=0.5)
#' Priors <- Priors + setPriors1(Name="a1", Prior1=0.5, Prior2=0.1, Density="dnorm", 
#'                      SDProp=0.05, Min=0, Max=1, Init=0.5)
#' # Using Parameters
#' Priors <- setPriors1(Name="a0", Parameters=c(min=0, max=1), Density="dunif", 
#'                      SDProp=0.1, Min=0, Max=1, Init=0.5)
#' Priors <- Priors + setPriors1(Name="a1", Parameters=c(mean=0.5, sd=0.1), Density="dnorm", 
#'                      SDProp=0.05, Min=0, Max=1, Init=0.5)
#' }
#' @export

`+.PriorsmcmcComposite` <- function(prior1, prior2) {
  
  if (!inherits(prior2, "PriorsmcmcComposite")) {
    stop("Both objects must be of class 'PriorsmcmcComposite' generated using setPrior1().")
  }
  
  # Optional: check same columns
   # if (!all(names(prior1) == names(prior2))) {
   #   if (warn) warning("Priors of same names are replaced.")
   # }
  
  # if (any(duplicated(c(rownames(prior1), rownames(prior2))))) {
  #   if (warn) warning("Priors of same names are replaced.")
  # }
  
  if (all(colnames(prior2) != "Prior3")) {
    prior2 <- cbind(prior2[, c("Density", "Prior1", "Prior2")], Prior3=NA, prior2[, c("SDProp", "Min", "Max", "Init")])
  }
  
  if (all(colnames(prior1) != "Prior3")) {
    prior1 <- cbind(prior1[, c("Density", "Prior1", "Prior2")], Prior3=NA, prior1[, c("SDProp", "Min", "Max", "Init")])
  }
  
  prior1 <- prior1[!(rownames(prior1) %in% rownames(prior2)), ]
  
  res <- rbind(prior1, prior2)
  class(res) <- c("PriorsmcmcComposite", "data.frame")  # keep class
  
  return(res)
}
