//! Error types for the kvstore crate
use thiserror::Error;

#[derive(Debug, Error)]
pub enum KVError {
    #[error("I/O error: {0}")]
    Io(#[from] std::io::Error),
    #[error("Key not found: {0}")]
    KeyNotFound(String),
    #[error("Store not found: {0}")]
    StoreNotFound(String),
    #[error("Serialization error: {0}")]
    Serialization(String),
    #[error("Deserialization error: {0}")]
    Deserialization(String),
    #[error("Encryption error: {0}")]
    Encryption(String),
    #[error("Decryption error: {0}")]
    Decryption(String),
    #[error("Other error: {0}")]
    Other(String),
}

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

// Allow automatic conversion from idb::Error to KVError
#[cfg(target_arch = "wasm32")]
impl From<idb::Error> for KVError {
    fn from(e: idb::Error) -> Self {
        KVError::Other(format!("idb error: {e:?}"))
    }
}

