1use std::collections::BTreeMap;
4
5use crate::core::metadata::MetadataValue;
6use crate::core::object_id::ObjectId;
7use crate::core::timestamp::Timestamp;
8use crate::events::event_type::EventType;
9use crate::security::actor::ActorId;
10
11#[derive(Clone, Debug, Default, PartialEq)]
16pub struct EventData {
17 fields: BTreeMap<String, MetadataValue>,
18}
19
20impl EventData {
21 pub fn new() -> Self {
23 Self::default()
24 }
25
26 pub fn insert(
28 &mut self,
29 key: impl Into<String>,
30 value: MetadataValue,
31 ) -> Option<MetadataValue> {
32 self.fields.insert(key.into(), value)
33 }
34
35 pub fn remove(&mut self, key: &str) -> Option<MetadataValue> {
37 self.fields.remove(key)
38 }
39
40 pub fn get(&self, key: &str) -> Option<&MetadataValue> {
42 self.fields.get(key)
43 }
44
45 pub fn fields(&self) -> &BTreeMap<String, MetadataValue> {
47 &self.fields
48 }
49}
50
51#[derive(Clone, Debug, PartialEq)]
56pub struct ObjectEvent {
57 pub event_type: EventType,
59 pub object: ObjectId,
61 pub source_parent: Option<ObjectId>,
63 pub destination_parent: Option<ObjectId>,
65 pub actor: Option<ActorId>,
67 pub timestamp: Timestamp,
69 pub data: EventData,
71}
72
73impl ObjectEvent {
74 pub fn new(
76 event_type: EventType,
77 object: ObjectId,
78 actor: Option<ActorId>,
79 timestamp: Timestamp,
80 ) -> Self {
81 Self {
82 event_type,
83 object,
84 source_parent: None,
85 destination_parent: None,
86 actor,
87 timestamp,
88 data: EventData::new(),
89 }
90 }
91}