use std::ops::Range;
use std::path::Path;
use async_trait::async_trait;
use crate::{OwnedBytes, PutPayload, StorageErrorKind, StorageResult};
#[cfg_attr(any(test, feature = "testsuite"), mockall::automock)]
#[async_trait]
pub trait Storage: Send + Sync + 'static {
async fn check(&self) -> anyhow::Result<()>;
async fn put(&self, path: &Path, payload: Box<dyn PutPayload>) -> StorageResult<()>;
async fn copy_to_file(&self, path: &Path, output_path: &Path) -> StorageResult<()>;
async fn get_slice(&self, path: &Path, range: Range<usize>) -> StorageResult<OwnedBytes>;
async fn get_all(&self, path: &Path) -> StorageResult<OwnedBytes>;
async fn delete(&self, path: &Path) -> StorageResult<()>;
async fn exists(&self, path: &Path) -> StorageResult<bool> {
match self.file_num_bytes(path).await {
Ok(_) => Ok(true),
Err(storage_err) if storage_err.kind() == StorageErrorKind::DoesNotExist => Ok(false),
Err(other_storage_err) => Err(other_storage_err),
}
}
async fn file_num_bytes(&self, path: &Path) -> StorageResult<u64>;
fn uri(&self) -> String;
}