1mod aggregate;
2mod filter;
3
4pub use self::aggregate::*;
5pub use self::filter::*;
6
7use crate::UpsertOptions;
8use crate::{
9 EqIdentity, Identity, IntoPatch, IntoPatchItem, Patch, UpdateList, UpdateMap, UpdateSetNull,
10};
11use serde::{Deserialize, Serialize};
12use serde_with::skip_serializing_none;
13use std::collections::HashMap;
14
15#[skip_serializing_none]
16#[derive(Serialize, Deserialize, Debug, Default, Clone)]
17#[serde(rename_all = "camelCase")]
18pub struct Event {
20 pub id: i64,
22 pub external_id: Option<String>,
24 pub data_set_id: Option<i64>,
26 pub start_time: Option<i64>,
28 pub end_time: Option<i64>,
30 #[serde(rename = "type")]
32 pub r#type: Option<String>,
33 pub subtype: Option<String>,
35 pub description: Option<String>,
37 pub metadata: Option<HashMap<String, String>>,
41 pub asset_ids: Option<Vec<i64>>,
43 pub source: Option<String>,
45 pub created_time: i64,
47 pub last_updated_time: i64,
49}
50
51#[skip_serializing_none]
52#[derive(Serialize, Deserialize, Debug, Default, Clone)]
53#[serde(rename_all = "camelCase")]
54pub struct AddEvent {
56 pub external_id: Option<String>,
58 pub data_set_id: Option<i64>,
60 pub start_time: Option<i64>,
62 pub end_time: Option<i64>,
64 #[serde(rename = "type")]
66 pub r#type: Option<String>,
67 pub subtype: Option<String>,
69 pub description: Option<String>,
71 pub metadata: Option<HashMap<String, String>>,
75 pub asset_ids: Option<Vec<i64>>,
77 pub source: Option<String>,
79}
80
81impl From<Event> for AddEvent {
82 fn from(event: Event) -> AddEvent {
83 AddEvent {
84 external_id: event.external_id,
85 data_set_id: event.data_set_id,
86 start_time: event.start_time,
87 end_time: event.end_time,
88 r#type: event.r#type,
89 subtype: event.subtype,
90 description: event.description,
91 metadata: event.metadata,
92 asset_ids: event.asset_ids,
93 source: event.source,
94 }
95 }
96}
97
98impl EqIdentity for AddEvent {
99 fn eq(&self, id: &Identity) -> bool {
100 match id {
101 Identity::Id { id: _ } => false,
102 Identity::ExternalId { external_id } => self.external_id.as_ref() == Some(external_id),
103 }
104 }
105}
106
107#[skip_serializing_none]
108#[derive(Serialize, Deserialize, Debug, Default, Clone)]
109#[serde(rename_all = "camelCase")]
110pub struct PatchEvent {
112 pub external_id: Option<UpdateSetNull<String>>,
114 pub data_set_id: Option<UpdateSetNull<i64>>,
116 pub start_time: Option<UpdateSetNull<i64>>,
118 pub end_time: Option<UpdateSetNull<i64>>,
120 pub description: Option<UpdateSetNull<String>>,
122 pub metadata: Option<UpdateMap<String, String>>,
126 pub asset_ids: Option<UpdateList<i64, i64>>,
128 pub source: Option<UpdateSetNull<String>>,
130 pub r#type: Option<UpdateSetNull<String>>,
132 pub subtype: Option<UpdateSetNull<String>>,
134}
135
136impl IntoPatch<Patch<PatchEvent>> for Event {
137 fn patch(self, options: &UpsertOptions) -> Patch<PatchEvent> {
138 Patch::<PatchEvent> {
139 id: to_idt!(self),
140 update: PatchEvent {
141 external_id: self.external_id.patch(options),
142 data_set_id: self.data_set_id.patch(options),
143 start_time: self.start_time.patch(options),
144 end_time: self.end_time.patch(options),
145 description: self.description.patch(options),
146 metadata: self.metadata.patch(options),
147 asset_ids: self.asset_ids.patch(options),
148 source: self.source.patch(options),
149 r#type: self.r#type.patch(options),
150 subtype: self.subtype.patch(options),
151 },
152 }
153 }
154}
155
156impl IntoPatch<PatchEvent> for AddEvent {
157 fn patch(self, options: &UpsertOptions) -> PatchEvent {
158 PatchEvent {
159 external_id: self.external_id.patch(options),
160 data_set_id: self.data_set_id.patch(options),
161 start_time: self.start_time.patch(options),
162 end_time: self.end_time.patch(options),
163 description: self.description.patch(options),
164 metadata: self.metadata.patch(options),
165 asset_ids: self.asset_ids.patch(options),
166 source: self.source.patch(options),
167 r#type: self.r#type.patch(options),
168 subtype: self.subtype.patch(options),
169 }
170 }
171}
172
173impl From<Event> for Patch<PatchEvent> {
174 fn from(value: Event) -> Self {
175 IntoPatch::<Patch<PatchEvent>>::patch(value, &Default::default())
176 }
177}