1
2use crate::types::*;
3use crate::errors::*;
4use uuid::Uuid;
5
6
7
8
9#[derive(Debug, Clone, Default, Serialize, Deserialize)]
11pub struct Session {
12 #[doc(hidden)]
13 #[serde(rename(serialize = "@type", deserialize = "@type"))]
14 td_name: String,
15 #[doc(hidden)]
16 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
17 extra: Option<String>,
18 id: isize,
20 is_current: bool,
22 is_password_pending: bool,
24 can_accept_secret_chats: bool,
26 can_accept_calls: bool,
28 api_id: i64,
30 application_name: String,
32 application_version: String,
34 is_official_application: bool,
36 device_model: String,
38 platform: String,
40 system_version: String,
42 log_in_date: i64,
44 last_active_date: i64,
46 ip: String,
48 country: String,
50 region: String,
52
53}
54
55impl RObject for Session {
56 #[doc(hidden)] fn td_name(&self) -> &'static str { "session" }
57 #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
58 fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
59}
60
61
62
63impl Session {
64 pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
65 pub fn builder() -> RTDSessionBuilder {
66 let mut inner = Session::default();
67 inner.td_name = "session".to_string();
68 inner.extra = Some(Uuid::new_v4().to_string());
69 RTDSessionBuilder { inner }
70 }
71
72 pub fn id(&self) -> isize { self.id }
73
74 pub fn is_current(&self) -> bool { self.is_current }
75
76 pub fn is_password_pending(&self) -> bool { self.is_password_pending }
77
78 pub fn can_accept_secret_chats(&self) -> bool { self.can_accept_secret_chats }
79
80 pub fn can_accept_calls(&self) -> bool { self.can_accept_calls }
81
82 pub fn api_id(&self) -> i64 { self.api_id }
83
84 pub fn application_name(&self) -> &String { &self.application_name }
85
86 pub fn application_version(&self) -> &String { &self.application_version }
87
88 pub fn is_official_application(&self) -> bool { self.is_official_application }
89
90 pub fn device_model(&self) -> &String { &self.device_model }
91
92 pub fn platform(&self) -> &String { &self.platform }
93
94 pub fn system_version(&self) -> &String { &self.system_version }
95
96 pub fn log_in_date(&self) -> i64 { self.log_in_date }
97
98 pub fn last_active_date(&self) -> i64 { self.last_active_date }
99
100 pub fn ip(&self) -> &String { &self.ip }
101
102 pub fn country(&self) -> &String { &self.country }
103
104 pub fn region(&self) -> &String { &self.region }
105
106}
107
108#[doc(hidden)]
109pub struct RTDSessionBuilder {
110 inner: Session
111}
112
113impl RTDSessionBuilder {
114 pub fn build(&self) -> Session { self.inner.clone() }
115
116
117 pub fn id(&mut self, id: isize) -> &mut Self {
118 self.inner.id = id;
119 self
120 }
121
122
123 pub fn is_current(&mut self, is_current: bool) -> &mut Self {
124 self.inner.is_current = is_current;
125 self
126 }
127
128
129 pub fn is_password_pending(&mut self, is_password_pending: bool) -> &mut Self {
130 self.inner.is_password_pending = is_password_pending;
131 self
132 }
133
134
135 pub fn can_accept_secret_chats(&mut self, can_accept_secret_chats: bool) -> &mut Self {
136 self.inner.can_accept_secret_chats = can_accept_secret_chats;
137 self
138 }
139
140
141 pub fn can_accept_calls(&mut self, can_accept_calls: bool) -> &mut Self {
142 self.inner.can_accept_calls = can_accept_calls;
143 self
144 }
145
146
147 pub fn api_id(&mut self, api_id: i64) -> &mut Self {
148 self.inner.api_id = api_id;
149 self
150 }
151
152
153 pub fn application_name<T: AsRef<str>>(&mut self, application_name: T) -> &mut Self {
154 self.inner.application_name = application_name.as_ref().to_string();
155 self
156 }
157
158
159 pub fn application_version<T: AsRef<str>>(&mut self, application_version: T) -> &mut Self {
160 self.inner.application_version = application_version.as_ref().to_string();
161 self
162 }
163
164
165 pub fn is_official_application(&mut self, is_official_application: bool) -> &mut Self {
166 self.inner.is_official_application = is_official_application;
167 self
168 }
169
170
171 pub fn device_model<T: AsRef<str>>(&mut self, device_model: T) -> &mut Self {
172 self.inner.device_model = device_model.as_ref().to_string();
173 self
174 }
175
176
177 pub fn platform<T: AsRef<str>>(&mut self, platform: T) -> &mut Self {
178 self.inner.platform = platform.as_ref().to_string();
179 self
180 }
181
182
183 pub fn system_version<T: AsRef<str>>(&mut self, system_version: T) -> &mut Self {
184 self.inner.system_version = system_version.as_ref().to_string();
185 self
186 }
187
188
189 pub fn log_in_date(&mut self, log_in_date: i64) -> &mut Self {
190 self.inner.log_in_date = log_in_date;
191 self
192 }
193
194
195 pub fn last_active_date(&mut self, last_active_date: i64) -> &mut Self {
196 self.inner.last_active_date = last_active_date;
197 self
198 }
199
200
201 pub fn ip<T: AsRef<str>>(&mut self, ip: T) -> &mut Self {
202 self.inner.ip = ip.as_ref().to_string();
203 self
204 }
205
206
207 pub fn country<T: AsRef<str>>(&mut self, country: T) -> &mut Self {
208 self.inner.country = country.as_ref().to_string();
209 self
210 }
211
212
213 pub fn region<T: AsRef<str>>(&mut self, region: T) -> &mut Self {
214 self.inner.region = region.as_ref().to_string();
215 self
216 }
217
218}
219
220impl AsRef<Session> for Session {
221 fn as_ref(&self) -> &Session { self }
222}
223
224impl AsRef<Session> for RTDSessionBuilder {
225 fn as_ref(&self) -> &Session { &self.inner }
226}
227
228
229