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

#[tokio::main]
async fn main() -> anyhow::Result<()> {
    let args: Vec<String> = std::env::args().collect();
    if args.len() < 4 {
        eprintln!("usage: detect <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();

    let st = ExecService::detect_system_type(&tool, cfg.clone()).await?;
    println!("system type: {:?}", st);

    let profile = ExecService::detect_system(&tool, cfg).await?;
    println!("os_id:           {:?}", profile.os_id);
    println!("os_version:      {:?}", profile.os_version);
    println!("arch:            {:?}", profile.arch);
    println!("package_manager: {:?}", profile.package_manager);
    println!("shell:           {:?}", profile.shell);

    match st {
        SystemType::Linux => println!("\n→ Linux detected"),
        SystemType::MacOs => println!("\n→ macOS detected"),
        SystemType::Windows => println!("\n→ Windows detected"),
        SystemType::Unknown => println!("\n→ unknown OS"),
    }

    Ok(())
}
