use std::collections::BTreeMap;
use crate::core::metadata::MetadataValue;
use crate::core::object_id::ObjectId;
use crate::core::timestamp::Timestamp;
use crate::events::event_type::EventType;
use crate::security::actor::ActorId;
#[derive(Clone, Debug, Default, PartialEq)]
pub struct EventData {
fields: BTreeMap<String, MetadataValue>,
}
impl EventData {
pub fn new() -> Self {
Self::default()
}
pub fn insert(
&mut self,
key: impl Into<String>,
value: MetadataValue,
) -> Option<MetadataValue> {
self.fields.insert(key.into(), value)
}
pub fn remove(&mut self, key: &str) -> Option<MetadataValue> {
self.fields.remove(key)
}
pub fn get(&self, key: &str) -> Option<&MetadataValue> {
self.fields.get(key)
}
pub fn fields(&self) -> &BTreeMap<String, MetadataValue> {
&self.fields
}
}
#[derive(Clone, Debug, PartialEq)]
pub struct ObjectEvent {
pub event_type: EventType,
pub object: ObjectId,
pub source_parent: Option<ObjectId>,
pub destination_parent: Option<ObjectId>,
pub actor: Option<ActorId>,
pub timestamp: Timestamp,
pub data: EventData,
}
impl ObjectEvent {
pub fn new(
event_type: EventType,
object: ObjectId,
actor: Option<ActorId>,
timestamp: Timestamp,
) -> Self {
Self {
event_type,
object,
source_parent: None,
destination_parent: None,
actor,
timestamp,
data: EventData::new(),
}
}
}