1use crate::models::{properties::DateValue, users::User, Database, Page};
2use serde::{Deserialize, Serialize};
3
4#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Copy, Clone)]
5#[serde(rename_all = "snake_case")]
6pub enum TextColor {
7 Default,
8 Gray,
9 Brown,
10 Orange,
11 Yellow,
12 Green,
13 Blue,
14 Purple,
15 Pink,
16 Red,
17 GrayBackground,
18 BrownBackground,
19 OrangeBackground,
20 YellowBackground,
21 GreenBackground,
22 BlueBackground,
23 PurpleBackground,
24 PinkBackground,
25 RedBackground,
26}
27
28#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
31pub struct Annotations {
32 pub bold: Option<bool>,
33 pub code: Option<bool>,
34 pub color: Option<TextColor>,
35 pub italic: Option<bool>,
36 pub strikethrough: Option<bool>,
37 pub underline: Option<bool>,
38}
39
40#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
43pub struct RichTextCommon {
44 pub plain_text: String,
45 #[serde(skip_serializing_if = "Option::is_none")]
46 pub href: Option<String>,
47 #[serde(skip_serializing_if = "Option::is_none")]
48 pub annotations: Option<Annotations>,
49}
50
51#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
52pub struct Link {
53 pub url: String,
54}
55
56#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
57pub struct Text {
58 pub content: String,
59 pub link: Option<Link>,
60}
61
62#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
64#[serde(tag = "type")]
65#[serde(rename_all = "snake_case")]
66pub enum MentionObject {
67 User {
68 user: User,
69 },
70 Page {
72 page: Page,
73 },
74 Database {
76 database: Database,
77 },
78 Date {
79 date: DateValue,
80 },
81 #[serde(other)]
86 Unknown,
87}
88
89#[derive(Serialize, Deserialize, Debug, Eq, PartialEq, Clone)]
94#[serde(tag = "type")]
95#[serde(rename_all = "snake_case")]
96pub enum RichText {
97 Text {
99 #[serde(flatten)]
100 rich_text: RichTextCommon,
101 text: Text,
102 },
103 Mention {
105 #[serde(flatten)]
106 rich_text: RichTextCommon,
107 mention: MentionObject,
108 },
109 Equation {
111 #[serde(flatten)]
112 rich_text: RichTextCommon,
113 },
114}
115
116impl RichText {
117 pub fn plain_text(&self) -> &str {
118 use RichText::*;
119 match self {
120 Text { rich_text, .. } | Mention { rich_text, .. } | Equation { rich_text, .. } => {
121 &rich_text.plain_text
122 }
123 }
124 }
125}