jmap_client/vacation_response/
set.rs

1/*
2 * Copyright Stalwart Labs Ltd. 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
12use crate::{
13    core::set::{from_timestamp, SetObject},
14    Get, Set,
15};
16
17use super::VacationResponse;
18
19impl VacationResponse<Set> {
20    pub fn is_enabled(&mut self, is_enabled: bool) -> &mut Self {
21        self.is_enabled = Some(is_enabled);
22        self
23    }
24
25    pub fn from_date(&mut self, from_date: Option<i64>) -> &mut Self {
26        self.from_date = from_date.map(from_timestamp);
27        self
28    }
29
30    pub fn to_date(&mut self, to_date: Option<i64>) -> &mut Self {
31        self.to_date = to_date.map(from_timestamp);
32        self
33    }
34
35    pub fn subject(&mut self, subject: Option<impl Into<String>>) -> &mut Self {
36        self.subject = subject.map(|s| s.into());
37        self
38    }
39
40    pub fn text_body(&mut self, text_body: Option<impl Into<String>>) -> &mut Self {
41        self.text_body = text_body.map(|s| s.into());
42        self
43    }
44
45    pub fn html_body(&mut self, html_body: Option<impl Into<String>>) -> &mut Self {
46        self.html_body = html_body.map(|s| s.into());
47        self
48    }
49}
50
51impl SetObject for VacationResponse<Set> {
52    type SetArguments = ();
53
54    fn new(_create_id: Option<usize>) -> Self {
55        VacationResponse {
56            _create_id,
57            _state: Default::default(),
58            id: None,
59            is_enabled: None,
60            from_date: from_timestamp(0).into(),
61            to_date: from_timestamp(0).into(),
62            subject: "".to_string().into(),
63            text_body: "".to_string().into(),
64            html_body: "".to_string().into(),
65        }
66    }
67
68    fn create_id(&self) -> Option<String> {
69        self._create_id.map(|id| format!("c{}", id))
70    }
71}
72
73impl SetObject for VacationResponse<Get> {
74    type SetArguments = ();
75
76    fn new(_create_id: Option<usize>) -> Self {
77        unimplemented!()
78    }
79
80    fn create_id(&self) -> Option<String> {
81        None
82    }
83}