1use serde::Serialize;
2use uuid::Uuid;
3
4#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
5#[cfg_attr(feature = "sqlx", sqlx(transparent))]
6#[derive(Debug, Copy, Clone)]
7pub struct EventId(Uuid);
8impl Default for EventId {
9 fn default() -> Self {
10 Self(Uuid::new_v4())
11 }
12}
13impl EventId {
14 pub fn load(id: Uuid) -> Self {
15 Self(id)
16 }
17 pub fn as_uuid(&self) -> Uuid {
18 self.0
19 }
20}
21
22#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
23#[cfg_attr(feature = "sqlx", sqlx(transparent))]
24#[derive(Debug, Clone)]
25pub struct IdempotencyToken(pub String);
26impl IdempotencyToken {
27 pub fn new(token: String) -> Self {
28 Self(token)
29 }
30 pub fn as_str(&self) -> &str {
31 &self.0
32 }
33 pub fn as_bytes(&self) -> &[u8] {
34 self.0.as_bytes()
35 }
36}
37
38#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
39#[cfg_attr(feature = "sqlx", sqlx(transparent))]
40#[derive(Debug)]
41pub struct EventType(String);
42impl EventType {
43 pub fn new(event_type: &str) -> Self {
44 Self(event_type.to_string())
45 }
46 pub fn load(value: &str) -> Self {
47 Self(value.to_owned())
48 }
49 pub fn as_str(&self) -> &str {
50 &self.0
51 }
52}
53
54#[cfg_attr(feature = "sqlx", derive(sqlx::Type))]
55#[cfg_attr(feature = "sqlx", sqlx(transparent))]
56#[derive(Debug, Serialize)]
57pub struct Payload(serde_json::Value);
58impl Payload {
59 pub fn new(payload: serde_json::Value) -> Self {
60 Self(payload)
61 }
62 pub fn load(value: &serde_json::Value) -> Self {
63 Self(value.clone())
64 }
65 pub fn as_json(&self) -> &serde_json::Value {
66 &self.0
67 }
68 pub fn from_static_str(s: &'static str) -> Self {
74 let val = serde_json::from_str(s).expect("Invalid JSON in static provider");
75 Self(val)
76 }
77}