use sshr::ssh::{AuthMethod, ExecRequest, ExecService, RusshTool, SshConfig};

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let args: Vec<String> = std::env::args().collect();
    if args.len() < 4 {
        eprintln!("usage: exec <host> <user> <password>");
        std::process::exit(1);
    }

    let cfg = SshConfig::new(
        &args[1],
        &args[2],
        AuthMethod::Password {
            password: args[3].clone(),
        },
    );
    let tool = RusshTool::new();

    // Validate connection
    ExecService::validate(&tool, cfg.clone()).await?;
    println!("✓ connected");

    // Execute command
    let result = tool.exec(cfg.clone(), ExecRequest::new("uname -a")).await?;
    println!("exit_code: {}", result.exit_code);
    println!("stdout: {}", result.stdout_string());

    // With timeout and environment variables
    let result = tool
        .exec(
            cfg,
            ExecRequest {
                command: "echo $GREETING".to_string(),
                env: vec![("GREETING".to_string(), "hello from sshr".to_string())],
                timeout_ms: Some(5000),
                use_shell: true,
                ..Default::default()
            },
        )
        .await?;
    println!("stdout: {}", result.stdout_string());

    Ok(())
}
