use thiserror::Error;

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

/// Errors returned by the persistent provider. Kept narrow on purpose — the SDK error
/// type widens these to `Error::Storage(_)` at the [`ping_core`] boundary.
#[derive(Debug, Error)]
#[non_exhaustive]
pub enum Error {
    /// Underlying I/O failure (SQLite, file system, IndexedDB).
    #[error("storage I/O: {0}")]
    Io(String),

    /// CBOR encode/decode failure on the persisted MLS-state blob.
    #[error("codec: {0}")]
    Codec(String),

    /// Schema migration failed — typically because the on-disk file was produced by a
    /// newer SDK build with an unknown `user_version`.
    #[error("unsupported schema version: {0}")]
    UnsupportedSchema(i64),

    /// Encryption key supplied but the underlying store rejected it (wrong key on an
    /// existing SQLCipher file, or the cipher prelude doesn't match).
    #[error("encryption key mismatch — wrong key or non-encrypted file")]
    EncryptionKeyMismatch,
}
