//! RAG Pipeline error types

use thiserror::Error;

/// Errors that can occur in the RAG pipeline.
#[derive(Debug, Error)]
pub enum RagError {
    /// Embedding / perception failed
    #[error("Embedding error: {0}")]
    Embedding(String),

    /// Retrieval (search) failed
    #[error("Retrieval error: {0}")]
    Retrieval(String),

    /// Context assembly failed
    #[error("Context assembly error: {0}")]
    ContextAssembly(String),

    /// Generation (LLM) failed
    #[error("Generation error: {0}")]
    Generation(String),

    /// Session management error
    #[error("Session error: {0}")]
    Session(String),

    /// Configuration error
    #[error("Configuration error: {0}")]
    Config(String),

    /// Reranking error
    #[error("Reranking error: {0}")]
    Rerank(String),

    /// Pipeline not initialized
    #[error("Pipeline not initialized: {0}")]
    NotInitialized(String),
}

/// Result type alias for RAG operations.
pub type RagResult<T> = Result<T, RagError>;

// ── Conversions from other error types ────────────────────────────

impl From<crate::perception::PerceptionError> for RagError {
    fn from(e: crate::perception::PerceptionError) -> Self {
        RagError::Embedding(e.to_string())
    }
}

impl From<crate::perception::ReasoningError> for RagError {
    fn from(e: crate::perception::ReasoningError) -> Self {
        RagError::Generation(e.to_string())
    }
}

impl From<crate::query::reranker::RerankError> for RagError {
    fn from(e: crate::query::reranker::RerankError) -> Self {
        RagError::Rerank(e.to_string())
    }
}
