use config::Config;
use serde::Deserialize;
use std::path::Path;

#[derive(Debug, Deserialize)]
pub struct FrenApiConfig {
    pub api_addr: String,
    pub api_key: String,
}

#[derive(Debug, Deserialize)]
pub struct OnDeckConfig {
    pub fren_api: FrenApiConfig,
}

impl OnDeckConfig {
    pub fn new(src: &Path) -> Result<Self, config::ConfigError> {
        let cfg = Config::builder()
            .add_source(config::File::from(src))
            .build()?;

        cfg.try_deserialize()
    }
}
