use crate::error::Result;
use serde::{Serialize, de::DeserializeOwned};
pub use async_trait::async_trait;
#[async_trait]
pub trait AuthProvider: Send + Sync {
type User: DeserializeOwned + Send;
type Session: DeserializeOwned + Send;
async fn sign_up_with_email(&self, email: &str, password: &str) -> Result<Self::Session>;
async fn sign_in_with_email(&self, email: &str, password: &str) -> Result<Self::Session>;
async fn sign_out(&self) -> Result<()>;
async fn get_session(&self) -> Result<Option<Self::Session>>;
async fn get_user(&self) -> Result<Option<Self::User>>;
async fn refresh_session(&self) -> Result<Self::Session>;
}
#[async_trait]
pub trait StorageProvider: Send + Sync {
async fn upload(
&self,
bucket: &str,
path: &str,
data: Vec<u8>,
content_type: Option<&str>,
) -> Result<String>;
async fn download(&self, bucket: &str, path: &str) -> Result<Vec<u8>>;
async fn remove(&self, bucket: &str, paths: &[&str]) -> Result<()>;
async fn list(&self, bucket: &str, path: Option<&str>) -> Result<Vec<StorageObject>>;
fn get_public_url(&self, bucket: &str, path: &str) -> String;
async fn create_signed_url(&self, bucket: &str, path: &str, expires_in: u64) -> Result<String>;
}
#[derive(Debug, Clone, serde::Deserialize, serde::Serialize)]
pub struct StorageObject {
pub name: String,
pub id: Option<String>,
pub updated_at: Option<String>,
pub created_at: Option<String>,
pub last_accessed_at: Option<String>,
pub metadata: Option<serde_json::Value>,
}
#[async_trait]
pub trait FunctionsProvider: Send + Sync {
async fn invoke<T, R>(&self, function_name: &str, body: Option<T>) -> Result<R>
where
T: Serialize + Send + Sync,
R: DeserializeOwned;
async fn invoke_raw<T>(&self, function_name: &str, body: Option<T>) -> Result<Vec<u8>>
where
T: Serialize + Send + Sync;
}