use async_trait::async_trait;
use schema_core::{GenericValue, IndexMapping, IndexName};
use crate::Result;
#[derive(Debug, Clone, Default)]
pub struct FlushReport {
pub rejected: Vec<RejectedDocument>,
}
impl FlushReport {
pub fn clean() -> Self {
Self::default()
}
pub fn is_clean(&self) -> bool {
self.rejected.is_empty()
}
}
#[derive(Debug, Clone)]
pub struct RejectedDocument {
pub index: String,
pub id: String,
pub reason: String,
}
#[async_trait]
pub trait Sink: std::fmt::Debug + Send + Sync {
async fn ensure_index(&self, _mapping: &IndexMapping) -> Result<()> {
Ok(())
}
async fn upsert(&self, index: &IndexName, id: &str, document: &GenericValue) -> Result<()>;
async fn delete(&self, index: &IndexName, id: &str) -> Result<()>;
async fn flush(&self, caught_up: bool) -> Result<FlushReport>;
async fn is_seeded(&self, _: &IndexName) -> Result<bool> {
Ok(false)
}
async fn mark_seeded(&self, _: &IndexName) -> Result<()> {
Ok(())
}
async fn reindex(&self, _: &IndexMapping) -> Result<()> {
Ok(())
}
}