/// Example: Object Storage
use lattice::prelude::*;
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!("=== Object Storage ===\n");

    // Upload
    println!("1. Uploading...");
    match client.objects.upload_object(
        &"examples/test.txt".into(),
        &b"Hello SDK!".to_vec(),
        None
    ).await {
        Ok(m) => println!("✓ Uploaded: {}", m.content_identifier.path),
        Err(e) => println!("✗ Error: {:?}", e),
    }

    // List
    println!("\n2. Listing...");
    let req = ListObjectsQueryRequest {
        prefix: Some("examples/".into()),
        since_timestamp: None,
        page_token: None,
        all_objects_in_mesh: None,
    };

    match client.objects.list_objects(&req, None).await {
        Ok(r) => println!("✓ Found {} object(s)", r.path_metadatas.len()),
        Err(e) => println!("✗ Error: {:?}", e),
    }

    println!("\n=== Completed ===");
    Ok(())
}
