use std::ops::Range;
use std::path::Path;
use async_trait::async_trait;
use bytes::Bytes;
use crate::error::StorageResult;
#[async_trait]
pub trait Storage: Send + Sync + 'static {
async fn put(&self, key: &str, data: Bytes) -> StorageResult<()>;
async fn put_file(&self, key: &str, local: &Path) -> StorageResult<()>;
async fn get(&self, key: &str) -> StorageResult<Bytes>;
async fn get_range(&self, key: &str, range: Range<u64>) -> StorageResult<Bytes>;
async fn size(&self, key: &str) -> StorageResult<u64>;
async fn delete(&self, key: &str) -> StorageResult<()>;
async fn list(&self, prefix: &str) -> StorageResult<Vec<String>>;
async fn exists(&self, key: &str) -> StorageResult<bool> {
match self.size(key).await {
Ok(_) => Ok(true),
Err(crate::StorageError::NotFound(_)) => Ok(false),
Err(e) => Err(e),
}
}
}