use std::future::Future;
use std::pin::Pin;
use futures_core::Stream;
use crate::{
ChannelCapabilities, ChannelError, ChannelHealth, ChannelId, InboundMessage, OutboundMessage,
};
pub type ChannelStream = Pin<Box<dyn Stream<Item = Result<InboundMessage, ChannelError>> + Send>>;
pub type ChannelFuture<'a, T> = Pin<Box<dyn Future<Output = Result<T, ChannelError>> + Send + 'a>>;
#[derive(Clone, Debug, Eq, PartialEq, serde::Serialize, serde::Deserialize)]
pub struct DeliveryReceipt {
pub channel: ChannelId,
pub message_id: String,
pub target: crate::MessageTarget,
pub timestamp_ms: Option<u64>,
}
pub trait ChannelAdapter: Send + Sync {
fn id(&self) -> ChannelId;
fn capabilities(&self) -> ChannelCapabilities;
fn listen(&self) -> Result<ChannelStream, ChannelError>;
fn send(&self, message: OutboundMessage) -> ChannelFuture<'_, DeliveryReceipt>;
fn health(&self) -> ChannelFuture<'_, ChannelHealth> {
Box::pin(async { Ok(ChannelHealth::ready()) })
}
}