use bon::Builder;
use serde::{Deserialize, Serialize};
#[derive(Builder, Default, Debug, Clone, Serialize, Deserialize)]
pub struct EventContext {
correlation_id: Option<String>,
causation_id: Option<String>,
duration_ms: Option<u128>,
actor_type: Option<String>,
actor_id: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
extensions: Option<serde_json::Value>,
}
impl EventContext {
pub fn correlation_id(&self) -> Option<&str> {
self.correlation_id.as_deref()
}
pub fn causation_id(&self) -> Option<&str> {
self.causation_id.as_deref()
}
pub fn duration_ms(&self) -> Option<u128> {
self.duration_ms
}
pub fn actor_type(&self) -> Option<&str> {
self.actor_type.as_deref()
}
pub fn actor_id(&self) -> Option<&str> {
self.actor_id.as_deref()
}
pub fn extensions(&self) -> Option<&serde_json::Value> {
self.extensions.as_ref()
}
pub fn set_actor(&mut self, actor_type: impl Into<String>, actor_id: impl Into<String>) {
self.actor_type = Some(actor_type.into());
self.actor_id = Some(actor_id.into());
}
}