use reqwest::Client;
use std::env;

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Set environment variables
    env::set_var("QDRANT_URL", "http://localhost:6333");
    env::set_var("QDRANT_API_KEY", "Test3200Test3200Test3200");
    env::set_var("QDRANT_COLLECTION", "momentry_rule1");

    let base_url = env::var("QDRANT_URL").unwrap_or_else(|_| "http://localhost:6333".to_string());
    let api_key =
        env::var("QDRANT_API_KEY").unwrap_or_else(|_| "Test3200Test3200Test3200".to_string());
    let collection_name =
        env::var("QDRANT_COLLECTION").unwrap_or_else(|_| "momentry_rule1".to_string());

    println!("Testing Qdrant connection...");
    println!("Base URL: {}", base_url);
    println!("API Key: {}", api_key);
    println!("Collection: {}", collection_name);

    let client = Client::new();
    let url = format!("{}/collections/{}", base_url, collection_name);

    match client.get(&url).header("api-key", &api_key).send().await {
        Ok(response) => {
            if response.status().is_success() {
                println!("✅ Qdrant connection successful!");
                let body = response.text().await?;
                println!("Response: {}", body);
            } else {
                println!(
                    "❌ Qdrant connection failed with status: {}",
                    response.status()
                );
                println!("Response: {:?}", response.text().await);
            }
        }
        Err(e) => {
            println!("❌ Qdrant connection error: {}", e);
        }
    }

    Ok(())
}
