use thiserror::Error;

#[derive(Debug, Error)]
pub enum MonaVecError {
    #[error("dimension mismatch: expected {expected}, got {got}")]
    DimMismatch { expected: usize, got: usize },

    #[error("invalid bit width: {0} (must be 2 or 4)")]
    InvalidBitWidth(u8),

    #[error("invalid metric byte: {0}")]
    InvalidMetric(u8),

    #[error("index is empty")]
    EmptyIndex,

    #[error("id/vector count mismatch: {ids} ids vs {vectors} vectors")]
    CountMismatch { ids: usize, vectors: usize },

    #[error("io error: {0}")]
    Io(#[from] std::io::Error),

    #[error("invalid .mvec file: {0}")]
    InvalidFormat(String),

    #[error("unsupported file version: {0}")]
    UnsupportedVersion(u32),

    #[error("unsupported index type byte: {0}")]
    UnsupportedIndexType(u8),

    #[error("index type '{0}' is not yet implemented — use IndexType::BruteForce")]
    IndexTypeNotImplemented(&'static str),

    #[error("call build() before search() for IvfFlat indexes")]
    BuildRequired,

    #[error("sample is empty — provide at least 1 vector for profiling")]
    EmptySample,

    #[error("fit() must be called before add() — index already contains vectors")]
    FitAfterAdd,
}

pub type Result<T> = std::result::Result<T, MonaVecError>;
