use crate::Result;
use crate::checkpoint::Checkpoint;
use crate::event::{Op, Relation, SourceEvent};
use crate::lsn::Lsn;
use std::future::Future;
use std::sync::Arc;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct Feedback {
pub written: Lsn,
pub flushed: Lsn,
pub applied: Lsn,
pub reply_requested: bool,
}
pub trait EventStream: Send {
fn next_event(&mut self) -> impl Future<Output = Result<SourceEvent>> + Send;
fn send_feedback(&mut self, fb: Feedback) -> impl Future<Output = Result<()>> + Send;
}
pub trait StreamFactory: Send {
type Stream: EventStream;
fn connect(
&mut self,
cp: &Checkpoint,
) -> impl Future<Output = Result<(Self::Stream, Lsn)>> + Send;
}
pub trait ReplicationSink: Send {
fn load_checkpoint(
&mut self,
job_id: &str,
) -> impl Future<Output = Result<Option<Checkpoint>>> + Send;
fn save_checkpoint(&mut self, cp: &Checkpoint) -> impl Future<Output = Result<()>> + Send;
fn begin(&mut self) -> impl Future<Output = Result<()>> + Send;
fn relation(&mut self, rel: Arc<Relation>) -> impl Future<Output = Result<()>> + Send;
fn apply(&mut self, op: Op) -> impl Future<Output = Result<()>> + Send;
fn commit(&mut self, cp: &Checkpoint) -> impl Future<Output = Result<()>> + Send;
fn rollback(&mut self) -> impl Future<Output = Result<()>> + Send;
}
pub trait SinkFactory: Send {
type Sink: ReplicationSink;
fn connect(&mut self) -> impl Future<Output = Result<Self::Sink>> + Send;
}