use async_trait::async_trait;
use chrono::{DateTime, Utc};
use futures::stream::BoxStream;
use serde::{Deserialize, Serialize};
use crate::error::Result;
use crate::model::{AnamnesisRecord, SourceDescriptor};
#[derive(Debug, Clone, Default)]
pub struct ScanOpts {
pub since: Option<DateTime<Utc>>,
pub full: bool,
}
#[derive(Debug, Clone, Default)]
pub struct WatchOpts {
pub poll_interval: Option<std::time::Duration>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct RawRecord {
pub native_id: String,
pub native_path: Option<String>,
pub payload: serde_json::Value,
pub captured_at: DateTime<Utc>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub enum RawDelta {
Upsert(RawRecord),
Delete {
native_id: String,
},
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HealthStatus {
pub ok: bool,
pub detail: String,
}
#[async_trait]
pub trait MemoryAdapter: Send + Sync {
fn descriptor(&self) -> SourceDescriptor;
fn scan<'a>(&'a self, opts: ScanOpts) -> BoxStream<'a, Result<RawRecord>>;
fn watch<'a>(&'a self, _opts: WatchOpts) -> Option<BoxStream<'a, Result<RawDelta>>> {
None
}
fn normalize(&self, raw: RawRecord) -> Result<Vec<AnamnesisRecord>>;
async fn health(&self) -> HealthStatus;
}