notionrs_schema/object/page/
verification.rs1use serde::{Deserialize, Serialize};
2
3#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default, notionrs_macro::Setter)]
18pub struct PageVerificationProperty {
19 #[serde(skip_serializing)]
20 pub id: Option<String>,
21
22 pub verification: PageVerificationPropertyParameter,
23}
24
25#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default, notionrs_macro::Setter)]
26pub struct PageVerificationPropertyParameter {
27 pub state: PageVerificationState,
29
30 pub verified_by: Option<crate::object::user::User>,
31
32 pub date: Option<PageVerificationDate>,
33}
34
35#[derive(Debug, Deserialize, Serialize, Clone, Copy, Default, PartialEq)]
36#[serde(rename_all = "lowercase")]
37pub enum PageVerificationState {
38 Verified,
39 #[default]
40 Unverified,
41 Expired,
42}
43
44#[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Default, notionrs_macro::Setter)]
45pub struct PageVerificationDate {
46 pub start: Option<crate::object::date::DateOrDateTime>,
48
49 pub end: Option<crate::object::date::DateOrDateTime>,
52
53 #[serde(skip_deserializing)]
55 pub time_zone: Option<String>,
56}
57
58impl PageVerificationProperty {
59 pub fn state(&mut self, state: PageVerificationState) -> &mut Self {
60 self.verification.state = state;
61 self
62 }
63
64 pub fn verified_by(&mut self, verified_by: crate::object::user::User) -> &mut Self {
65 self.verification.verified_by = Some(verified_by);
66 self
67 }
68
69 pub fn date(&mut self, date: PageVerificationDate) -> &mut Self {
70 self.verification.date = Some(date);
71 self
72 }
73}
74
75impl std::fmt::Display for PageVerificationProperty {
76 fn fmt(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
77 write!(
78 f,
79 "{}",
80 match self.verification.state {
81 PageVerificationState::Verified => "verified",
82 PageVerificationState::Unverified => "unverified",
83 PageVerificationState::Expired => "expired",
84 }
85 )
86 }
87}
88
89#[cfg(test)]
96mod unit_tests {
97 use super::*;
98
99 #[test]
100 fn deserialize_page_verification_property() {
101 let json_data = r#"
102 {
103 "id": "%3DP%7CC",
104 "type": "verification",
105 "verification": {
106 "state": "verified",
107 "verified_by": {
108 "object": "user",
109 "id": "174984bc-2b3e-408f-97fd-fa5ff989e907",
110 "name": "<masked>",
111 "avatar_url": "https://example.com/",
112 "type": "person",
113 "person": {
114 "email": "<masked>@example.com"
115 }
116 },
117 "date": {
118 "start": "2024-12-11T15:00:00.000Z",
119 "end": "2024-12-18T15:00:00.000Z",
120 "time_zone": null
121 }
122 }
123 }
124 "#;
125
126 let page_verification: PageVerificationProperty = serde_json::from_str(json_data).unwrap();
127
128 assert_eq!(
129 page_verification.verification.state,
130 PageVerificationState::Verified
131 );
132 }
133}