use async_trait::async_trait;
use crate::types::{AnalyticsQuery, ConversationManifest, SegmentHash, StoredSegment};
#[derive(Debug, thiserror::Error)]
pub enum StorageError {
#[error("segment not found: {0}")]
SegmentNotFound(String),
#[error("conversation not found: {0}")]
ConversationNotFound(String),
#[error("backend error: {0}")]
BackendError(String),
#[error("serialization error: {0}")]
SerializationError(String),
#[error("IO error: {0}")]
IoError(#[from] std::io::Error),
}
pub type StorageResult<T> = Result<T, StorageError>;
#[async_trait]
pub trait StorageBackend: Send + Sync {
async fn put_segment(&self, segment: &StoredSegment) -> StorageResult<()>;
async fn get_segment(&self, hash: &SegmentHash) -> StorageResult<StoredSegment>;
async fn has_segment(&self, hash: &SegmentHash) -> StorageResult<bool>;
async fn increment_ref(&self, hash: &SegmentHash) -> StorageResult<()>;
async fn replace_segment_data(
&self,
hash: &SegmentHash,
new_data: Vec<u8>,
) -> StorageResult<()>;
async fn decrement_ref(&self, hash: &SegmentHash) -> StorageResult<bool>;
async fn delete_segment(&self, hash: &SegmentHash) -> StorageResult<()>;
async fn put_manifest(&self, manifest: &ConversationManifest) -> StorageResult<()>;
async fn get_manifest(&self, id: &str) -> StorageResult<ConversationManifest>;
async fn delete_manifest(&self, id: &str) -> StorageResult<()>;
async fn list_conversations(
&self,
query: &AnalyticsQuery,
limit: u64,
offset: u64,
) -> StorageResult<Vec<String>>;
async fn list_garbage(&self) -> StorageResult<Vec<SegmentHash>> {
Ok(Vec::new())
}
async fn garbage_collect(&self) -> StorageResult<u64>;
async fn storage_size_bytes(&self) -> StorageResult<u64>;
}