use serde::Deserialize;

#[derive(Debug, Deserialize, Clone)]
pub struct AppConfig {
    pub server_port: u16,
    pub nats_addr: String,
    pub data_persistence_service_url: String,
    pub workflow_data_path: String,
}

#[allow(dead_code)]
fn default_workflow_data_path() -> String {
    "/app/data".to_string()
}

impl AppConfig {
    pub fn load() -> Result<Self, config::ConfigError> {
        let config = config::Config::builder()
            .add_source(
                config::Environment::default()
                    .separator("__")
                    .ignore_empty(true),
            )
            .build()?;

        config.try_deserialize()
    }
}
