use async_trait::async_trait;
use crate::error::{NotifyError, SourceError, StateError};
use crate::model::Event;
#[async_trait]
pub trait StateStore: Send + Sync {
async fn get_snapshot(
&self,
source_id: &str,
scope: &str,
) -> Result<Option<Vec<u8>>, StateError>;
async fn put_snapshot(
&self,
source_id: &str,
scope: &str,
bytes: &[u8],
) -> Result<(), StateError>;
async fn was_delivered(&self, dedup_key: &str) -> Result<bool, StateError>;
async fn mark_delivered(&self, dedup_key: &str) -> Result<(), StateError>;
async fn get_cursor(&self, source_id: &str, key: &str) -> Result<Option<String>, StateError>;
async fn put_cursor(&self, source_id: &str, key: &str, value: &str) -> Result<(), StateError>;
}
#[async_trait]
pub trait Source: Send + Sync {
fn id(&self) -> &str;
async fn poll(&self, state: &dyn StateStore) -> Result<Vec<Event>, SourceError>;
async fn commit(&self, _state: &dyn StateStore, _event: &Event) -> Result<(), SourceError> {
Ok(())
}
}
#[async_trait]
pub trait Notifier: Send + Sync {
fn id(&self) -> &str;
async fn send(&self, event: &Event) -> Result<(), NotifyError>;
}