use serde::Deserialize;

#[derive(Debug, Deserialize)]
pub struct BuildConfig {
    pub build: BuildMeta,
    #[serde(default)]
    pub plugin: Vec<PluginEntry>,
}

#[derive(Debug, Deserialize)]
pub struct BuildMeta {
    pub output: String,
    #[serde(default = "default_rust_version")]
    pub rust_version: String,
}

fn default_rust_version() -> String {
    "1.85".into()
}

#[derive(Debug, Deserialize)]
pub struct PluginEntry {
    pub crate_name: String,
    pub version: Option<String>,
    pub path: Option<String>,
    pub git: Option<String>,
    #[serde(default)]
    pub config_key: String,
}

pub fn load(path: &str) -> anyhow::Result<BuildConfig> {
    let text = std::fs::read_to_string(path)?;
    Ok(toml::from_str(&text)?)
}
