use crate::error::Result;
use crate::iroh::channel::Channel;
use did_ma::Message;
#[derive(Debug)]
pub struct Outbox {
inner: OutboxTransport,
did: String,
protocol: String,
}
#[derive(Debug)]
enum OutboxTransport {
Channel(Channel),
}
impl Outbox {
pub(crate) fn from_channel(channel: Channel, did: String, protocol: String) -> Self {
Self {
inner: OutboxTransport::Channel(channel),
did,
protocol,
}
}
pub async fn send(&mut self, message: &Message) -> Result<()> {
message.headers().validate()?;
let cbor = message.to_cbor()?;
match &mut self.inner {
OutboxTransport::Channel(channel) => channel.send(&cbor).await,
}
}
pub fn did(&self) -> &str {
&self.did
}
pub fn protocol(&self) -> &str {
&self.protocol
}
pub fn close(self) {
match self.inner {
OutboxTransport::Channel(channel) => channel.close(),
}
}
}