//! Basic example: Loading configuration from environment variables.
//!
//! Run with:
//! ```bash
//! export MYAPP__PORT=8080
//! export MYAPP__HOST=0.0.0.0
//! export MYAPP__LOG_LEVEL=info
//! cargo run --example basic_env
//! ```

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

#[derive(Debug, Default, Deserialize, Config)]
#[config(prefix = "MYAPP")]
struct AppConfig {
    #[config(default = "8080")]
    port: u16,
    #[config(default = "127.0.0.1")]
    host: String,
    #[config(default = "info")]
    log_level: String,
}

fn main() {
    println!("Basic Environment Configuration Example");
    println!();

    // Load configuration from environment variables
    let config = AppConfig::from_env().expect("Failed to load config");

    println!("Configuration loaded:");
    println!("  Port: {}", config.port);
    println!("  Host: {}", config.host);
    println!("  Log Level: {}", config.log_level);

    // Simulate starting a server
    println!("\nServer would start on {}:{}", config.host, config.port);
    println!("   Log level: {}", config.log_level);
}
