use crate::models::text::RichText;
use crate::models::users::User;
use crate::ids::{DatabaseId, PageId, PropertyId};
use crate::models::{DateTime, Number, Utc};
use chrono::NaiveDate;
use serde::{Deserialize, Serialize};
#[cfg(test)]
mod tests;
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone, Hash)]
#[serde(rename_all = "snake_case")]
pub enum NumberFormat {
Number,
NumberWithCommas,
Percent,
Dollar,
Euro,
Pound,
Yen,
Ruble,
Rupee,
Won,
Yuan,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Hash, Clone)]
pub struct NumberDetails {
pub format: NumberFormat,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Clone)]
#[serde(transparent)]
pub struct SelectOptionId(String);
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
#[serde(rename_all = "lowercase")]
pub enum Color {
Default,
Gray,
Brown,
Orange,
Yellow,
Green,
Blue,
Purple,
Pink,
Red,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct SelectOption {
pub name: String,
pub id: SelectOptionId,
pub color: Color,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Select {
pub options: Vec<SelectOption>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct StatusGroupOption {
pub name: String,
pub id: SelectOptionId,
pub color: Color,
pub option_ids: Vec<SelectOptionId>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Status {
pub options: Vec<SelectOption>,
pub groups: Vec<StatusGroupOption>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Formula {
pub expression: String,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Relation {
pub database_id: DatabaseId,
pub synced_property_name: Option<String>,
pub synced_property_id: Option<PropertyId>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
#[serde(rename_all = "snake_case")]
pub enum RollupFunction {
Average,
Checked,
Count,
CountPerGroup,
CountValues,
DateRange,
EarliestDate,
Empty,
LatestDate,
Max,
Median,
Min,
NotEmpty,
PercentChecked,
PercentEmpty,
PercentNotEmpty,
PercentPerGroup,
PercentUnchecked,
Range,
ShowOriginal,
ShowUnique,
Sum,
Unchecked,
Unique,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Rollup {
pub relation_property_name: String,
pub relation_property_id: PropertyId,
pub rollup_property_name: String,
pub rollup_property_id: String,
pub function: RollupFunction,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum PropertyConfiguration {
Title { id: PropertyId },
#[serde(rename = "rich_text")]
Text { id: PropertyId },
Number {
id: PropertyId,
number: NumberDetails,
},
Select { id: PropertyId, select: Select },
Status { id: PropertyId, status: Status },
MultiSelect {
id: PropertyId,
multi_select: Select,
},
Date { id: PropertyId },
People { id: PropertyId },
Files { id: PropertyId },
Checkbox { id: PropertyId },
Url { id: PropertyId },
Email { id: PropertyId },
PhoneNumber { id: PropertyId },
Formula { id: PropertyId, formula: Formula },
Relation { id: PropertyId, relation: Relation },
Rollup { id: PropertyId, rollup: Rollup },
CreatedTime { id: PropertyId },
CreatedBy { id: PropertyId },
LastEditedTime { id: PropertyId },
LastEditBy { id: PropertyId },
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct SelectedValue {
#[serde(skip_serializing_if = "Option::is_none")]
pub id: Option<SelectOptionId>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
pub color: Color,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(untagged)]
pub enum DateOrDateTime {
Date(NaiveDate),
DateTime(DateTime<Utc>),
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct DateValue {
pub start: DateOrDateTime,
pub end: Option<DateOrDateTime>,
pub time_zone: Option<String>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum FormulaResultValue {
String { string: Option<String> },
Number { number: Option<Number> },
Boolean { boolean: Option<bool> },
Date { date: Option<DateValue> },
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct RelationValue {
pub id: PageId,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum RollupValue {
Number { number: Option<Number> },
Date { date: Option<DateTime<Utc>> },
Array { array: Vec<RollupPropertyValue> },
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct FileReference {
pub name: String,
pub url: String,
pub mime_type: String,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum PropertyValue {
Title {
id: PropertyId,
title: Vec<RichText>,
},
#[serde(rename = "rich_text")]
Text {
id: PropertyId,
rich_text: Vec<RichText>,
},
Number {
id: PropertyId,
number: Option<Number>,
},
Select {
id: PropertyId,
select: Option<SelectedValue>,
},
Status {
id: PropertyId,
status: Option<SelectedValue>,
},
MultiSelect {
id: PropertyId,
multi_select: Option<Vec<SelectedValue>>,
},
Date {
id: PropertyId,
date: Option<DateValue>,
},
Formula {
id: PropertyId,
formula: FormulaResultValue,
},
Relation {
id: PropertyId,
relation: Option<Vec<RelationValue>>,
},
Rollup {
id: PropertyId,
rollup: Option<RollupValue>,
},
People { id: PropertyId, people: Vec<User> },
Files {
id: PropertyId,
files: Option<Vec<FileReference>>,
},
Checkbox { id: PropertyId, checkbox: bool },
Url { id: PropertyId, url: Option<String> },
Email {
id: PropertyId,
email: Option<String>,
},
PhoneNumber {
id: PropertyId,
phone_number: String,
},
CreatedTime {
id: PropertyId,
created_time: DateTime<Utc>,
},
CreatedBy { id: PropertyId, created_by: User },
LastEditedTime {
id: PropertyId,
last_edited_time: DateTime<Utc>,
},
LastEditedBy {
id: PropertyId,
last_edited_by: User,
},
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum RollupPropertyValue {
#[serde(rename = "rich_text")]
Text {
rich_text: Vec<RichText>,
},
Number {
number: Option<Number>,
},
Select {
select: Option<SelectedValue>,
},
Status {
status: Option<SelectedValue>,
},
MultiSelect {
multi_select: Option<Vec<SelectedValue>>,
},
Date {
date: Option<DateValue>,
},
Formula {
formula: FormulaResultValue,
},
Relation {
relation: Option<Vec<RelationValue>>,
},
Rollup {
rollup: Option<RollupValue>,
},
People {
people: Vec<User>,
},
Files {
files: Option<Vec<FileReference>>,
},
Checkbox {
checkbox: bool,
},
Url {
url: Option<String>,
},
Email {
email: Option<String>,
},
PhoneNumber {
phone_number: String,
},
CreatedTime {
created_time: DateTime<Utc>,
},
CreatedBy {
created_by: User,
},
LastEditedTime {
last_edited_time: DateTime<Utc>,
},
LastEditedBy {
last_edited_by: User,
},
}