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

#' Get infection probability values
#' 
#' Simulate infection probability according to pathogen consider
#' @param tbl_risk data.frame containing PathogenID and dose_perEvent columns
#' @param dose_response data.frame database of dose_response factors presents in config_ambre
#' @param health data.frame database of health factors presents in config_ambre
#' @return result_vector
#' @references Sonnenberg H (2024). kwb.utils: General Utility Functions Developed at KWB. R package version 0.15.0
#'   URL: \url{https://github.com/kwb-r/kwb.utils}
#'   (MIT Licence)
#' @export
get_infection_prob <- function(tbl_risk, dose_response, health)
{
  result_vector <- rep(NA_real_, nrow(tbl_risk))
  
  for (pathogenID in unique(tbl_risk$PathogenID)) {
    
    condition <- tbl_risk$PathogenID == pathogenID
    
    this_pathogen <- dose_response$PathogenID == pathogenID
    
    values <- get_dose_response_values(
      dose = tbl_risk$dose_perEvent[condition], 
      k = dose_response$k[this_pathogen], 
      n50 = dose_response$N50[this_pathogen],
      alpha = dose_response$alpha[this_pathogen],
      pathogen_name = health$PathogenName[health$PathogenID == pathogenID]
    )

    result_vector[condition] <- values$infectionProbability
  }
  
  return(result_vector)
}
