use std::collections::HashMap;
use std::future::Future;
use bytes::Bytes;
use exoware_sdk::prune_policy::PrunePolicyDocument;
pub type QueryExtra = HashMap<String, buffa_types::google::protobuf::Value>;
#[derive(Clone, Debug, Default)]
pub struct RangeScanBatch {
pub rows: Vec<(Bytes, Bytes)>,
pub extra: QueryExtra,
}
pub trait RangeScan: Send {
fn next_batch(
&mut self,
max_items: usize,
) -> impl Future<Output = Result<RangeScanBatch, String>> + Send;
}
pub trait Sequence: Send + Sync + 'static {
fn current_sequence(&self) -> u64;
}
pub trait Ingest: Send + Sync + 'static {
fn put_batch(
&self,
kvs: Vec<(Bytes, Bytes)>,
) -> impl Future<Output = Result<u64, String>> + Send;
}
pub trait Query: Sequence {
type RangeScan: RangeScan + 'static;
fn get(
&self,
key: Bytes,
) -> impl Future<Output = Result<(Option<Bytes>, QueryExtra), String>> + Send;
fn range_scan(
&self,
start: Bytes,
end: Bytes,
limit: usize,
forward: bool,
) -> impl Future<Output = Result<Self::RangeScan, String>> + Send;
fn get_many(
&self,
keys: Vec<Bytes>,
) -> impl Future<Output = Result<(Vec<(Bytes, Option<Bytes>)>, QueryExtra), String>> + Send;
}
pub trait Prune: Send + Sync + 'static {
fn apply_prune_policies(
&self,
document: PrunePolicyDocument,
) -> impl Future<Output = Result<(), String>> + Send;
}
pub trait Log: Sequence {
fn get_batch(
&self,
sequence_number: u64,
) -> impl Future<Output = Result<Option<Vec<(Bytes, Bytes)>>, String>> + Send;
fn oldest_retained_batch(&self) -> impl Future<Output = Result<Option<u64>, String>> + Send;
}
pub trait StoreEngine: Ingest + Query + Prune + Log {}
impl<T: Ingest + Query + Prune + Log> StoreEngine for T {}