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