rust_tdlib/types/
authentication_code_type.rs1use crate::errors::Result;
2use crate::types::*;
3use uuid::Uuid;
4
5use std::fmt::Debug;
6
7pub trait TDAuthenticationCodeType: Debug + RObject {}
9
10#[derive(Debug, Clone, Deserialize, Serialize, Default)]
12#[serde(tag = "@type")]
13pub enum AuthenticationCodeType {
14 #[doc(hidden)]
15 #[default]
16 _Default,
17 #[serde(rename = "authenticationCodeTypeCall")]
19 Call(AuthenticationCodeTypeCall),
20 #[serde(rename = "authenticationCodeTypeFlashCall")]
22 FlashCall(AuthenticationCodeTypeFlashCall),
23 #[serde(rename = "authenticationCodeTypeMissedCall")]
25 MissedCall(AuthenticationCodeTypeMissedCall),
26 #[serde(rename = "authenticationCodeTypeSms")]
28 Sms(AuthenticationCodeTypeSms),
29 #[serde(rename = "authenticationCodeTypeTelegramMessage")]
31 TelegramMessage(AuthenticationCodeTypeTelegramMessage),
32}
33
34impl RObject for AuthenticationCodeType {
35 #[doc(hidden)]
36 fn extra(&self) -> Option<&str> {
37 match self {
38 AuthenticationCodeType::Call(t) => t.extra(),
39 AuthenticationCodeType::FlashCall(t) => t.extra(),
40 AuthenticationCodeType::MissedCall(t) => t.extra(),
41 AuthenticationCodeType::Sms(t) => t.extra(),
42 AuthenticationCodeType::TelegramMessage(t) => t.extra(),
43
44 _ => None,
45 }
46 }
47 #[doc(hidden)]
48 fn client_id(&self) -> Option<i32> {
49 match self {
50 AuthenticationCodeType::Call(t) => t.client_id(),
51 AuthenticationCodeType::FlashCall(t) => t.client_id(),
52 AuthenticationCodeType::MissedCall(t) => t.client_id(),
53 AuthenticationCodeType::Sms(t) => t.client_id(),
54 AuthenticationCodeType::TelegramMessage(t) => t.client_id(),
55
56 _ => None,
57 }
58 }
59}
60
61impl AuthenticationCodeType {
62 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
63 Ok(serde_json::from_str(json.as_ref())?)
64 }
65 #[doc(hidden)]
66 pub fn _is_default(&self) -> bool {
67 matches!(self, AuthenticationCodeType::_Default)
68 }
69}
70
71impl AsRef<AuthenticationCodeType> for AuthenticationCodeType {
72 fn as_ref(&self) -> &AuthenticationCodeType {
73 self
74 }
75}
76
77#[derive(Debug, Clone, Default, Serialize, Deserialize)]
79pub struct AuthenticationCodeTypeCall {
80 #[doc(hidden)]
81 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
82 extra: Option<String>,
83 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
84 client_id: Option<i32>,
85 #[serde(default)]
88 length: i32,
89}
90
91impl RObject for AuthenticationCodeTypeCall {
92 #[doc(hidden)]
93 fn extra(&self) -> Option<&str> {
94 self.extra.as_deref()
95 }
96 #[doc(hidden)]
97 fn client_id(&self) -> Option<i32> {
98 self.client_id
99 }
100}
101
102impl TDAuthenticationCodeType for AuthenticationCodeTypeCall {}
103
104impl AuthenticationCodeTypeCall {
105 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
106 Ok(serde_json::from_str(json.as_ref())?)
107 }
108 pub fn builder() -> AuthenticationCodeTypeCallBuilder {
109 let mut inner = AuthenticationCodeTypeCall::default();
110 inner.extra = Some(Uuid::new_v4().to_string());
111
112 AuthenticationCodeTypeCallBuilder { inner }
113 }
114
115 pub fn length(&self) -> i32 {
116 self.length
117 }
118}
119
120#[doc(hidden)]
121pub struct AuthenticationCodeTypeCallBuilder {
122 inner: AuthenticationCodeTypeCall,
123}
124
125#[deprecated]
126pub type RTDAuthenticationCodeTypeCallBuilder = AuthenticationCodeTypeCallBuilder;
127
128impl AuthenticationCodeTypeCallBuilder {
129 pub fn build(&self) -> AuthenticationCodeTypeCall {
130 self.inner.clone()
131 }
132
133 pub fn length(&mut self, length: i32) -> &mut Self {
134 self.inner.length = length;
135 self
136 }
137}
138
139impl AsRef<AuthenticationCodeTypeCall> for AuthenticationCodeTypeCall {
140 fn as_ref(&self) -> &AuthenticationCodeTypeCall {
141 self
142 }
143}
144
145impl AsRef<AuthenticationCodeTypeCall> for AuthenticationCodeTypeCallBuilder {
146 fn as_ref(&self) -> &AuthenticationCodeTypeCall {
147 &self.inner
148 }
149}
150
151#[derive(Debug, Clone, Default, Serialize, Deserialize)]
153pub struct AuthenticationCodeTypeFlashCall {
154 #[doc(hidden)]
155 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
156 extra: Option<String>,
157 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
158 client_id: Option<i32>,
159 #[serde(default)]
162 pattern: String,
163}
164
165impl RObject for AuthenticationCodeTypeFlashCall {
166 #[doc(hidden)]
167 fn extra(&self) -> Option<&str> {
168 self.extra.as_deref()
169 }
170 #[doc(hidden)]
171 fn client_id(&self) -> Option<i32> {
172 self.client_id
173 }
174}
175
176impl TDAuthenticationCodeType for AuthenticationCodeTypeFlashCall {}
177
178impl AuthenticationCodeTypeFlashCall {
179 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
180 Ok(serde_json::from_str(json.as_ref())?)
181 }
182 pub fn builder() -> AuthenticationCodeTypeFlashCallBuilder {
183 let mut inner = AuthenticationCodeTypeFlashCall::default();
184 inner.extra = Some(Uuid::new_v4().to_string());
185
186 AuthenticationCodeTypeFlashCallBuilder { inner }
187 }
188
189 pub fn pattern(&self) -> &String {
190 &self.pattern
191 }
192}
193
194#[doc(hidden)]
195pub struct AuthenticationCodeTypeFlashCallBuilder {
196 inner: AuthenticationCodeTypeFlashCall,
197}
198
199#[deprecated]
200pub type RTDAuthenticationCodeTypeFlashCallBuilder = AuthenticationCodeTypeFlashCallBuilder;
201
202impl AuthenticationCodeTypeFlashCallBuilder {
203 pub fn build(&self) -> AuthenticationCodeTypeFlashCall {
204 self.inner.clone()
205 }
206
207 pub fn pattern<T: AsRef<str>>(&mut self, pattern: T) -> &mut Self {
208 self.inner.pattern = pattern.as_ref().to_string();
209 self
210 }
211}
212
213impl AsRef<AuthenticationCodeTypeFlashCall> for AuthenticationCodeTypeFlashCall {
214 fn as_ref(&self) -> &AuthenticationCodeTypeFlashCall {
215 self
216 }
217}
218
219impl AsRef<AuthenticationCodeTypeFlashCall> for AuthenticationCodeTypeFlashCallBuilder {
220 fn as_ref(&self) -> &AuthenticationCodeTypeFlashCall {
221 &self.inner
222 }
223}
224
225#[derive(Debug, Clone, Default, Serialize, Deserialize)]
227pub struct AuthenticationCodeTypeMissedCall {
228 #[doc(hidden)]
229 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
230 extra: Option<String>,
231 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
232 client_id: Option<i32>,
233 #[serde(default)]
236 phone_number_prefix: String,
237 #[serde(default)]
240 length: i32,
241}
242
243impl RObject for AuthenticationCodeTypeMissedCall {
244 #[doc(hidden)]
245 fn extra(&self) -> Option<&str> {
246 self.extra.as_deref()
247 }
248 #[doc(hidden)]
249 fn client_id(&self) -> Option<i32> {
250 self.client_id
251 }
252}
253
254impl TDAuthenticationCodeType for AuthenticationCodeTypeMissedCall {}
255
256impl AuthenticationCodeTypeMissedCall {
257 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
258 Ok(serde_json::from_str(json.as_ref())?)
259 }
260 pub fn builder() -> AuthenticationCodeTypeMissedCallBuilder {
261 let mut inner = AuthenticationCodeTypeMissedCall::default();
262 inner.extra = Some(Uuid::new_v4().to_string());
263
264 AuthenticationCodeTypeMissedCallBuilder { inner }
265 }
266
267 pub fn phone_number_prefix(&self) -> &String {
268 &self.phone_number_prefix
269 }
270
271 pub fn length(&self) -> i32 {
272 self.length
273 }
274}
275
276#[doc(hidden)]
277pub struct AuthenticationCodeTypeMissedCallBuilder {
278 inner: AuthenticationCodeTypeMissedCall,
279}
280
281#[deprecated]
282pub type RTDAuthenticationCodeTypeMissedCallBuilder = AuthenticationCodeTypeMissedCallBuilder;
283
284impl AuthenticationCodeTypeMissedCallBuilder {
285 pub fn build(&self) -> AuthenticationCodeTypeMissedCall {
286 self.inner.clone()
287 }
288
289 pub fn phone_number_prefix<T: AsRef<str>>(&mut self, phone_number_prefix: T) -> &mut Self {
290 self.inner.phone_number_prefix = phone_number_prefix.as_ref().to_string();
291 self
292 }
293
294 pub fn length(&mut self, length: i32) -> &mut Self {
295 self.inner.length = length;
296 self
297 }
298}
299
300impl AsRef<AuthenticationCodeTypeMissedCall> for AuthenticationCodeTypeMissedCall {
301 fn as_ref(&self) -> &AuthenticationCodeTypeMissedCall {
302 self
303 }
304}
305
306impl AsRef<AuthenticationCodeTypeMissedCall> for AuthenticationCodeTypeMissedCallBuilder {
307 fn as_ref(&self) -> &AuthenticationCodeTypeMissedCall {
308 &self.inner
309 }
310}
311
312#[derive(Debug, Clone, Default, Serialize, Deserialize)]
314pub struct AuthenticationCodeTypeSms {
315 #[doc(hidden)]
316 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
317 extra: Option<String>,
318 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
319 client_id: Option<i32>,
320 #[serde(default)]
323 length: i32,
324}
325
326impl RObject for AuthenticationCodeTypeSms {
327 #[doc(hidden)]
328 fn extra(&self) -> Option<&str> {
329 self.extra.as_deref()
330 }
331 #[doc(hidden)]
332 fn client_id(&self) -> Option<i32> {
333 self.client_id
334 }
335}
336
337impl TDAuthenticationCodeType for AuthenticationCodeTypeSms {}
338
339impl AuthenticationCodeTypeSms {
340 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
341 Ok(serde_json::from_str(json.as_ref())?)
342 }
343 pub fn builder() -> AuthenticationCodeTypeSmsBuilder {
344 let mut inner = AuthenticationCodeTypeSms::default();
345 inner.extra = Some(Uuid::new_v4().to_string());
346
347 AuthenticationCodeTypeSmsBuilder { inner }
348 }
349
350 pub fn length(&self) -> i32 {
351 self.length
352 }
353}
354
355#[doc(hidden)]
356pub struct AuthenticationCodeTypeSmsBuilder {
357 inner: AuthenticationCodeTypeSms,
358}
359
360#[deprecated]
361pub type RTDAuthenticationCodeTypeSmsBuilder = AuthenticationCodeTypeSmsBuilder;
362
363impl AuthenticationCodeTypeSmsBuilder {
364 pub fn build(&self) -> AuthenticationCodeTypeSms {
365 self.inner.clone()
366 }
367
368 pub fn length(&mut self, length: i32) -> &mut Self {
369 self.inner.length = length;
370 self
371 }
372}
373
374impl AsRef<AuthenticationCodeTypeSms> for AuthenticationCodeTypeSms {
375 fn as_ref(&self) -> &AuthenticationCodeTypeSms {
376 self
377 }
378}
379
380impl AsRef<AuthenticationCodeTypeSms> for AuthenticationCodeTypeSmsBuilder {
381 fn as_ref(&self) -> &AuthenticationCodeTypeSms {
382 &self.inner
383 }
384}
385
386#[derive(Debug, Clone, Default, Serialize, Deserialize)]
388pub struct AuthenticationCodeTypeTelegramMessage {
389 #[doc(hidden)]
390 #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
391 extra: Option<String>,
392 #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
393 client_id: Option<i32>,
394 #[serde(default)]
397 length: i32,
398}
399
400impl RObject for AuthenticationCodeTypeTelegramMessage {
401 #[doc(hidden)]
402 fn extra(&self) -> Option<&str> {
403 self.extra.as_deref()
404 }
405 #[doc(hidden)]
406 fn client_id(&self) -> Option<i32> {
407 self.client_id
408 }
409}
410
411impl TDAuthenticationCodeType for AuthenticationCodeTypeTelegramMessage {}
412
413impl AuthenticationCodeTypeTelegramMessage {
414 pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
415 Ok(serde_json::from_str(json.as_ref())?)
416 }
417 pub fn builder() -> AuthenticationCodeTypeTelegramMessageBuilder {
418 let mut inner = AuthenticationCodeTypeTelegramMessage::default();
419 inner.extra = Some(Uuid::new_v4().to_string());
420
421 AuthenticationCodeTypeTelegramMessageBuilder { inner }
422 }
423
424 pub fn length(&self) -> i32 {
425 self.length
426 }
427}
428
429#[doc(hidden)]
430pub struct AuthenticationCodeTypeTelegramMessageBuilder {
431 inner: AuthenticationCodeTypeTelegramMessage,
432}
433
434#[deprecated]
435pub type RTDAuthenticationCodeTypeTelegramMessageBuilder =
436 AuthenticationCodeTypeTelegramMessageBuilder;
437
438impl AuthenticationCodeTypeTelegramMessageBuilder {
439 pub fn build(&self) -> AuthenticationCodeTypeTelegramMessage {
440 self.inner.clone()
441 }
442
443 pub fn length(&mut self, length: i32) -> &mut Self {
444 self.inner.length = length;
445 self
446 }
447}
448
449impl AsRef<AuthenticationCodeTypeTelegramMessage> for AuthenticationCodeTypeTelegramMessage {
450 fn as_ref(&self) -> &AuthenticationCodeTypeTelegramMessage {
451 self
452 }
453}
454
455impl AsRef<AuthenticationCodeTypeTelegramMessage> for AuthenticationCodeTypeTelegramMessageBuilder {
456 fn as_ref(&self) -> &AuthenticationCodeTypeTelegramMessage {
457 &self.inner
458 }
459}