use herolib_mos::cloud_hypervisor::config::VMConfig;
use herolib_mos::cloud_hypervisor::errors::CloudHypervisorError;
use tempfile::TempDir;

#[tokio::test]
async fn test_api_client_vm_create_mock() {
    let temp_dir = TempDir::new().unwrap();
    let socket_path = temp_dir.path().join("test.sock");
    
    std::fs::write(&socket_path, b"").unwrap();
    
    let config = VMConfig::new()
        .with_kernel("/boot/vmlinux")
        .with_cpus(2)
        .with_memory(1024);
    
    assert!(config.payload.is_some());
    assert!(config.payload.as_ref().unwrap().kernel.is_some());
}

#[tokio::test]
async fn test_vm_lifecycle_mock() {
    let config = VMConfig::new()
        .with_kernel("/boot/vmlinux")
        .with_cpus(2)
        .with_memory(1024);
    
    let spec = config.build().unwrap();
    assert!(!spec.id.is_empty());
}

#[test]
fn test_config_serialization() {
    let config = VMConfig::new()
        .with_kernel("/boot/vmlinux")
        .with_cpus(4)
        .with_memory(2048);
    
    let json = serde_json::to_string(&config).unwrap();
    assert!(json.contains("vmlinux"));
    
    let value: serde_json::Value = serde_json::from_str(&json).unwrap();
    assert_eq!(value["cpus"]["boot_vcpus"], 4);
    assert_eq!(value["memory"]["size"], 2048u64 * 1024 * 1024);
}

#[test]
fn test_error_propagation() {
    let config = VMConfig::new().with_cpus(2).with_memory(1024);
    
    let result = config.build();
    assert!(result.is_err());
    
    match result {
        Err(CloudHypervisorError::Config(_)) => {}
        _ => panic!("Expected Config error"),
    }
}
