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

#' Get risk total
#' 
#' Calcul the total illness probability and total dalys that are the sum of every exposure event
#' @param scenario data.frame with risk column
#' @importFrom dplyr group_by summarise n
#' @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"))
#'
#' 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)
#'
#' scenario_inf_proba_and_co <- infection_probability_calculation(scenario_final_dose_and_co_test)
#'
#' scenario_illness_proba_and_co <- illness_probability_calculation(scenario_inf_proba_and_co)
#'
#' scenario_dalys_and_co <- dalys_calculation(scenario_illness_proba_and_co)
#'
#' get_risk_total(scenario_dalys_and_co)
get_risk_total <- function(scenario){
  total_risk <- map(.x = scenario$risk, ~.x |> 
    group_by(repeatID, 
            PathogenID, 
            PathogenName.x, 
            PathogenGroup) |> 
    summarise(events = dplyr::n(), 
            inflow_median = median(inflow), 
            effluent_median = median(effluent), 
            logreduction_median = median(logreduction), 
            volume_sum = sum(volume_perEvent), 
            dose_sum = sum(dose_perEvent), 
            infectionProb_sum = 1 - prod(1 - proba_inf), 
            illnessProb_sum = 1 - prod(1 - illnessProb_per_event), 
            dalys_sum = sum(dalys_per_event)))

  scenario_updated <- scenario |> mutate(risk_total = total_risk)
  
  return(scenario_updated)
    
}
