nullnet_libdatastore/builders/
register_device_request_builder.rs1use crate::datastore::{RegisterDeviceParams, RegisterDeviceRequest};
2
3#[derive(Debug, Default)]
4pub struct RegisterDeviceRequestBuilder {
5 pub categories: Vec<String>,
6 pub organization_id: Option<String>,
7 pub account_id: Option<String>,
8 pub account_secret: Option<String>,
9 pub is_new_user: bool,
10 pub is_invited: bool,
11 pub role_id: Option<String>,
12 pub account_organization_status: Option<String>,
13 pub account_organization_categories: Vec<String>,
14 pub device_categories: Vec<String>,
15 pub device_id: Option<String>,
16}
17
18impl RegisterDeviceRequestBuilder {
19 pub fn new() -> Self {
20 Self::default()
21 }
22
23 pub fn device_id(mut self, device_id: impl Into<String>) -> Self {
24 self.device_id = Some(device_id.into());
25 self
26 }
27
28 pub fn add_category(mut self, category: impl Into<String>) -> Self {
29 self.categories.push(category.into());
30 self
31 }
32
33 pub fn organization_id(mut self, id: impl Into<String>) -> Self {
34 self.organization_id = Some(id.into());
35 self
36 }
37
38 pub fn account_id(mut self, id: impl Into<String>) -> Self {
39 self.account_id = Some(id.into());
40 self
41 }
42
43 pub fn account_secret(mut self, secret: impl Into<String>) -> Self {
44 self.account_secret = Some(secret.into());
45 self
46 }
47
48 pub fn set_is_new_user(mut self, flag: bool) -> Self {
49 self.is_new_user = flag;
50 self
51 }
52
53 pub fn set_is_invited(mut self, flag: bool) -> Self {
54 self.is_invited = flag;
55 self
56 }
57
58 pub fn role_id(mut self, id: impl Into<String>) -> Self {
59 self.role_id = Some(id.into());
60 self
61 }
62
63 pub fn account_organization_status(mut self, status: impl Into<String>) -> Self {
64 self.account_organization_status = Some(status.into());
65 self
66 }
67
68 pub fn add_account_organization_category(mut self, category: impl Into<String>) -> Self {
69 self.account_organization_categories.push(category.into());
70 self
71 }
72
73 pub fn add_device_category(mut self, category: impl Into<String>) -> Self {
74 self.device_categories.push(category.into());
75 self
76 }
77
78 pub fn build(self) -> RegisterDeviceRequest {
79 RegisterDeviceRequest {
80 device: Some(RegisterDeviceParams {
81 organization_id: self.organization_id.unwrap_or_default(),
82 account_id: self.account_id.unwrap_or_default(),
83 account_secret: self.account_secret.unwrap_or_default(),
84 is_new_user: self.is_new_user,
85 is_invited: self.is_invited,
86 role_id: self.role_id.unwrap_or_default(),
87 account_organization_status: self.account_organization_status.unwrap_or_default(),
88 account_organization_categories: self.account_organization_categories,
89 device_categories: self.device_categories,
90 device_id: self.device_id.unwrap_or_default(),
91 }),
92 }
93 }
94}