#'@title Import Luminescence Data into R
#'
#'@description
#'Convenience wrapper function to provide a quicker and more standardised way of
#'reading data into R by looping through all in the package available data import
#'functions starting with `read_`. Import data types can be mixed.
#'
#'@param file [character] (**required**): file to be imported, can be a [list] or a [character] vector
#'
#'@param ... arguments to be further passed down to supported functions (please check the functions
#'to determine the correct arguments)
#'
#'@param fastForward [logical] (*with default*): option to create [Luminescence::RLum-class] objects
#'during import or a [list] of such objects
#'
#' @param verbose [logical] (*with default*): enable/disable output to the
#' terminal.
#'
#' @section Function version: 0.1.6
#'
#'@author Sebastian Kreutzer, F2.1 Geophysical Parametrisation/Regionalisation, LIAG - Institute for Applied Geophysics (Germany)
#'
#'@returns Always returns a [list]; empty or filled with [Luminescence::RLum.Analysis-class] objects
#'
#' @seealso `r toString(paste0("[Luminescence::", sort(grep("^read_", getNamespaceExports("Luminescence"), value = TRUE)), "]"))`
#'
#'@keywords datagen
#'
#'@examples
#'
#' ## import BINX/BIN
#' file <- system.file("extdata/BINfile_V8.binx", package = "Luminescence")
#' temp <- import_Data(file)
#'
#' ## RF data
#' file <- system.file("extdata", "RF_file.rf", package = "Luminescence")
#' temp <- import_Data(file)
#'
#'@export
import_Data <- function(
  file,
  ...,
  fastForward = TRUE,
  verbose = FALSE
) {
  .set_function_name("import_Data")
  on.exit(.unset_function_name(), add = TRUE)

  .validate_class(file, c("character", "list"))

  ## supported functions are extracted automatically from the package
  ## namespace so that we don't have to maintain this list manually
  fun <- grep("^read_", getNamespaceExports("Luminescence"), value = TRUE)

  ## put the most common formats first, the rest alphabetically
  fun <- unique(c("read_BIN2R", "read_XSYG2R", sort(fun)))

  ## make the file handling just a little bit easier
  if(length(file) > 1)
    file <- as.list(file)

  ## get arguments of functions
  args <- c(list(file = file, fastForward = fastForward, verbose = verbose), list(...))

  ## set empty output list
  out <- list()

  ## just try all functions and all files
  for (i in fun) {
    SW({
      ## get arguments and remove non-supported arguments
      t <- try(do.call(what = i, args = args), silent = TRUE)
    })

      if (!is.null(t) && !inherits(t, "try-error"))
        out <- c(out, t)
  }

  ## return if output is not empty
  if (length(out) == 0)
   .throw_message("Unknown file format, nothing imported")

  return(out)
}
