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