use crate::model::event::Event;
use crate::model::update::UpdateItem;
use async_trait::async_trait;
use futures_util::stream::Stream;
use futures_util::Sink;

#[derive(Debug, Eq, PartialEq, Clone)]
pub enum SinkMessage {
    Ping,
}

pub enum SocketUpdate {
    Update(Vec<UpdateItem>),
    Pong,
}

pub enum SocketEvent {
    Update(Event),
    Pong,
}

#[async_trait]
pub trait EventSocket {
    type Error;
    type EventStream: Stream<Item = Result<SocketEvent, Self::Error>>;
    type UpdateStream: Stream<Item = Result<SocketUpdate, Self::Error>>;

    /// Modern event pipeline
    async fn events(
        self,
    ) -> (
        Self::EventStream,
        impl Sink<SinkMessage, Error = Self::Error>,
    );

    /// Raw update items from the v1 API.
    async fn raw_updates(self) -> Self::UpdateStream;
}
