//! Nested configuration example with NPM-style environment variables.
//!
//! NOTE: Full nested struct support with `#[config(nested)]` is planned.
//! This example demonstrates flat configuration with prefixed fields.
//!
//! Run with:
//! ```bash
//! export MYAPP__SERVER__PORT=3000
//! export MYAPP__SERVER__HOST=0.0.0.0
//! export MYAPP__DATABASE__URL=postgres://localhost/mydb
//! export MYAPP__DATABASE__POOL_SIZE=20
//! cargo run --example nested_config
//! ```

use cfgmatic::{Config, ConfigLoader};
use serde::Deserialize;

#[derive(Debug, Default, Deserialize, Config)]
#[config(prefix = "MYAPP")]
struct AppConfig {
    // Server settings
    #[config(default = "8080")]
    server_port: u16,
    #[config(default = "127.0.0.1")]
    server_host: String,
    #[config(default = "false")]
    server_tls: bool,

    // Database settings
    #[config(default = "postgres://localhost/postgres")]
    database_url: String,
    #[config(default = "10")]
    database_pool_size: u32,
    #[config(default = "30")]
    database_timeout_seconds: u64,
}

fn main() {
    println!("Nested Configuration Example");
    println!();
    println!("Environment variables expected:");
    println!("  MYAPP__SERVER__PORT=3000");
    println!("  MYAPP__SERVER__HOST=0.0.0.0");
    println!("  MYAPP__DATABASE__URL=postgres://localhost/mydb");
    println!();

    let config = AppConfig::from_env().expect("Failed to load config");

    println!("Loaded configuration:");
    println!("  Server:");
    println!("    Port: {}", config.server_port);
    println!("    Host: {}", config.server_host);
    println!("    TLS: {}", config.server_tls);
    println!();
    println!("  Database:");
    println!("    URL: {}", config.database_url);
    println!("    Pool Size: {}", config.database_pool_size);
    println!("    Timeout: {}s", config.database_timeout_seconds);
}
