use std::{fmt::Debug, future::Future};
use anyhow::Result;
use futures::Stream;
use crate::{
types::{ExactLink, NamespaceId, NamespaceSecretKey, SubspaceId, SubspaceSecretKey},
Digest,
};
#[cfg(feature = "backend_iroh")]
pub mod iroh;
pub trait KeyResolverImpl<KeyId> {
fn id(&self) -> KeyId;
fn resolve(&self, data: &[u8]) -> KeyId;
}
pub trait EncryptionAlgorithmImpl<Digest> {
fn id(&self) -> Digest;
fn encrypt(&self, key_id: [u8; 32], data: &[u8]) -> Vec<u8>;
fn decrypt(&self, key_id: [u8; 32], data: &[u8]) -> Vec<u8>;
}
pub trait LeafStore: Debug {
fn key_resolvers(&self) -> Box<dyn Iterator<Item = &dyn KeyResolverImpl<Digest>> + '_>;
fn encryption_algorithms(
&self,
) -> Box<dyn Iterator<Item = &dyn EncryptionAlgorithmImpl<Digest>> + '_>;
fn create_subspace(&self) -> impl Future<Output = Result<SubspaceId>>;
fn get_subspace_secret(
&self,
subspace: SubspaceId,
) -> impl Future<Output = Result<Option<SubspaceSecretKey>>>;
fn list_subspaces(
&self,
) -> impl Future<Output = Result<impl Stream<Item = anyhow::Result<SubspaceId>>>>;
fn import_subspace_secret(
&self,
subspace_secret: SubspaceSecretKey,
) -> impl Future<Output = Result<SubspaceId>>;
fn create_namespace(&self) -> impl Future<Output = Result<NamespaceId>>;
fn list_namespaces(
&self,
) -> impl Future<Output = Result<impl Stream<Item = anyhow::Result<NamespaceId>>>>;
fn get_namespace_secret(
&self,
namespace: NamespaceId,
) -> impl Future<Output = Result<Option<NamespaceSecretKey>>>;
fn import_namespace_secret(
&self,
secret: [u8; 32],
) -> impl Future<Output = Result<NamespaceId>>;
fn store_blob(
&self,
data: &[u8],
link: &ExactLink,
entity_snapshot_id: Digest,
) -> impl Future<Output = Result<Digest>>;
fn del_blobs(
&self,
link: &ExactLink,
entity_snapshot_id: Digest,
) -> impl Future<Output = Result<usize>>;
fn get_blob(&self, digest: Digest) -> impl Future<Output = Result<Vec<u8>>>;
fn store_entity(&self, link: &ExactLink, data: Vec<u8>)
-> impl Future<Output = Result<Digest>>;
fn del_entity(&self, link: &ExactLink) -> impl Future<Output = Result<()>>;
fn get_entity(&self, link: &ExactLink) -> impl Future<Output = Result<Option<Digest>>>;
fn list(
&self,
link: ExactLink,
limit: Option<u64>,
offset: Option<u64>,
) -> impl Future<Output = Result<impl Stream<Item = anyhow::Result<ExactLink>>>>;
}