use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
use uuid::Uuid;
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub struct OutboxRecord {
pub id: Uuid,
pub event_type: String,
pub aggregate_type: String,
pub aggregate_id: String,
pub company_id: Uuid,
pub payload: serde_json::Value,
pub occurred_at: DateTime<Utc>,
pub correlation_id: Option<String>,
pub causation_id: Option<String>,
pub version: i32,
}
impl OutboxRecord {
pub fn new(
event_type: impl Into<String>,
aggregate_type: impl Into<String>,
aggregate_id: impl Into<String>,
company_id: Uuid,
payload: serde_json::Value,
occurred_at: DateTime<Utc>,
) -> Self {
Self {
id: Uuid::new_v4(),
event_type: event_type.into(),
aggregate_type: aggregate_type.into(),
aggregate_id: aggregate_id.into(),
company_id,
payload,
occurred_at,
correlation_id: None,
causation_id: None,
version: 1,
}
}
pub fn with_id(mut self, id: Uuid) -> Self {
self.id = id;
self
}
pub fn with_correlation_id(mut self, id: impl Into<String>) -> Self {
self.correlation_id = Some(id.into());
self
}
}