args = commandArgs(trailingOnly=TRUE)

dirPath   <- c(args[3]) #"/var/www/lbc-file/r/v2"

fileMatrix <- "TransitionMatrix.xlsx"

#filesPath <- "Teste/"
#inpFile   <- "Inputs-Teste.xlsx"
# filesPath <- "Bravinhos/"
# inpFile   <- "Inputs-Bravinhos.xlsx"
filesPath <- c(args[1])
inpFile   <- c(args[2])

# rm(list=ls())
setwd(dirPath)
source("Libraries.R")
source("RunGEE.R")

#mtxList <- list.files(path = filesPath, pattern = "TransitionMatrix")

# setting up logger
suppressWarnings(file.remove(paste0(filesPath, inpFile, "-logfile.log")))
logger <- create.logger(paste0(filesPath, inpFile, "-logfile.log"), level = "INFO")

# Loading input's category and diet data
allInp <- readInput(filepath = paste0(filesPath, inpFile), mtxpath = fileMatrix, logger = logger)

#printAll(allInp)

allOut <- runGEE(allInp = allInp, logger = logger)

#allOut <- soilTransition(path = filesPath, fileList = mtxList, logger = logger, resList = GEE)

# Writing output file
writeDF(filepath = paste0(filesPath, "Outputs-", inpFile), resList = allOut, logger = logger)

info(logger, "The code ran successfully.")
