//! Example: Age Verification Credentials
//!
//! Demonstrates requesting age proof credentials without revealing the user's
//! actual date of birth - only whether they meet the age requirement.
//!
//! # Running
//!
//! ```bash
//! cargo run --example age_verification --features age-proof-policy
//! ```

use lastid_sdk::{AgeProofPolicy, ClientBuilder, LastIDError, PolicyBuilder};

#[tokio::main]
async fn main() -> Result<(), LastIDError> {
    println!("=== Age Verification Examples ===\n");

    // Initialize client (demonstrates configuration, actual requests require IDP)
    let _client = ClientBuilder::new()
        .with_auto_config()
        .map_err(|e| {
            eprintln!("Config error: {e}");
            eprintln!("Create lastid.toml with: idp_endpoint = \"https://human.dev.lastid.co\"");
            e
        })?
        .build()?;

    // Example 1: Age 21+ verification (alcohol, gambling)
    println!("1. Age 21+ Verification (Legal drinking age in US)");
    let policy = AgeProofPolicy::new()
        .at_least(21)
        .with_callback("https://example.com/callback");

    let request = policy.clone().to_request()?;
    println!("   Type: {}", request.credential_type);
    let constraints = request.constraints.unwrap();
    println!("   Comparison: {}", constraints.get("comparison").unwrap());
    println!("   Age: {}", constraints.get("age").unwrap());
    println!("   User's actual DOB is never revealed!\n");

    // Example 2: Age 18+ verification (voting, contracts)
    println!("2. Age 18+ Verification (Legal adult)");
    let policy = AgeProofPolicy::new()
        .at_least(18)
        .with_callback("https://example.com/callback");

    let request = policy.clone().to_request()?;
    let constraints = request.constraints.unwrap();
    println!("   Comparison: atLeast");
    println!("   Age: {}\n", constraints.get("age").unwrap());

    // Example 3: Under 65 verification (working age)
    println!("3. Under 65 Verification");
    let policy = AgeProofPolicy::new()
        .under(65)
        .with_callback("https://example.com/callback");

    let request = policy.clone().to_request()?;
    let constraints = request.constraints.unwrap();
    println!("   Comparison: under");
    println!("   Age: {}\n", constraints.get("age").unwrap());

    // Example 4: Age range verification (18-65)
    println!("4. Age Range Verification (Working age: 18-65)");
    let policy = AgeProofPolicy::new()
        .between(18, 65)
        .with_callback("https://example.com/callback");

    let request = policy.clone().to_request()?;
    let constraints = request.constraints.unwrap();
    println!("   Comparison: between");
    println!("   Min Age: {}", constraints.get("age").unwrap());
    println!("   Max Age: {}\n", constraints.get("maxAge").unwrap());

    // Example 5: Over 13 (COPPA compliance)
    println!("5. Over 13 Verification (COPPA compliance)");
    let policy = AgeProofPolicy::new()
        .over(13)
        .with_callback("https://example.com/callback");

    let request = policy.clone().to_request()?;
    let constraints = request.constraints.unwrap();
    println!("   Comparison: over (strictly greater than)");
    println!(
        "   Age: {} (must be 14+)\n",
        constraints.get("age").unwrap()
    );

    // Demonstrate AgeComparison enum
    println!("=== AgeComparison Options ===");
    println!("  AtLeast  (>=) : \"User is at least X years old\"");
    println!("  Over     (>)  : \"User is over X years old\"");
    println!("  Under    (<)  : \"User is under X years old\"");
    println!("  AtMost   (<=) : \"User is at most X years old\"");
    println!("  Exactly  (==) : \"User is exactly X years old\"");
    println!("  Between       : \"User is between X and Y years old\"");

    println!("\n=== Age Verification Examples Complete ===");
    Ok(())
}
