jmap_client/vacation_response/
mod.rs

1/*
2 * Copyright Stalwart Labs LLC See the COPYING
3 * file at the top-level directory of this distribution.
4 *
5 * Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 * https://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 * <LICENSE-MIT or https://opensource.org/licenses/MIT>, at your
8 * option. This file may not be copied, modified, or distributed
9 * except according to those terms.
10 */
11
12pub mod get;
13pub mod helpers;
14pub mod set;
15
16use std::fmt::Display;
17
18use crate::core::changes::ChangesObject;
19use crate::core::set::date_not_set;
20use crate::core::set::string_not_set;
21use crate::core::Object;
22use crate::Get;
23use crate::Set;
24use chrono::{DateTime, Utc};
25use serde::{Deserialize, Serialize};
26
27#[derive(Debug, Clone, Serialize, Deserialize)]
28pub struct VacationResponse<State = Get> {
29    #[serde(skip)]
30    _create_id: Option<usize>,
31
32    #[serde(skip)]
33    _state: std::marker::PhantomData<State>,
34
35    #[serde(rename = "id")]
36    #[serde(skip_serializing_if = "Option::is_none")]
37    id: Option<String>,
38
39    #[serde(rename = "isEnabled")]
40    #[serde(skip_serializing_if = "Option::is_none")]
41    is_enabled: Option<bool>,
42
43    #[serde(rename = "fromDate")]
44    #[serde(skip_serializing_if = "date_not_set")]
45    from_date: Option<DateTime<Utc>>,
46
47    #[serde(rename = "toDate")]
48    #[serde(skip_serializing_if = "date_not_set")]
49    to_date: Option<DateTime<Utc>>,
50
51    #[serde(rename = "subject")]
52    #[serde(skip_serializing_if = "string_not_set")]
53    subject: Option<String>,
54
55    #[serde(rename = "textBody")]
56    #[serde(skip_serializing_if = "string_not_set")]
57    text_body: Option<String>,
58
59    #[serde(rename = "htmlBody")]
60    #[serde(skip_serializing_if = "string_not_set")]
61    html_body: Option<String>,
62}
63
64#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash, Copy)]
65pub enum Property {
66    #[serde(rename = "id")]
67    Id,
68    #[serde(rename = "isEnabled")]
69    IsEnabled,
70    #[serde(rename = "fromDate")]
71    FromDate,
72    #[serde(rename = "toDate")]
73    ToDate,
74    #[serde(rename = "subject")]
75    Subject,
76    #[serde(rename = "textBody")]
77    TextBody,
78    #[serde(rename = "htmlBody")]
79    HtmlBody,
80}
81
82impl Display for Property {
83    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
84        match self {
85            Property::Id => write!(f, "id"),
86            Property::IsEnabled => write!(f, "isEnabled"),
87            Property::FromDate => write!(f, "fromDate"),
88            Property::ToDate => write!(f, "toDate"),
89            Property::Subject => write!(f, "subject"),
90            Property::TextBody => write!(f, "textBody"),
91            Property::HtmlBody => write!(f, "htmlBody"),
92        }
93    }
94}
95
96impl Object for VacationResponse<Set> {
97    type Property = Property;
98
99    fn requires_account_id() -> bool {
100        true
101    }
102}
103
104impl Object for VacationResponse<Get> {
105    type Property = Property;
106
107    fn requires_account_id() -> bool {
108        true
109    }
110}
111
112impl ChangesObject for VacationResponse<Set> {
113    type ChangesResponse = ();
114}
115
116impl ChangesObject for VacationResponse<Get> {
117    type ChangesResponse = ();
118}