use async_trait::async_trait;
use axum::body::Bytes;
use futures_core::Stream;
use std::{fmt::Debug, pin::Pin};
use tokio::io::AsyncRead;
use crate::prelude::*;
#[derive(Clone, Default)]
pub struct CreateBlobOptions {}
pub struct BlobStat {
pub size: u64,
}
#[async_trait]
pub trait BlobAdapter: Debug + Send + Sync {
async fn create_blob_buf(
&self,
tn_id: TnId,
file_id: &str,
data: &[u8],
opts: &CreateBlobOptions,
) -> ClResult<()>;
async fn create_blob_stream(
&self,
tn_id: TnId,
file_id: &str,
stream: &mut (dyn AsyncRead + Send + Unpin),
) -> ClResult<()>;
async fn stat_blob(&self, tn_id: TnId, blob_id: &str) -> Option<u64>;
async fn read_blob_buf(&self, tn_id: TnId, blob_id: &str) -> ClResult<Box<[u8]>>;
async fn read_blob_range(
&self,
tn_id: TnId,
blob_id: &str,
offset: u64,
length: u64,
) -> ClResult<Box<[u8]>>;
async fn read_blob_stream(
&self,
tn_id: TnId,
blob_id: &str,
) -> ClResult<Pin<Box<dyn Stream<Item = Result<Bytes, std::io::Error>> + Send>>>;
async fn create_blob_from_path(
&self,
tn_id: TnId,
file_id: &str,
source: &std::path::Path,
opts: &CreateBlobOptions,
) -> ClResult<()>;
async fn delete_tenant_blobs(&self, tn_id: TnId) -> ClResult<()>;
}