// Legacy alias: ai -> aibot
// This provides backward compatibility for existing scripts

use std::env;
use std::path::PathBuf;
use std::process::{Command, exit};

fn main() {
    let args: Vec<String> = env::args().collect();
    
    // Skip the first argument (program name) and pass the rest to aibot
    let aibot_args: Vec<&str> = args.iter().skip(1).map(|s| s.as_str()).collect();
    
    // Try to find aibot binary in the same directory as this binary
    let current_exe = env::current_exe().unwrap_or_else(|_| PathBuf::from("ai"));
    let mut aibot_path = current_exe.parent().unwrap_or(&PathBuf::from(".")).to_path_buf();
    aibot_path.push("aibot");
    
    // First try relative path, then try PATH
    let mut cmd = if aibot_path.exists() {
        Command::new(&aibot_path)
    } else {
        Command::new("aibot")
    };
    
    cmd.args(&aibot_args);
    
    match cmd.status() {
        Ok(status) => {
            exit(status.code().unwrap_or(1));
        }
        Err(e) => {
            eprintln!("Error executing aibot: {}", e);
            eprintln!("Make sure 'aibot' is installed and available in PATH");
            eprintln!("Attempted path: {:?}", aibot_path);
            exit(1);
        }
    }
}