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

#' Volume update
#' 
#' Update the configuration with min and max volumes to be simulated according to path ID
#' @param scenario dataframe scenario obtained with function create_scenario
#' @importFrom dplyr mutate
#' @importFrom purrr map2 map
#' @return scenario_updated list configuration updated with the min and max volumes to be simulated
#' 
#' @export
#' @examples
#' scenario_example <- create_scenario(
#'   system.file("input_1culture_2pop.xlsx", package = "ambre")
#' )
#' scenario_updated <- update_volume(scenario_example)
#' scenario_updated$config[[1]]$exposure
update_volume <- function(scenario) {
  
  new_volume <- map(.x = scenario$PathID, .f = ~ query_volume(.x))   # $min et $max

  scenario_updated <- scenario |>
    mutate(
      config = map2(
        .x = config,
        .y = new_volume,
        .f = ~{
          .x$exposure$min[[3]] <- .y$min
          .x                          
        }
      )
    ) |>
    mutate(
      config = map2(
        .x = config,
        .y = new_volume,
        .f = ~{
          .x$exposure$max[[3]] <- .y$max
          .x
        }
      )
    )
  return(scenario_updated)
}
