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}
129
130#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
131#[serde(rename_all = "snake_case")]
132pub enum Color {
133 Default,
134 Gray,
135 Brown,
136 Red,
137 Orange,
138 Yellow,
139 Green,
140 Blue,
141 Purple,
142 Pink,
143}
144
145#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
146pub struct DatePropertyValue {
147 pub start: Option<DateOrDateTime>,
148 pub end: Option<DateOrDateTime>,
149 pub time_zone: Option<String>,
150}
151
152#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
153#[serde(untagged)]
154pub enum DateOrDateTime {
155 Date(NaiveDate),
156 DateTime(DateTime<Utc>),
157}
158
159#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
160#[serde(tag = "type", rename_all = "snake_case")]
161pub enum FormulaPropertyValue {
162 String { string: Option<String> },
163 Number { number: Option<Number> },
164 Boolean { boolean: bool },
165 Date { date: Option<DatePropertyValue> },
166}
167
168#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
169pub struct RelationPropertyValue {
170 pub id: String,
171}
172
173#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
174#[serde(tag = "type", rename_all = "snake_case")]
175pub enum RollupPropertyValue {
176 Array {
177 function: RollupFunction,
178 array: Vec<PageProperty>,
179 },
180 Date {
181 function: RollupFunction,
182 date: Option<DateTime<Utc>>,
183 },
184 Incomplete {
185 function: RollupFunction,
186 incomplete: Option<String>,
187 },
188 Number {
189 function: RollupFunction,
190 number: Option<Number>,
191 },
192 Unsupported {
193 function: RollupFunction,
194 unsupported: Option<String>,
195 },
196}
197
198#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
199#[serde(rename_all = "snake_case")]
200pub enum RollupFunction {
201 Average,
202 Checked,
203 Count,
204 CountPerGroup,
205 CountValues,
206 DateRange,
207 EarliestDate,
208 Empty,
209 LatestDate,
210 Max,
211 Median,
212 Min,
213 NotEmpty,
214 PercentChecked,
215 PercentEmpty,
216 PercentNotEmpty,
217 PercentPerGroup,
218 PercentUnchecked,
219 Range,
220 ShowOriginal,
221 ShowUnique,
222 Sum,
223 Unchecked,
224 Unique,
225}
226
227#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
228pub struct FilePropertyValue {
229 pub name: String,
230 #[serde(flatten)]
231 pub file: File,
232}
233
234#[skip_serializing_none]
235#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone, Default)]
236pub struct SelectPropertyValue {
237 pub id: Option<String>,
238 pub name: Option<String>,
239 pub color: Option<Color>,
240}
241
242#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
243pub struct UniqueIDPropertyValue {
244 #[serde(default)]
245 #[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"]
246 pub number: Option<Number>,
247 pub prefix: Option<String>,
248}
249
250#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
251pub struct VerificationPropertyValue {
252 pub state: VerificationState,
253 pub verified_by: Option<User>,
254 pub date: Option<DatePropertyValue>,
255}
256
257#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
258#[serde(rename_all = "snake_case")]
259pub enum VerificationState {
260 Verified,
261 Unverified,
262}