use super::{StateOptions, StateSnapshot, VersionedState};
use crate::error::Result;
use async_trait::async_trait;
use serde::{de::DeserializeOwned, Serialize};
#[async_trait]
pub trait StateManager: Send + Sync {
async fn save<T: Serialize + Send + Sync>(&self, node_id: &str, state: &T) -> Result<()>;
async fn save_with_options<T: Serialize + Send + Sync>(
&self,
node_id: &str,
state: &T,
options: StateOptions,
) -> Result<()>;
async fn load<T: DeserializeOwned + Send + Sync>(&self, node_id: &str) -> Result<Option<T>>;
async fn load_versioned<T: DeserializeOwned + Send + Sync>(
&self,
node_id: &str,
) -> Result<Option<VersionedState<T>>>;
async fn delete(&self, node_id: &str) -> Result<()>;
async fn exists(&self, node_id: &str) -> Result<bool>;
async fn list_nodes(&self) -> Result<Vec<String>>;
async fn size(&self, node_id: &str) -> Result<Option<usize>>;
async fn create_snapshot(&self, node_id: &str, description: Option<String>) -> Result<StateSnapshot>;
async fn restore_snapshot(&self, snapshot_id: &str) -> Result<()>;
async fn list_snapshots(&self, node_id: &str) -> Result<Vec<StateSnapshot>>;
async fn delete_snapshot(&self, snapshot_id: &str) -> Result<()>;
async fn compare_and_swap<T: Serialize + DeserializeOwned + Send + Sync>(
&self,
node_id: &str,
expected: &T,
new: &T,
) -> Result<bool>;
async fn clear_expired(&self) -> Result<usize>;
}