use crate::models::{properties::DateValue, users::User, Database, Page};
use serde::{Deserialize, Serialize};
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
#[serde(rename_all = "snake_case")]
pub enum TextColor {
Default,
Gray,
Brown,
Orange,
Yellow,
Green,
Blue,
Purple,
Pink,
Red,
GrayBackground,
BrownBackground,
OrangeBackground,
YellowBackground,
GreenBackground,
BlueBackground,
PurpleBackground,
PinkBackground,
RedBackground,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Annotations {
pub bold: Option<bool>,
pub code: Option<bool>,
pub color: Option<TextColor>,
pub italic: Option<bool>,
pub strikethrough: Option<bool>,
pub underline: Option<bool>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct RichTextCommon {
pub plain_text: String,
#[serde(skip_serializing_if = "Option::is_none")]
pub href: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub annotations: Option<Annotations>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Link {
pub url: String,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
pub struct Text {
pub content: String,
pub link: Option<Link>,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum MentionObject {
User {
user: User,
},
Page {
page: Page,
},
Database {
database: Database,
},
Date {
date: DateValue,
},
#[serde(other)]
Unknown,
}
#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
#[serde(tag = "type")]
#[serde(rename_all = "snake_case")]
pub enum RichText {
Text {
#[serde(flatten)]
rich_text: RichTextCommon,
text: Text,
},
Mention {
#[serde(flatten)]
rich_text: RichTextCommon,
mention: MentionObject,
},
Equation {
#[serde(flatten)]
rich_text: RichTextCommon,
},
}
impl RichText {
pub fn plain_text(&self) -> &str {
use RichText::*;
match self {
Text { rich_text, .. } | Mention { rich_text, .. } | Equation { rich_text, .. } => {
&rich_text.plain_text
}
}
}
}