args = commandArgs(trailingOnly=TRUE)

dirPath   <- "/var/www/lbc-file/r/v1"
#filesPath <- "Teste/"
#inpFile   <- "Inputs-Teste.xlsx"
filesPath <- "Cedro/"
inpFile   <- "Inputs-Cedro.xlsx"
#filesPath <- c(args[1])
#inpFile   <- c(args[2])

# rm(list=ls())
setwd(dirPath)
source("Libraries.R")
source("RunGEE.R")
source("SoilCTransitionMatrix.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), logger = logger)

#printAll(allInp)

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

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

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

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