use serde::Deserialize;
use config::Config;

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

impl AppConfig {
    pub fn load() -> Result<Self, config::ConfigError> {
        let builder = Config::builder()
            .set_default("server_port", 8005)?
            .set_default("nats_addr", "nats://nats:4222")?
            .set_default("api_gateway_url", "http://api-gateway:4000")?
            .set_default("service_host", "mock-provider-service")?
            .add_source(config::Environment::default());

        builder.build()?.try_deserialize()
    }
}

