use super::{Command, Event, Storable};
use crate::commons::eventsourcing::WithStorableDetails;
pub trait Aggregate: Storable + Send + Sync + 'static {
type Command: Command<StorableDetails = Self::StorableCommandDetails>;
type StorableCommandDetails: WithStorableDetails;
type Event: Event;
type InitEvent: Event;
type Error: std::error::Error + Send + Sync;
fn init(event: Self::InitEvent) -> Result<Self, Self::Error>;
fn version(&self) -> u64;
fn apply(&mut self, event: Self::Event);
fn apply_all(&mut self, events: Vec<Self::Event>) {
for event in events {
self.apply(event);
}
}
fn process_command(&self, command: Self::Command) -> Result<Vec<Self::Event>, Self::Error>;
}