use super::config::KEYS;
use toml::Value;
pub(super) fn values(contents: &str, source: &str) -> Result<Vec<String>, String> {
let document: Value =
toml::from_str(contents).map_err(|error| format!("failed to parse {source}: {error}"))?;
let database = document
.get("database")
.ok_or_else(|| format!("{source} has no [database] section"))?;
KEYS.iter()
.map(|key| match database.get(format!("database_{key}")) {
Some(Value::String(value)) => Ok(value.clone()),
Some(Value::Integer(value)) => Ok(value.to_string()),
_ => Err(format!("{source} is missing [database].database_{key}")),
})
.collect()
}