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

test_that("retrieve_specific_barrier applies a vector of barriers cumulatively", {
  scenario <- create_scenario(system.file("input_1culture_2pop.xlsx", package = "ambre"))
  scenario_conc <- inflow_concentration(scenario = scenario, pathogenName = "Campylobacter jejuni")
  scenario_vol <- scenario_conc |>
    dplyr::mutate(volume = purrr::map(config, ~ simulate_exposure(config = .x)))
  scenario_ttt <- update_treatment_scheme(
    scenario = initial_dose_calculation(scenario_vol),
    initial_situation = TRUE
  )

  cfg <- scenario_ttt$config[[1]]
  ch <- scenario_ttt$CropHeight[[1]]
  matrix_id <- scenario_ttt$MatrixID[[1]]
  pop_id <- scenario_ttt$PopulationID[[1]]
  decay <- scenario_ttt$nb_day_decay[[1]]

  # A vector of barrier ids == applying each one after the other (cumulative).
  expect_identical(
    retrieve_specific_barrier(cfg, c(9, 13), ch, matrix_id, pop_id, decay),
    retrieve_specific_barrier(
      retrieve_specific_barrier(cfg, 9, ch, matrix_id, pop_id, decay),
      13, ch, matrix_id, pop_id, decay
    )
  )
  # An empty role (NA) matches no branch and leaves the config unchanged.
  expect_identical(retrieve_specific_barrier(cfg, NA, ch, matrix_id, pop_id, decay), cfg)
})
