# WARNING - Generated by {fusen} from dev/flat_simulate_treatment.Rmd: do not edit by hand # nolint: line_length_linter.

#' Update treatment scheme
#' 
#' Update treatment scheme list in config data frame according to scenario define
#' @param scenario created with function create_scenario
#' @param initial_situation boolean to retrieve simulate treatment train if TRUE or from Barrier train if FALSE
#' @importFrom purrr pmap
#' @return updated_scenario
#' @export
#' @examples
#' scenario_test <- create_scenario(
#'   system.file("input_cas_apprentissage_complet.xlsx", package = "ambre")
#' )
#' scenario_ini <- update_treatment_scheme(scenario_test, initial_situation = TRUE)
#' scenario_supp <- update_treatment_scheme(scenario_test, initial_situation = FALSE)
update_treatment_scheme <- function(scenario, initial_situation = TRUE){
 
  updated_scenario <- scenario
  
  if (initial_situation == TRUE){
    
    updated_scenario$config <- purrr::pmap(
        updated_scenario[c("config", "InitialTrainID", "InitialTrainName")],
        \(config, InitialTrainID, InitialTrainName) {
      
          config$treatment$schemes <- tibble(
            TreatmentSchemeID   = seq_len(length(InitialTrainID)),
            TreatmentSchemeName = InitialTrainName,
            TreatmentName       = InitialTrainName,
            TreatmentID         = InitialTrainID
          )
      
          config
        }
      )
  }
    
  else {
    updated_scenario$config <- purrr::pmap(
        updated_scenario[c("config", "SupplementaryTrainID", "SupplementaryTrainName")],
        \(config, SupplementaryTrainID, SupplementaryTrainName) {
      
          config$treatment$schemes <- tibble(
            TreatmentSchemeID   = seq_len(length(SupplementaryTrainID)),
            TreatmentSchemeName = SupplementaryTrainName,
            TreatmentName       = SupplementaryTrainName,
            TreatmentID         = SupplementaryTrainID
          )
      
          config
        }
      )
    
    
  }
  
  return(updated_scenario)
}
