#'
#' @title Checks if an input is valid
#' @description Tells if an object on the server side is valid.
#' @details This function checks if an object is valid.
#' @param obj, a vector (numeric, integer, factor, character), data.frame or matrix
#' @return a boolean, TRUE if input is valid or FALSE if not.
#' @author Gaye, A.
#'@export
#'
isValidDS <- function(obj) {
  
  # this filter sets the minimum number of observations that are allowed 

  #############################################################
  # MODULE 1: CAPTURE THE nfilter SETTINGS
  thr <- listDisclosureSettingsDS()
  nfilter.tab <- as.numeric(thr$nfilter.tab)
  #nfilter.glm <- as.numeric(thr$nfilter.glm)
  #nfilter.subset <- as.numeric(thr$nfilter.subset)
  #nfilter.string <- as.numeric(thr$nfilter.string)
  #############################################################
  
  if(class(obj) == "character" | class(obj) == "integer" | class(obj) == "logical" | class(obj) == "numeric") {
    if(length(obj) > 0 & length(obj)  < nfilter.tab) {
      return(FALSE)
    } else {
      return(TRUE)
    }
  }else{
    if(class(obj) == "factor"){
      tt <- tabulate(obj)
      xx <- which(tt > 0 & tt < nfilter.tab)
      if(length(xx) > 0) {
        return(FALSE)
      } else {
        return(TRUE)
      }
    }else{
      if(class(obj) == "data.frame" | class(obj) == "matrix"){
        if(dim(obj)[1] > 0 & dim(obj)[1] < nfilter.tab){
          return(FALSE)
        }else{
          return(TRUE)
        }
      }else{
        return(FALSE)
      }
    }
  } 

}
