//! Simple deployment example
//!
//! This example shows how to create a basic deployment with a single container.
//!
//! Run with: cargo run --example simple_deploy

use lmrc_kubernetes::config::DeploymentOptions;
use lmrc_kubernetes::deployment::{ContainerSpec, DeploymentSpec};
use lmrc_kubernetes::{Client, ClientConfig};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Initialize tracing
    tracing_subscriber::fmt::init();

    // Create client using default kubeconfig
    let config = ClientConfig::infer().await?;
    let client = Client::new(config, "default").await?;

    // Create a simple nginx deployment
    let container = ContainerSpec::new("nginx", "nginx:1.21")
        .with_port(80)
        .with_env("NGINX_HOST", "example.com");

    let deployment = DeploymentSpec::new("simple-nginx")
        .with_replicas(2)
        .with_container(container);

    // Apply the deployment
    let options = DeploymentOptions::new().timeout_secs(180).wait(true);

    println!("Deploying nginx...");
    client.deployments().apply(&deployment, &options).await?;

    // Get status
    let status = client.deployments().status("simple-nginx").await?;
    println!(
        "Deployment ready: {}/{} replicas",
        status.ready_replicas, status.replicas
    );

    Ok(())
}
