/// Example: Basic Entity Management  
use lattice::prelude::*;
use chrono::Utc;
use std::env;

#[tokio::main]
async fn main() -> Result<(), ApiError> {
    let client = ApiClientBuilder::new(
        &env::var("LATTICE_BASE_URL").unwrap_or("https://api.lattice.example.com".into())
    )
    .api_key(&env::var("LATTICE_API_KEY").unwrap_or("your-key".into()))
    .build()?;

    println!("=== Entity Management ===\n");

    // Create entity with minimal required fields
    let entity = Entity {
        entity_id: Some("example-001".into()),
        is_live: Some(true),
        provenance: Some(Provenance {
            source_update_time: Some(Utc::now()),
            source_id: Some("rust-example".into()),
            integration_name: Some("Example".into()),
            data_type: None,
            source_description: None,
        }),
        description: Some("Example entity".into()),
        location: Some(Location {
            position: Some(Position {
                latitude_degrees: Some(37.7749),
                longitude_degrees: Some(-122.4194),
                altitude_hae_meters: Some(1000.0),
                altitude_agl_meters: None,
                altitude_asf_meters: None,
                pressure_depth_meters: None,
            }),
            velocity_enu: None,
            speed_mps: None,
            acceleration: None,
            attitude_enu: None,
        }),
        // All other fields None
        created_time: None,
        expiry_time: None,
        no_expiry: None,
        status: None,
        location_uncertainty: None,
        geo_shape: None,
        geo_details: None,
        aliases: None,
        tracked: None,
        correlation: None,
        mil_view: None,
        ontology: None,
        sensors: None,
        payloads: None,
        power_state: None,
        overrides: None,
        indicators: None,
        target_priority: None,
        signal: None,
        transponder_codes: None,
        data_classification: None,
        task_catalog: None,
        media: None,
        relationships: None,
        visual_details: None,
        dimensions: None,
        route_details: None,
        schedules: None,
        health: None,
        group_details: None,
        supplies: None,
        orbit: None,
    };

    match client.entities.publish_entity(&entity, None).await {
        Ok(_) => println!("✓ Entity published!"),
        Err(e) => println!("✗ Error: {:?}", e),
    }

    Ok(())
}
