use lmrc_ssh::{AuthMethod, SshClient};

fn main() -> Result<(), lmrc_ssh::Error> {
    println!("SSH Manager - Batch Commands Example\n");

    // Get configuration from environment variables
    let host = std::env::var("SSH_HOST").unwrap_or_else(|_| "example.com".to_string());
    let username = std::env::var("SSH_USER").unwrap_or_else(|_| "user".to_string());
    let password = std::env::var("SSH_PASSWORD").unwrap_or_else(|_| "password".to_string());

    println!("Connecting to {}@{}", username, host);

    let mut client = SshClient::new(host, 22)?
        .with_auth(AuthMethod::Password { username, password })
        .connect()?;

    println!("✓ Connected successfully!\n");

    // Define a batch of commands to execute
    let commands = vec!["whoami", "hostname", "pwd", "date", "uptime", "df -h /"];

    println!("Executing {} commands in batch...\n", commands.len());

    // Execute all commands
    let outputs = client.execute_batch(&commands)?;

    // Display results
    for (cmd, output) in commands.iter().zip(outputs.iter()) {
        println!("┌─ Command: {}", cmd);
        println!("│  Exit Code: {}", output.exit_status);

        if output.is_success() {
            println!("│  Output:");
            for line in output.stdout.lines() {
                println!("│    {}", line);
            }
        } else {
            println!("│  Error:");
            for line in output.stderr.lines() {
                println!("│    {}", line);
            }
        }

        println!("└─");
        println!();
    }

    println!("✓ All commands executed successfully!");

    Ok(())
}
