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

#' Infection probability calculation
#' 
#' Simulate infection probability for each events
#' @param scenario data.frame with columns inflow concentration, final dose and volume
#' @importFrom purrr map
#' @importFrom dplyr mutate
#' @return scenario_updated
#' 
#' @export
#' @examples
#'
#' library(dplyr)
#' library(purrr)
#' scenario_test <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre"))
#'
#' scenario_conc <- inflow_concentration(scenario = scenario_test,
#'  pathogenName = c("Campylobacter jejuni", "Escherichia coli"))
#'
#' scenario_volume <-
#'   scenario_conc |>                     
#'   mutate(
#'     volume = map(
#'       .x = config,                                         
#'       .f = ~ simulate_exposure(config = .x)              
#'     )
#'   )
#'
#' scenario_dose_ini <- initial_dose_calculation(scenario_volume)
#'
#' scenario_scheme <- update_treatment_scheme(scenario_dose_ini)
#'
#' scenario_with_logreduc_and_co <- scenario_scheme |> 
#'   mutate( log_reduction = map(config, simulate_treatment))
#'
#' scenario_final_dose_and_co_test <- final_dose_calculation(scenario_with_logreduc_and_co)
#'
#' infection_probability_calculation(scenario_final_dose_and_co_test)
#'
infection_probability_calculation <- function(scenario){
  tbl_risk <- get_tbl_risk(scenario)

  infection_proba <- map(tbl_risk, ~get_infection_prob(.x, dose_response = config_ambre$doseresponse, health = config_ambre$health))
  tbl_risk <- map2(tbl_risk, infection_proba, ~ mutate(.x, proba_inf = .y))
  
  scenario_updated <- scenario |> 
    mutate(risk = tbl_risk)
  
  return(scenario_updated)
    
}
