//! Basic container creation and management example

use lmrc_docker::{DockerClient, Result};

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

    // Check connectivity
    client.ping().await?;
    println!("✓ Connected to Docker daemon");

    // Pull an image
    println!("\nPulling nginx:alpine image...");
    client.images().pull("nginx:alpine", None).await?;
    println!("✓ Image pulled successfully");

    // Create and start a container
    println!("\nCreating container...");
    let container = client
        .containers()
        .create("nginx:alpine")
        .name("my-nginx")
        .port(8080, 80, "tcp")
        .env("ENV", "development")
        .build()
        .await?;

    println!("✓ Container created: {}", container.id());

    // Start the container
    container.start().await?;
    println!("✓ Container started");

    // Inspect the container
    let info = container.inspect().await?;
    println!("\nContainer info:");
    println!("  Name: {:?}", info.name);
    println!("  Status: {:?}", info.state.and_then(|s| s.status));

    // Stop the container
    println!("\nStopping container...");
    container.stop(Some(10)).await?;
    println!("✓ Container stopped");

    // Remove the container
    container.remove(false, false).await?;
    println!("✓ Container removed");

    Ok(())
}
