1use chrono::{DateTime, NaiveDate, 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: Option<DateOrDateTime>,
120 pub end: Option<DateOrDateTime>,
121 pub time_zone: Option<String>,
122}
123
124#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
125#[serde(untagged)]
126pub enum DateOrDateTime {
127 Date(NaiveDate),
128 DateTime(DateTime<Utc>),
129}
130
131#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
132#[serde(tag = "type", rename_all = "snake_case")]
133pub enum FormulaPropertyValue {
134 String { string: Option<String> },
135 Number { number: Option<Number> },
136 Boolean { boolean: bool },
137 Date { date: Option<DatePropertyValue> },
138}
139
140#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
141pub struct RelationPropertyValue {
142 pub id: String,
143}
144
145#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
146#[serde(tag = "type", rename_all = "snake_case")]
147pub enum RollupPropertyValue {
148 String { string: Option<String> },
149 Number { number: Option<Number> },
150 Date { date: DateTime<Utc> },
151 Array { results: Vec<RollupPropertyValue> },
152}
153
154#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
155pub struct FilePropertyValue {
156 pub name: String,
157 #[serde(flatten)]
158 pub file: File,
159}