1use std::collections::HashMap;
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use serde_with::skip_serializing_none;
6
7use super::{
8 emoji::Emoji, file::File, native_icon::NativeIcon, parent::Parent, rich_text::RichText,
9 user::User,
10};
11
12#[skip_serializing_none]
13#[derive(Serialize, Deserialize, Eq, PartialEq, Debug, Clone)]
14pub struct Database {
15 pub id: Option<String>,
16 pub created_time: DateTime<Utc>,
17 pub created_by: Option<User>,
18 pub last_edited_time: DateTime<Utc>,
19 pub last_edited_by: Option<User>,
20 pub title: Vec<RichText>,
21 pub description: Vec<RichText>,
22 pub icon: Option<Icon>,
23 pub cover: Option<File>,
24 pub properties: HashMap<String, DatabaseProperty>,
25 pub parent: Parent,
26 pub url: String,
27 pub in_trash: bool,
28 pub is_inline: bool,
29 pub public_url: Option<bool>,
30}
31
32#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
33#[serde(rename_all = "snake_case", untagged)]
34pub enum Icon {
35 #[default]
36 None,
37 File(File),
38 Emoji(Emoji),
39 NativeIcon(NativeIcon),
40}
41
42#[skip_serializing_none]
43#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
44#[serde(tag = "type", rename_all = "snake_case")]
45pub enum DatabaseProperty {
46 Checkbox {
47 id: Option<String>,
48 name: Option<String>,
49 checkbox: HashMap<(), ()>,
50 },
51 CreatedBy {
52 id: Option<String>,
53 name: Option<String>,
54 created_by: HashMap<(), ()>,
55 },
56 CreatedTime {
57 id: Option<String>,
58 name: Option<String>,
59 created_time: HashMap<(), ()>,
60 },
61 Date {
62 id: Option<String>,
63 name: Option<String>,
64 date: HashMap<(), ()>,
65 },
66 Email {
67 id: Option<String>,
68 name: Option<String>,
69 email: HashMap<(), ()>,
70 },
71 Files {
72 id: Option<String>,
73 name: Option<String>,
74 files: HashMap<(), ()>,
75 },
76 Formula {
77 id: Option<String>,
78 name: Option<String>,
79 formula: FormulaPropertyValue,
80 },
81 LastEditedBy {
82 id: Option<String>,
83 name: Option<String>,
84 last_edited_by: HashMap<(), ()>,
85 },
86 LastEditedTime {
87 id: Option<String>,
88 name: Option<String>,
89 last_edited_time: HashMap<(), ()>,
90 },
91 MultiSelect {
92 id: Option<String>,
93 name: Option<String>,
94 multi_select: SelectPropertyValue,
95 },
96 Number {
97 id: Option<String>,
98 name: Option<String>,
99 number: NumberPropertyValue,
100 },
101 People {
102 id: Option<String>,
103 name: Option<String>,
104 people: HashMap<(), ()>,
105 },
106 PhoneNumber {
107 id: Option<String>,
108 name: Option<String>,
109 phone_number: HashMap<(), ()>,
110 },
111 Relation {
112 id: Option<String>,
113 name: Option<String>,
114 relation: RelationPropertyValue,
115 },
116 RichText {
117 id: Option<String>,
118 name: Option<String>,
119 rich_text: HashMap<(), ()>,
120 },
121 Rollup {
122 id: Option<String>,
123 name: Option<String>,
124 rollup: RollupPropertyValue,
125 },
126 Select {
127 id: Option<String>,
128 name: Option<String>,
129 select: SelectPropertyValue,
130 },
131 Status {
132 id: Option<String>,
133 name: Option<String>,
134 status: StatusPropertyValue,
135 },
136 Title {
137 id: Option<String>,
138 name: Option<String>,
139 title: HashMap<(), ()>,
140 },
141 Url {
142 id: Option<String>,
143 name: Option<String>,
144 url: HashMap<(), ()>,
145 },
146 Button {
147 id: Option<String>,
148 name: Option<String>,
149 button: HashMap<(), ()>,
150 },
151}
152
153#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
154#[serde(rename_all = "snake_case")]
155pub enum Color {
156 #[default]
157 Blue,
158 Brown,
159 Default,
160 Gray,
161 Green,
162 Orange,
163 Pink,
164 Purple,
165 Red,
166 Yellow,
167}
168
169#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
170pub struct FormulaPropertyValue {
171 pub expression: String,
172}
173
174#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
175pub struct NumberPropertyValue {
176 pub format: NumberFormat,
177}
178
179#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
180#[serde(rename_all = "snake_case")]
181pub enum NumberFormat {
182 ArgentinePeso,
183 Baht,
184 AustralianDollar,
185 CanadianDollar,
186 ChileanPeso,
187 ColombianPeso,
188 DanishKrone,
189 Dirham,
190 Dollar,
191 Euro,
192 Forint,
193 Franc,
194 HongKongDollar,
195 Koruna,
196 Krona,
197 Leu,
198 Lira,
199 MexicanPeso,
200 NewTaiwanDollar,
201 NewZealandDollar,
202 NorwegianKrone,
203 Number,
204 NumberWithCommas,
205 Percent,
206 PhilippinePeso,
207 Pound,
208 PeruvianSol,
209 Rand,
210 Real,
211 Ringgit,
212 Riyal,
213 Ruble,
214 Rupee,
215 Rupiah,
216 Shekel,
217 SingaporeDollar,
218 UruguayanPeso,
219 Yen,
220 Yuan,
221 Won,
222 Zloty,
223}
224
225#[skip_serializing_none]
226#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
227pub struct RelationPropertyValue {
228 pub database_id: Option<String>,
229 pub data_source_id: Option<String>,
230 pub synced_property_id: Option<String>,
231 pub synced_property_name: Option<String>,
232}
233
234#[skip_serializing_none]
235#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
236pub struct RollupPropertyValue {
237 pub rollup_property_name: String,
238 pub relation_property_name: String,
239 pub function: RollupFunction,
240 pub relation_property_id: Option<String>,
241 pub rollup_property_id: Option<String>,
242}
243
244#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
245#[serde(rename_all = "snake_case")]
246pub enum RollupFunction {
247 #[default]
248 Average,
249 Checked,
250 CountPerGroup,
251 Count,
252 CountValues,
253 DateRange,
254 EarliestDate,
255 Empty,
256 LatestDate,
257 Max,
258 Median,
259 Min,
260 NotEmpty,
261 PercentChecked,
262 PercentEmpty,
263 PercentNotEmpty,
264 PercentPerGroup,
265 PercentUnchecked,
266 Range,
267 Unchecked,
268 Unique,
269 ShowOriginal,
270 ShowUnique,
271 Sum,
272}
273
274#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
275pub struct StatusPropertyValue {
276 pub options: Vec<OptionValue>,
277 pub groups: Vec<Group>,
278}
279
280#[skip_serializing_none]
281#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
282pub struct Group {
283 pub color: Color,
284 pub id: Option<String>,
285 pub name: String,
286 pub option_ids: Vec<String>,
287}
288
289#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
290pub struct SelectPropertyValue {
291 pub options: Vec<OptionValue>,
292}
293
294#[skip_serializing_none]
295#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
296pub struct OptionValue {
297 pub name: String,
298 pub color: Option<Color>,
299 pub id: Option<String>,
300}