//! Error types for Cloud Hypervisor operations.

use std::error::Error;
use std::fmt;

/// Error type for Cloud Hypervisor operations.
#[derive(Debug)]
pub enum CloudHvError {
    /// Command execution failed.
    CommandFailed(String),
    /// I/O operation failed.
    IoError(String),
    /// JSON parsing or serialization failed.
    JsonError(String),
    /// Required dependency is missing.
    DependencyMissing(String),
    /// Invalid VM specification.
    InvalidSpec(String),
    /// Resource not found.
    NotFound(String),
}

impl fmt::Display for CloudHvError {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            CloudHvError::CommandFailed(e) => write!(f, "{}", e),
            CloudHvError::IoError(e) => write!(f, "IO error: {}", e),
            CloudHvError::JsonError(e) => write!(f, "JSON error: {}", e),
            CloudHvError::DependencyMissing(e) => write!(f, "Dependency missing: {}", e),
            CloudHvError::InvalidSpec(e) => write!(f, "Invalid spec: {}", e),
            CloudHvError::NotFound(e) => write!(f, "{}", e),
        }
    }
}

impl Error for CloudHvError {}
