//! Reactive configuration example (requires `reactive` feature).
//!
//! Run with:
//! ```bash
//! cargo run --example reactive --features reactive
//! ```

#[cfg(feature = "reactive")]
use cfgmatic::{
    Config, ConfigLoader,
    reactive::{FieldQuery, PathQuery},
};
#[cfg(feature = "reactive")]
use serde::Deserialize;

#[cfg(feature = "reactive")]
#[derive(Debug, Clone, Default, Deserialize, Config)]
#[config(prefix = "MYAPP")]
struct AppConfig {
    #[config(default = "8080")]
    port: u16,
    #[config(default = "localhost")]
    host: String,
}

#[cfg(feature = "reactive")]
#[tokio::main]
async fn main() {
    println!("Reactive Configuration Example");
    println!();

    // Load initial config
    let config = AppConfig::from_env().expect("Failed to load config");
    println!("Initial config: {config:?}");

    // This example demonstrates the reactive API structure.
    // In a real application, you would:
    // 1. Create a ConfigManager with file watching enabled
    // 2. Subscribe to specific fields
    // 3. React to changes

    println!("\nReactive API available:");
    println!("  - FieldQuery: Watch specific fields");
    println!("  - PathQuery: Watch JSON pointer paths");
    println!("  - ConfigStream: Receive change notifications");

    // Example: Create a field query
    let _port_query = FieldQuery::new(|c: &AppConfig| &c.port);
    println!("\nCreated FieldQuery for port");

    // Example: Create a path query
    let _path_query = PathQuery::new("/server/port");
    println!("Created PathQuery for /server/port");

    println!("\nNote: Full reactive functionality requires ConfigManager with watching enabled.");
    println!("See REACTIVE_ARCHITECTURE.md for more details.");
}

#[cfg(not(feature = "reactive"))]
fn main() {
    println!("Reactive Configuration Example");
    println!();
    println!("This example requires the 'reactive' feature.");
    println!();
    println!("Run with:");
    println!("  cargo run --example reactive --features reactive");
    println!();
    println!("Available reactive features:");
    println!("  - FieldQuery: Subscribe to specific field changes");
    println!("  - PathQuery: Subscribe to JSON pointer paths");
    println!("  - ConfigStream: Stream of configuration changes");
}
