//! Database error types.

use thiserror::Error;

/// Database errors.
#[derive(Debug, Error)]
pub enum DatabaseError {
    #[error("Database already exists: {0}")]
    AlreadyExists(String),

    #[error("Database not found: {0}")]
    NotFound(String),

    #[error("Collection not found: {0}")]
    CollectionNotFound(String),

    #[error("Document not found: {0}")]
    DocumentNotFound(String),

    #[error("Key not found: {0}")]
    KeyNotFound(String),

    #[error("Index not found: {0}")]
    IndexNotFound(String),

    #[error("Schema validation failed: {0}")]
    SchemaValidation(String),

    #[error("Query error: {0}")]
    QueryError(String),

    #[error("Vector dimension mismatch: expected {expected}, got {got}")]
    DimensionMismatch { expected: u32, got: u32 },

    #[error("Storage error: {0}")]
    StorageError(String),

    #[error("Serialization error: {0}")]
    SerializationError(String),

    #[error("Capacity exceeded: {0}")]
    CapacityExceeded(String),

    #[error("TTL expired")]
    TtlExpired,

    #[error("Invalid operation: {0}")]
    InvalidOperation(String),

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

impl From<serde_json::Error> for DatabaseError {
    fn from(err: serde_json::Error) -> Self {
        DatabaseError::SerializationError(err.to_string())
    }
}

impl From<std::io::Error> for DatabaseError {
    fn from(err: std::io::Error) -> Self {
        DatabaseError::StorageError(err.to_string())
    }
}
