Skip to main content

brevo_rust/api/types/
task.rs

1pub use crate::prelude::*;
2
3/// Task Details
4#[derive(Debug, Clone, Serialize, Deserialize, Default, PartialEq, Eq, Hash)]
5pub struct Task {
6    /// Unique task id
7    #[serde(skip_serializing_if = "Option::is_none")]
8    pub id: Option<String>,
9    /// Id for type of task e.g Call / Email / Meeting etc.
10    #[serde(rename = "taskTypeId")]
11    #[serde(default)]
12    pub task_type_id: String,
13    /// Name of task
14    #[serde(default)]
15    pub name: String,
16    /// Companies ids for companies a task is linked to
17    #[serde(rename = "companiesIds")]
18    #[serde(skip_serializing_if = "Option::is_none")]
19    pub companies_ids: Option<Vec<String>>,
20    /// Deal ids for deals a task is linked to
21    #[serde(rename = "dealsIds")]
22    #[serde(skip_serializing_if = "Option::is_none")]
23    pub deals_ids: Option<Vec<String>>,
24    /// Contact ids for contacts linked to this task
25    #[serde(rename = "contactsIds")]
26    #[serde(skip_serializing_if = "Option::is_none")]
27    pub contacts_ids: Option<Vec<i64>>,
28    /// Account id of the user assigned to this task
29    #[serde(rename = "assignToId")]
30    #[serde(skip_serializing_if = "Option::is_none")]
31    pub assign_to_id: Option<String>,
32    /// Task due date and time
33    #[serde(default)]
34    #[serde(with = "crate::core::flexible_datetime::offset")]
35    pub date: DateTime<FixedOffset>,
36    /// Notes added to a task
37    #[serde(skip_serializing_if = "Option::is_none")]
38    pub notes: Option<String>,
39    /// Whether the task is marked as done
40    #[serde(skip_serializing_if = "Option::is_none")]
41    pub done: Option<bool>,
42    /// Task creation date/time
43    #[serde(rename = "createdAt")]
44    #[serde(skip_serializing_if = "Option::is_none")]
45    #[serde(default)]
46    #[serde(with = "crate::core::flexible_datetime::offset::option")]
47    pub created_at: Option<DateTime<FixedOffset>>,
48    /// Task last update date/time
49    #[serde(rename = "updatedAt")]
50    #[serde(skip_serializing_if = "Option::is_none")]
51    #[serde(default)]
52    #[serde(with = "crate::core::flexible_datetime::offset::option")]
53    pub updated_at: Option<DateTime<FixedOffset>>,
54}
55
56impl Task {
57    pub fn builder() -> TaskBuilder {
58        <TaskBuilder as Default>::default()
59    }
60}
61
62#[derive(Clone, PartialEq, Default, Debug)]
63#[non_exhaustive]
64pub struct TaskBuilder {
65    id: Option<String>,
66    task_type_id: Option<String>,
67    name: Option<String>,
68    companies_ids: Option<Vec<String>>,
69    deals_ids: Option<Vec<String>>,
70    contacts_ids: Option<Vec<i64>>,
71    assign_to_id: Option<String>,
72    date: Option<DateTime<FixedOffset>>,
73    notes: Option<String>,
74    done: Option<bool>,
75    created_at: Option<DateTime<FixedOffset>>,
76    updated_at: Option<DateTime<FixedOffset>>,
77}
78
79impl TaskBuilder {
80    pub fn id(mut self, value: impl Into<String>) -> Self {
81        self.id = Some(value.into());
82        self
83    }
84
85    pub fn task_type_id(mut self, value: impl Into<String>) -> Self {
86        self.task_type_id = Some(value.into());
87        self
88    }
89
90    pub fn name(mut self, value: impl Into<String>) -> Self {
91        self.name = Some(value.into());
92        self
93    }
94
95    pub fn companies_ids(mut self, value: Vec<String>) -> Self {
96        self.companies_ids = Some(value);
97        self
98    }
99
100    pub fn deals_ids(mut self, value: Vec<String>) -> Self {
101        self.deals_ids = Some(value);
102        self
103    }
104
105    pub fn contacts_ids(mut self, value: Vec<i64>) -> Self {
106        self.contacts_ids = Some(value);
107        self
108    }
109
110    pub fn assign_to_id(mut self, value: impl Into<String>) -> Self {
111        self.assign_to_id = Some(value.into());
112        self
113    }
114
115    pub fn date(mut self, value: DateTime<FixedOffset>) -> Self {
116        self.date = Some(value);
117        self
118    }
119
120    pub fn notes(mut self, value: impl Into<String>) -> Self {
121        self.notes = Some(value.into());
122        self
123    }
124
125    pub fn done(mut self, value: bool) -> Self {
126        self.done = Some(value);
127        self
128    }
129
130    pub fn created_at(mut self, value: DateTime<FixedOffset>) -> Self {
131        self.created_at = Some(value);
132        self
133    }
134
135    pub fn updated_at(mut self, value: DateTime<FixedOffset>) -> Self {
136        self.updated_at = Some(value);
137        self
138    }
139
140    /// Consumes the builder and constructs a [`Task`].
141    /// This method will fail if any of the following fields are not set:
142    /// - [`task_type_id`](TaskBuilder::task_type_id)
143    /// - [`name`](TaskBuilder::name)
144    /// - [`date`](TaskBuilder::date)
145    pub fn build(self) -> Result<Task, BuildError> {
146        Ok(Task {
147            id: self.id,
148            task_type_id: self
149                .task_type_id
150                .ok_or_else(|| BuildError::missing_field("task_type_id"))?,
151            name: self.name.ok_or_else(|| BuildError::missing_field("name"))?,
152            companies_ids: self.companies_ids,
153            deals_ids: self.deals_ids,
154            contacts_ids: self.contacts_ids,
155            assign_to_id: self.assign_to_id,
156            date: self.date.ok_or_else(|| BuildError::missing_field("date"))?,
157            notes: self.notes,
158            done: self.done,
159            created_at: self.created_at,
160            updated_at: self.updated_at,
161        })
162    }
163}