1use crate::{HatId, Topic};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Event {
9 pub topic: Topic,
11
12 pub payload: String,
14
15 pub source: Option<HatId>,
17
18 pub target: Option<HatId>,
20}
21
22impl Event {
23 pub fn new(topic: impl Into<Topic>, payload: impl Into<String>) -> Self {
25 Self {
26 topic: topic.into(),
27 payload: payload.into(),
28 source: None,
29 target: None,
30 }
31 }
32
33 #[must_use]
35 pub fn with_source(mut self, source: impl Into<HatId>) -> Self {
36 self.source = Some(source.into());
37 self
38 }
39
40 #[must_use]
42 pub fn with_target(mut self, target: impl Into<HatId>) -> Self {
43 self.target = Some(target.into());
44 self
45 }
46}