//! Dev command handler
//!
//! Orchestrates development mode with hot reload using DevSession service.
//! This handler follows the 3-layer architecture with session-based lifecycle management:
//! - Commands: Pure data structures (DevArgs)
//! - Handlers: Minimal orchestration (this file)
//! - Services: Session and business logic (DevSession, DevService, etc.)

// Submodules
pub mod command_listener;
pub mod ops;
pub mod session;

use crate::commands::dev::DevArgs;
use crate::context::CliContext;
use anyhow::Result;

use session::DevSession;

/// Handle dev command
///
/// Starts development mode with automatic rebuilding and hot reload.
///
/// # Architecture
///
/// This handler uses a session-based approach:
/// 1. DevSession - Manages entire dev lifecycle
/// 2. DevService - Core business logic
/// 3. Services - Infrastructure (Docker, Redis, Process, etc.)
/// 4. UI components - Display functions
///
/// The handler is now ultra-thin - it simply creates a DevSession
/// and executes it. All complexity is encapsulated in the session service.
///
/// # Arguments
///
/// * `ctx` - CLI execution context
/// * `args` - Dev command arguments
pub async fn handle_dev(ctx: &mut CliContext, args: &DevArgs) -> Result<()> {
    // Initialize dev session (loads config, validates, selects nodes)
    let session = DevSession::initialize(ctx, args).await?;

    // Execute complete lifecycle (setup → build → spawn → run)
    session.execute(ctx).await?;

    Ok(())
}
