use std::collections::HashMap;
use uni_comfyui_sdk::{UniComfyUIClient, Result, ServerRegistrationRequest};

// Note: These tests require a running ComfyUI service
// They are disabled by default and should be run manually when needed

#[tokio::test]
#[ignore]
async fn test_client_creation() -> Result<()> {
    let _client = UniComfyUIClient::new("http://192.168.0.148:18000")?;
    assert!(true); // Just test that client creation doesn't panic
    Ok(())
}

#[tokio::test]
#[ignore]
async fn test_get_metrics() -> Result<()> {
    let client = UniComfyUIClient::new("http://192.168.0.148:18000")?;
    let _metrics = client.get_metrics().await?;
    // Just test that the call doesn't fail
    Ok(())
}

#[tokio::test]
#[ignore]
async fn test_get_all_workflows() -> Result<()> {
    let client = UniComfyUIClient::new("http://192.168.0.148:18000")?;
    let workflows = client.get_all_workflows().await?;
    assert!(workflows.is_empty() || !workflows.is_empty()); // Just test the call
    Ok(())
}

#[tokio::test]
#[ignore]
async fn test_health_check() -> Result<()> {
    let client = UniComfyUIClient::new("http://192.168.0.148:18000")?;
    let _health = client.health_check().await?;
    Ok(())
}

#[tokio::test]
#[ignore]
async fn test_server_registration() -> Result<()> {
    let client = UniComfyUIClient::new("http://192.168.0.148:18000")?;
    
    let registration_request = ServerRegistrationRequest {
        name: "test-server".to_string(),
        http_url: "http://192.168.0.148:8188".to_string(),
        ws_url: "ws://192.168.0.148:8188".to_string(),
    };

    // This might fail if server already exists, which is fine for testing
    let _result = client.register_server(registration_request).await;
    Ok(())
}

#[tokio::test]
#[ignore]
async fn test_workflow_execution() -> Result<()> {
    let client = UniComfyUIClient::new("http://192.168.0.148:18000")?;

    let mut workflow_data = HashMap::new();
    workflow_data.insert("test_input".to_string(), serde_json::json!("test_value"));

    // This will likely fail without a real workflow, but tests the API call
    let _result = client
        .run_workflow("test_workflow", None, workflow_data)
        .await;

    Ok(())
}

#[test]
fn test_url_building() {
    let _client = UniComfyUIClient::new("http://192.168.0.148:18000").unwrap();
    // Test that URL building works correctly
    assert!(true); // Basic test that client creation works
}

#[test]
fn test_error_types() {
    use uni_comfyui_sdk::ComfyUIError;
    
    // Test that error types can be created
    let _error = ComfyUIError::Validation("test error".to_string());
    let _error = ComfyUIError::ServerNotFound("test server".to_string());
    let _error = ComfyUIError::WorkflowNotFound("test workflow".to_string());
    
    assert!(true);
}
