1use std::collections::HashMap;
2
3use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5use serde_json::Number;
6use serde_with::skip_serializing_none;
7
8use super::{
9 emoji::Emoji, file::File, native_icon::NativeIcon, parent::Parent, property::DateOrDateTime,
10 rich_text::RichText, user::User,
11};
12
13#[skip_serializing_none]
14#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
15pub struct Page {
16 pub id: String,
17 pub created_time: DateTime<Utc>,
18 pub created_by: User,
19 pub last_edited_time: DateTime<Utc>,
20 pub last_edited_by: User,
21 pub in_trash: bool,
22 pub icon: Option<Icon>,
23 pub cover: Option<File>,
24 pub properties: HashMap<String, PageProperty>,
25 pub parent: Parent,
26 pub url: String,
27 pub public_url: Option<String>,
28}
29
30#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
31#[serde(rename_all = "snake_case", untagged)]
32pub enum Icon {
33 File(File),
34 Emoji(Emoji),
35 NativeIcon(NativeIcon),
36}
37
38#[skip_serializing_none]
39#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
40#[serde(tag = "type", rename_all = "snake_case")]
41pub enum PageProperty {
42 Checkbox {
43 id: Option<String>,
44 checkbox: bool,
45 },
46 CreatedBy {
47 id: Option<String>,
48 created_by: User,
49 },
50 CreatedTime {
51 id: Option<String>,
52 created_time: DateTime<Utc>,
53 },
54 Date {
55 id: Option<String>,
56 date: Option<DatePropertyValue>,
57 },
58 Email {
59 id: Option<String>,
60 email: Option<String>,
61 },
62 Files {
63 id: Option<String>,
64 files: Vec<FilePropertyValue>,
65 },
66 Formula {
67 id: Option<String>,
68 formula: Option<FormulaPropertyValue>,
69 },
70 LastEditedBy {
71 id: Option<String>,
72 last_edited_by: User,
73 },
74 LastEditedTime {
75 id: Option<String>,
76 last_edited_time: Option<DateTime<Utc>>,
77 },
78 MultiSelect {
79 id: Option<String>,
80 multi_select: Vec<SelectPropertyValue>,
81 },
82 Number {
83 id: Option<String>,
84 number: Option<Number>,
85 },
86 People {
87 id: Option<String>,
88 people: Vec<User>,
89 },
90 PhoneNumber {
91 id: Option<String>,
92 phone_number: Option<String>,
93 },
94 Relation {
95 id: Option<String>,
96 relation: Vec<RelationPropertyValue>,
97 has_more: Option<bool>,
98 },
99 Rollup {
100 id: Option<String>,
101 rollup: Option<RollupPropertyValue>,
102 },
103 RichText {
104 id: Option<String>,
105 rich_text: Vec<RichText>,
106 },
107 Select {
108 id: Option<String>,
109 select: Option<SelectPropertyValue>,
110 },
111 Status {
112 id: Option<String>,
113 status: Option<SelectPropertyValue>,
114 },
115 Title {
116 id: Option<String>,
117 title: Vec<RichText>,
118 },
119 Url {
120 id: Option<String>,
121 url: Option<String>,
122 },
123 #[serde(rename = "unique_id")]
124 UniqueID {
125 id: Option<String>,
126 unique_id: Option<UniqueIDPropertyValue>,
127 },
128 Verification {
129 id: Option<String>,
130 verification: Option<VerificationPropertyValue>,
131 },
132 Button {
133 id: Option<String>,
134 },
135}
136
137#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
138#[serde(rename_all = "snake_case")]
139pub enum Color {
140 Default,
141 Gray,
142 Brown,
143 Red,
144 Orange,
145 Yellow,
146 Green,
147 Blue,
148 Purple,
149 Pink,
150}
151
152#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
153pub struct DatePropertyValue {
154 pub start: Option<DateOrDateTime>,
155 pub end: Option<DateOrDateTime>,
156 pub time_zone: Option<String>,
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}