//! Error types for VAPORA doc-lifecycle adapter

use std::fmt;

/// Result type for adapter operations
pub type Result<T> = std::result::Result<T, Error>;

/// Error type for adapter operations
#[derive(Debug)]
pub enum Error {
    /// Core library error
    Core(doc_lifecycle_core::Error),
    /// Configuration error
    Config(String),
    /// NATS error
    NatsError(String),
    /// Database error
    DatabaseError(String),
    /// Other errors
    Other(Box<dyn std::error::Error + Send + Sync>),
}

impl fmt::Display for Error {
    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
        match self {
            Self::Core(e) => write!(f, "Core error: {}", e),
            Self::Config(msg) => write!(f, "Config error: {}", msg),
            Self::NatsError(msg) => write!(f, "NATS error: {}", msg),
            Self::DatabaseError(msg) => write!(f, "Database error: {}", msg),
            Self::Other(e) => write!(f, "{}", e),
        }
    }
}

impl std::error::Error for Error {}

impl From<doc_lifecycle_core::Error> for Error {
    fn from(err: doc_lifecycle_core::Error) -> Self {
        Self::Core(err)
    }
}

impl From<std::io::Error> for Error {
    fn from(err: std::io::Error) -> Self {
        Self::Other(Box::new(err))
    }
}
