1use std::collections::HashMap;
2
3use chrono::{DateTime, NaiveDate, Utc};
4use serde::{Deserialize, Serialize};
5use serde_json::Number;
6use serde_with::skip_serializing_none;
7
8use super::{emoji::Emoji, file::File, parent::Parent, rich_text::RichText, user::User};
9
10#[skip_serializing_none]
11#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
12pub struct Page {
13 pub id: String,
14 pub created_time: DateTime<Utc>,
15 pub created_by: User,
16 pub last_edited_time: DateTime<Utc>,
17 pub last_edited_by: User,
18 pub archived: bool,
19 pub icon: Option<Icon>,
20 pub cover: Option<File>,
21 pub properties: HashMap<String, PageProperty>,
22 pub parent: Parent,
23 pub url: String,
24 pub public_url: Option<String>,
25}
26
27#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
28#[serde(rename_all = "snake_case", untagged)]
29pub enum Icon {
30 File(File),
31 Emoji(Emoji),
32}
33
34#[skip_serializing_none]
35#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
36#[serde(tag = "type", rename_all = "snake_case")]
37pub enum PageProperty {
38 Checkbox {
39 id: Option<String>,
40 checkbox: bool,
41 },
42 CreatedBy {
43 id: Option<String>,
44 created_by: User,
45 },
46 CreatedTime {
47 id: Option<String>,
48 created_time: DateTime<Utc>,
49 },
50 Date {
51 id: Option<String>,
52 date: Option<DatePropertyValue>,
53 },
54 Email {
55 id: Option<String>,
56 email: Option<String>,
57 },
58 Files {
59 id: Option<String>,
60 files: Vec<FilePropertyValue>,
61 },
62 Formula {
63 id: Option<String>,
64 formula: Option<FormulaPropertyValue>,
65 },
66 LastEditedBy {
67 id: Option<String>,
68 last_edited_by: User,
69 },
70 LastEditedTime {
71 id: Option<String>,
72 last_edited_time: Option<DateTime<Utc>>,
73 },
74 MultiSelect {
75 id: Option<String>,
76 multi_select: Vec<SelectPropertyValue>,
77 },
78 Number {
79 id: Option<String>,
80 number: Option<Number>,
81 },
82 People {
83 id: Option<String>,
84 people: Vec<User>,
85 },
86 PhoneNumber {
87 id: Option<String>,
88 phone_number: Option<String>,
89 },
90 Relation {
91 id: Option<String>,
92 relation: Vec<RelationPropertyValue>,
93 has_more: Option<bool>,
94 },
95 Rollup {
96 id: Option<String>,
97 rollup: Option<RollupPropertyValue>,
98 },
99 RichText {
100 id: Option<String>,
101 rich_text: Vec<RichText>,
102 },
103 Select {
104 id: Option<String>,
105 select: Option<SelectPropertyValue>,
106 },
107 Status {
108 id: Option<String>,
109 status: Option<SelectPropertyValue>,
110 },
111 Title {
112 id: Option<String>,
113 title: Vec<RichText>,
114 },
115 Url {
116 id: Option<String>,
117 url: Option<String>,
118 },
119 #[serde(rename = "unique_id")]
120 UniqueID {
121 id: Option<String>,
122 unique_id: Option<UniqueIDPropertyValue>,
123 },
124 Verification {
125 id: Option<String>,
126 verification: Option<VerificationPropertyValue>,
127 },
128 Button {
129 id: Option<String>,
130 },
131}
132
133#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
134#[serde(rename_all = "snake_case")]
135pub enum Color {
136 Default,
137 Gray,
138 Brown,
139 Red,
140 Orange,
141 Yellow,
142 Green,
143 Blue,
144 Purple,
145 Pink,
146}
147
148#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
149pub struct DatePropertyValue {
150 pub start: Option<DateOrDateTime>,
151 pub end: Option<DateOrDateTime>,
152 pub time_zone: Option<String>,
153}
154
155#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
156#[serde(untagged)]
157pub enum DateOrDateTime {
158 Date(NaiveDate),
159 DateTime(DateTime<Utc>),
160}
161
162#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
163#[serde(tag = "type", rename_all = "snake_case")]
164pub enum FormulaPropertyValue {
165 String { string: Option<String> },
166 Number { number: Option<Number> },
167 Boolean { boolean: bool },
168 Date { date: Option<DatePropertyValue> },
169}
170
171#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
172pub struct RelationPropertyValue {
173 pub id: String,
174}
175
176#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
177#[serde(tag = "type", rename_all = "snake_case")]
178pub enum RollupPropertyValue {
179 Array {
180 function: RollupFunction,
181 array: Vec<PageProperty>,
182 },
183 Date {
184 function: RollupFunction,
185 date: Option<DateTime<Utc>>,
186 },
187 Incomplete {
188 function: RollupFunction,
189 incomplete: Option<String>,
190 },
191 Number {
192 function: RollupFunction,
193 number: Option<Number>,
194 },
195 Unsupported {
196 function: RollupFunction,
197 unsupported: Option<String>,
198 },
199}
200
201#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
202#[serde(rename_all = "snake_case")]
203pub enum RollupFunction {
204 Average,
205 Checked,
206 Count,
207 CountPerGroup,
208 CountValues,
209 DateRange,
210 EarliestDate,
211 Empty,
212 LatestDate,
213 Max,
214 Median,
215 Min,
216 NotEmpty,
217 PercentChecked,
218 PercentEmpty,
219 PercentNotEmpty,
220 PercentPerGroup,
221 PercentUnchecked,
222 Range,
223 ShowOriginal,
224 ShowUnique,
225 Sum,
226 Unchecked,
227 Unique,
228}
229
230#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
231pub struct FilePropertyValue {
232 pub name: String,
233 #[serde(flatten)]
234 pub file: File,
235}
236
237#[skip_serializing_none]
238#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
239pub struct SelectPropertyValue {
240 pub id: Option<String>,
241 pub name: Option<String>,
242 pub color: Option<Color>,
243}
244
245#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
246pub struct UniqueIDPropertyValue {
247 #[serde(default)]
248 #[doc = "This field is null only in extremely rare cases, for instance when it's being used as a Template for a Task in Notion's Project Management Template: https://www.notion.so/templates/notion-projects-and-tasks"]
249 pub number: Option<Number>,
250 pub prefix: Option<String>,
251}
252
253#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
254pub struct VerificationPropertyValue {
255 pub state: VerificationState,
256 pub verified_by: Option<User>,
257 pub date: Option<DatePropertyValue>,
258}
259
260#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
261#[serde(rename_all = "snake_case")]
262pub enum VerificationState {
263 Verified,
264 Unverified,
265}