/*
    This file is part of jellything (https://codeberg.org/metamuffin/jellything)
    which is licensed under the GNU Affero General Public License (version 3); see /COPYING.
    Copyright (C) 2026 metamuffin <metamuffin.org>
*/

pub mod dummy;
#[cfg(feature = "filesystem")]
pub mod filesystem;
#[cfg(feature = "memory")]
pub mod memory;
#[cfg(feature = "redb")]
pub mod redb;
#[cfg(feature = "rocksdb")]
pub mod rocksdb;

pub use anyhow;

use anyhow::Result;

pub trait Store: Send + Sync + 'static {
    fn transaction(&self, f: &mut dyn FnMut(&mut dyn Transaction) -> Result<()>) -> Result<()>;
}
pub trait Transaction {
    fn set(&mut self, key: &[u8], value: &[u8]) -> Result<()>;
    fn del(&mut self, key: &[u8]) -> Result<()>;
    fn get(&self, key: &[u8]) -> Result<Option<Vec<u8>>>;
    fn iter<'a>(
        &'a self,
        key: &[u8],
        reverse: bool,
    ) -> Result<Box<dyn Iterator<Item = Result<Vec<u8>>> + 'a>>;
}

pub trait BlobStorage: Send + Sync + 'static {
    fn store(&self, key: &str, value: &[u8]) -> Result<()>;
    fn read(&self, key: &str) -> Result<Option<Vec<u8>>>;
}
