use async_trait::async_trait;
use crate::error::Result;
use crate::inbox::Inbox;
use did_ma::Message;
pub const DEFAULT_INBOX_CAPACITY: usize = 256;
pub const DEFAULT_DELIVERY_PROTOCOL_ID: &str = "/ma/inbox/0.0.1";
#[async_trait]
pub trait MaEndpoint: Send + Sync {
fn id(&self) -> String;
fn service(&mut self, protocol: &str) -> Inbox<Message>;
fn services(&self) -> Vec<String>;
fn services_json(&self) -> serde_json::Value {
serde_json::Value::Array(
self.services()
.into_iter()
.map(serde_json::Value::String)
.collect(),
)
}
async fn send_to(&self, target: &str, protocol: &str, message: &Message) -> Result<()>;
async fn send(&self, target: &str, message: &Message) -> Result<()> {
self.send_to(target, DEFAULT_DELIVERY_PROTOCOL_ID, message)
.await
}
}