use crate::{DBBatch, Key, MassaDBError, StreamBatch, Value};
use massa_hash::{HashXof, HASH_XOF_SIZE_BYTES};
use massa_models::{error::ModelsError, slot::Slot, streaming_step::StreamingStep};
use parking_lot::RwLock;
use std::path::PathBuf;
use std::{fmt::Debug, sync::Arc};
#[cfg(feature = "test-exports")]
use std::collections::BTreeMap;
pub type ShareableMassaDBController = Arc<RwLock<Box<dyn MassaDBController>>>;
pub trait MassaDBController: Send + Sync + Debug {
fn backup_db(&self, slot: Slot) -> PathBuf;
fn get_change_id(&self) -> Result<Slot, ModelsError>;
fn set_initial_change_id(&self, change_id: Slot);
fn write_batch(&mut self, batch: DBBatch, versioning_batch: DBBatch, change_id: Option<Slot>);
fn put_or_update_entry_value(&self, batch: &mut DBBatch, key: Vec<u8>, value: &[u8]);
fn delete_key(&self, batch: &mut DBBatch, key: Vec<u8>);
fn delete_prefix(&mut self, prefix: &str, handle_str: &str, change_id: Option<Slot>);
fn reset(&mut self, slot: Slot);
fn get_cf(&self, handle_cf: &str, key: Key) -> Result<Option<Value>, MassaDBError>;
fn multi_get_cf(&self, query: Vec<(&str, Key)>) -> Vec<Result<Option<Value>, MassaDBError>>;
fn iterator_cf(
&self,
handle_cf: &str,
mode: MassaIteratorMode,
) -> Box<dyn Iterator<Item = (Key, Value)> + '_>;
fn prefix_iterator_cf(
&self,
handle_cf: &str,
prefix: &[u8],
) -> Box<dyn Iterator<Item = (Key, Value)> + '_>;
fn get_xof_db_hash(&self) -> HashXof<HASH_XOF_SIZE_BYTES>;
fn flush(&self) -> Result<(), MassaDBError>;
fn write_batch_bootstrap_client(
&mut self,
stream_changes: StreamBatch<Slot>,
stream_changes_versioning: StreamBatch<Slot>,
) -> Result<(StreamingStep<Key>, StreamingStep<Key>), MassaDBError>;
fn get_batch_to_stream(
&self,
last_state_step: &StreamingStep<Vec<u8>>,
last_change_id: Option<Slot>,
) -> Result<StreamBatch<Slot>, MassaDBError>;
fn get_versioning_batch_to_stream(
&self,
last_versioning_step: &StreamingStep<Vec<u8>>,
last_change_id: Option<Slot>,
) -> Result<StreamBatch<Slot>, MassaDBError>;
#[cfg(feature = "test-exports")]
fn get_entire_database(&self) -> Vec<BTreeMap<Vec<u8>, Vec<u8>>>;
}
pub enum MassaIteratorMode<'a> {
Start,
End,
From(&'a [u8], MassaDirection),
}
pub enum MassaDirection {
Forward,
Reverse,
}