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

test_that("create_scenario_from_df returns a data.frame", {
  df <- data.frame(
    CropName = "Tomato", Area = 35,
    PopulationName = "Maintenance staff", nb_population = 1,
    PathName = "Consumption of the final product tomato",
    nb_day_decay = NA_real_
  )
  df$STEPtreatmentName <- list("Q.1 - Activated Sludge")
  df$CollectiveTreatmentName <- list(NA_character_)
  df$InitialProcessName <- list("Q.6 - Chlorination")
  df$SupplementaryProcessName <- list(NA_character_)

  expect_true(is.data.frame(create_scenario_from_df(df)))
})

test_that("create_scenario_from_df builds a multi-process initial train", {
  df <- data.frame(
    CropName = "Tomato", Area = 35,
    PopulationName = "Maintenance staff", nb_population = 1,
    PathName = "Consumption of the final product tomato",
    nb_day_decay = NA_real_
  )
  df$STEPtreatmentName <- list(c("Q.1 - Activated Sludge", "Q.2 - Maturation Pond"))
  df$CollectiveTreatmentName <- list(NA_character_)
  df$InitialProcessName <- list("Q.6 - Chlorination")
  df$SupplementaryProcessName <- list(NA_character_)

  scenario <- create_scenario_from_df(df)

  # Roles are concatenated (order kept, NAs dropped); names and IDs stay aligned.
  expect_identical(
    scenario$InitialTrainName[[1]],
    c("Q.1 - Activated Sludge", "Q.2 - Maturation Pond", "Q.6 - Chlorination")
  )
  expect_identical(scenario$InitialTrainID[[1]], c(1, 2, 6))
})

test_that("create_scenario_from_df stop conditions work", {
  base <- data.frame(
    CropName = "Tomato", PopulationName = "Maintenance staff",
    PathName = "Consumption of the final product tomato", nb_day_decay = NA_real_
  )

  expect_error(create_scenario_from_df(123), "user_input must be a data.frame")
  expect_error(
    create_scenario_from_df(cbind(base, Area = "x", nb_population = 1)),
    "Area must be a numeric value"
  )
  expect_error(
    create_scenario_from_df(cbind(base, Area = 0, nb_population = 1)),
    "Area must be strictly greater"
  )
})
