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

#' Updated frequency with desired value
#' 
#' Update the value of the frequency in the simulated configuration according to a value defined by the user
#' @param scenario data.frame
#' @param frequency numeric, list of max frequency to simulate
#' @importFrom purrr map2
#' @importFrom dplyr mutate
#' @return scenario_updated
#' 
#' @export
#' @examples
#' scenario_example <- create_scenario(
#'   system.file("input_1culture_2pop.xlsx", package = "ambre")
#' )
#' scenario_example_updated <- update_frequency_with_desired_value(scenario = scenario_example, 
#'                                                                 frequency = c(2L,3L))
#' print(scenario_example_updated$config[[1]]$exposure)
#' print(scenario_example_updated$config[[2]]$exposure)
update_frequency_with_desired_value <- function(scenario, frequency){
  if (length(frequency) != length(scenario$config)){
    stop("A frequency value is required for all lines in the scenario")
  }
  
  if (!is.integer(frequency)) {
  stop("'frequency' must be an integer vector (e.g. c(1L, 2L, 3L)).")
}

  scenario_updated <- scenario |>
    mutate(
      config = map2(
        .x = config,
        .y = frequency,
        .f = ~{
          .x$exposure$value[[2]] <- .y  
          .x                          
        }
      )
    )
  return(scenario_updated)
}
