use async_trait::async_trait;
use crate::domain::A2AError;
use crate::port::streaming_handler::{SeqEvent, UpdateEvent};
#[async_trait]
pub trait AsyncEventLog: Send + Sync {
async fn append(&self, task_id: &str, event: UpdateEvent) -> Result<SeqEvent, A2AError>;
async fn replay(&self, task_id: &str, from: u64) -> Result<Replay, A2AError>;
async fn discard(&self, task_id: &str) -> Result<(), A2AError>;
}
#[derive(Debug, Clone, Default)]
pub struct Replay {
pub complete: bool,
pub events: Vec<SeqEvent>,
}
impl Replay {
pub fn bounded_by(oldest: Option<u64>, from: u64, events: Vec<SeqEvent>) -> Self {
Self {
complete: oldest.map_or(from == 0, |oldest| oldest <= from + 1),
events,
}
}
}