args = commandArgs(trailingOnly=TRUE)

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

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")

# 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)

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

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

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