//! List Docker resources example

use lmrc_docker::{DockerClient, Result};

#[tokio::main]
async fn main() -> Result<()> {
    let client = DockerClient::new()?;

    // List all containers
    println!("=== Containers ===");
    let containers = client.containers().list(true).await?;
    for container in containers {
        let id = container.id.unwrap_or_default();
        let id_short = if id.len() >= 12 { &id[..12] } else { &id };
        let state = container
            .state
            .map(|s| format!("{:?}", s))
            .unwrap_or_else(|| "unknown".to_string());
        println!("  {} - {:?} ({})", id_short, container.names, state);
    }

    // List all images
    println!("\n=== Images ===");
    let images = client.images().list(false).await?;
    for image in images {
        println!("  {} - {:?}", &image.id[..12], image.repo_tags);
    }

    // List all networks
    println!("\n=== Networks ===");
    let networks = client.networks().list().await?;
    for network in networks {
        let id = network.id.unwrap_or_default();
        let id_short = if id.len() >= 12 { &id[..12] } else { &id };
        println!("  {} - {}", id_short, network.name.unwrap_or_default());
    }

    // List all volumes
    println!("\n=== Volumes ===");
    let volumes = client.volumes().list().await?;
    for volume in volumes {
        println!("  {}", volume.name);
    }

    Ok(())
}
