// RLM Error Types
// Follows VaporaError pattern from vapora-shared

use thiserror::Error;

/// Main error type for RLM operations
#[derive(Error, Debug)]
pub enum RLMError {
    /// Storage operation error
    #[error("Storage error: {0}")]
    StorageError(String),

    /// Chunking operation error
    #[error("Chunking error: {0}")]
    ChunkingError(String),

    /// Search operation error
    #[error("Search error: {0}")]
    SearchError(String),

    /// Sandbox execution error
    #[error("Sandbox error: {0}")]
    SandboxError(String),

    /// LLM dispatch error
    #[error("Dispatch error: {0}")]
    DispatchError(String),

    /// Provider communication error
    #[error("Provider error: {0}")]
    ProviderError(String),

    /// Invalid input or validation error
    #[error("Invalid input: {0}")]
    InvalidInput(String),

    /// Database operation error
    #[error("Database error: {0}")]
    DatabaseError(#[from] Box<surrealdb::Error>),

    /// Serialization/deserialization error
    #[error("Serialization error: {0}")]
    SerializationError(#[from] serde_json::Error),

    /// IO operation error
    #[error("IO error: {0}")]
    IoError(#[from] std::io::Error),

    /// Internal error
    #[error("Internal error: {0}")]
    InternalError(String),
}

/// Result type alias using RLMError
pub type Result<T> = std::result::Result<T, RLMError>;

/// Convert from anyhow::Error
impl From<anyhow::Error> for RLMError {
    fn from(err: anyhow::Error) -> Self {
        RLMError::InternalError(err.to_string())
    }
}
