use async_trait::async_trait;
use crate::error::Result;
use crate::types::{ServiceDefinition, WebhookMethodMeta};
#[async_trait]
pub trait ServiceCaller: Send + Sync {
async fn call(&self, edge_id: &str, service: &str, method: &str, req: &[u8])
-> Result<Vec<u8>>;
async fn subscribe(
&self,
edge_id: &str,
service: &str,
method: &str,
req: &[u8],
handler: Box<dyn for<'a> Fn(&'a [u8]) -> Result<()> + Send + Sync>,
) -> Result<Box<dyn Subscription>>;
}
pub trait Subscription: Send + Sync {
fn unsubscribe(&self) -> Result<()>;
}
#[async_trait]
pub trait ServiceHandler: Send + Sync {
fn definition(&self) -> ServiceDefinition;
async fn handle_request(&self, method: &str, req_data: &[u8]) -> Result<Vec<u8>>;
async fn handle_stream(
&self,
method: &str,
req_data: &[u8],
emit: Box<dyn Fn(Vec<u8>) -> Result<()> + Send + Sync>,
) -> Result<()>;
fn webhook_methods(&self) -> Vec<WebhookMethodMeta> {
Vec::new()
}
}