## TODO: Use get_dir() to unify
add_logo <- function(recipe, logo) {
  # recipe: SUNSET recipe
  # logo: URL to the logo
  system <- gsub('.','', recipe$Analysis$Datasets$System$name, fixed = T)
  reference <- gsub('.','', recipe$Analysis$Datasets$Reference$name, fixed = T)
  calibration <- recipe$Analysis$Workflow$Calibration$method
  variable <- recipe$Analysis$Variable$name
  files <- lapply(variable, function(x) {
                  f <- list.files(paste0(recipe$Run$output_dir, "/plots/",
                                         system, "/", reference, "/", calibration, "/", x))
                  full_path <- paste0(recipe$Run$output_dir, "/plots/",
                                      system,"/", reference, "/", calibration, "/", x,"/", f)})[[1]]
  dim(files) <- c(file = length(files))
  Apply(list(files), target_dims = NULL, function(x) {
        system(paste("composite -gravity southeast -geometry +10+10",
                     logo, x, x))}, ncores = recipe$Analysis$ncores)
  
}

add_logo_scorecards <- function(recipe, logo) {
  # recipe: SUNSET recipe
  # logo: URL to the logo
  scorecards_f <- list.files(paste0(recipe$Run$output_dir, "/plots/Scorecards/"))
  scorecards <- paste0(recipe$Run$output_dir, "/plots/Scorecards/", scorecards_f)
  dim(scorecards) <- c(file = length(scorecards))
    Apply(list(scorecards), target_dims = NULL, function(x) {
  
    system(paste('convert ',x, ' -gravity north -background white -splice 0x15 ', x))
      
    system(paste("composite -gravity northeast -geometry +15+15",
                 logo, x, x))}, ncores = recipe$Analysis$ncores)
    
}
