1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372

use crate::types::*;
use crate::errors::*;




use std::fmt::Debug;
use serde::de::{Deserialize, Deserializer};



/// TRAIT | Describes the type of a chat
pub trait TDChatType: Debug + RObject {}

/// Describes the type of a chat
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum ChatType {
  #[doc(hidden)] _Default(()),
  /// An ordinary chat with a user
  Private(ChatTypePrivate),
  /// A basic group (i.e., a chat with 0-200 other users)
  BasicGroup(ChatTypeBasicGroup),
  /// A supergroup (i.e. a chat with up to GetOption("supergroup_max_size") other users), or channel (with unlimited members)
  Supergroup(ChatTypeSupergroup),
  /// A secret chat with a user
  Secret(ChatTypeSecret),

}

impl Default for ChatType {
  fn default() -> Self { ChatType::_Default(()) }
}

impl<'de> Deserialize<'de> for ChatType {
  fn deserialize<D>(deserializer: D) -> Result<ChatType, D::Error> where D: Deserializer<'de> {
    use serde::de::Error;
    rtd_enum_deserialize!(
      ChatType,
      (chatTypePrivate, Private);
      (chatTypeBasicGroup, BasicGroup);
      (chatTypeSupergroup, Supergroup);
      (chatTypeSecret, Secret);

    )(deserializer)
  }
}

impl RObject for ChatType {
  #[doc(hidden)] fn td_name(&self) -> &'static str {
    match self {
      ChatType::Private(t) => t.td_name(),
      ChatType::BasicGroup(t) => t.td_name(),
      ChatType::Supergroup(t) => t.td_name(),
      ChatType::Secret(t) => t.td_name(),

      _ => "-1",
    }
  }
  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}

impl ChatType {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
  #[doc(hidden)] pub fn _is_default(&self) -> bool { if let ChatType::_Default(_) = self { true } else { false } }

  pub fn is_private(&self) -> bool { if let ChatType::Private(_) = self { true } else { false } }
  pub fn is_basic_group(&self) -> bool { if let ChatType::BasicGroup(_) = self { true } else { false } }
  pub fn is_supergroup(&self) -> bool { if let ChatType::Supergroup(_) = self { true } else { false } }
  pub fn is_secret(&self) -> bool { if let ChatType::Secret(_) = self { true } else { false } }

  pub fn on_private<F: FnOnce(&ChatTypePrivate)>(&self, fnc: F) -> &Self { if let ChatType::Private(t) = self { fnc(t) }; self }
  pub fn on_basic_group<F: FnOnce(&ChatTypeBasicGroup)>(&self, fnc: F) -> &Self { if let ChatType::BasicGroup(t) = self { fnc(t) }; self }
  pub fn on_supergroup<F: FnOnce(&ChatTypeSupergroup)>(&self, fnc: F) -> &Self { if let ChatType::Supergroup(t) = self { fnc(t) }; self }
  pub fn on_secret<F: FnOnce(&ChatTypeSecret)>(&self, fnc: F) -> &Self { if let ChatType::Secret(t) = self { fnc(t) }; self }

  pub fn as_private(&self) -> Option<&ChatTypePrivate> { if let ChatType::Private(t) = self { return Some(t) } None }
  pub fn as_basic_group(&self) -> Option<&ChatTypeBasicGroup> { if let ChatType::BasicGroup(t) = self { return Some(t) } None }
  pub fn as_supergroup(&self) -> Option<&ChatTypeSupergroup> { if let ChatType::Supergroup(t) = self { return Some(t) } None }
  pub fn as_secret(&self) -> Option<&ChatTypeSecret> { if let ChatType::Secret(t) = self { return Some(t) } None }



  pub fn private<T: AsRef<ChatTypePrivate>>(t: T) -> Self { ChatType::Private(t.as_ref().clone()) }

  pub fn basic_group<T: AsRef<ChatTypeBasicGroup>>(t: T) -> Self { ChatType::BasicGroup(t.as_ref().clone()) }

  pub fn supergroup<T: AsRef<ChatTypeSupergroup>>(t: T) -> Self { ChatType::Supergroup(t.as_ref().clone()) }

  pub fn secret<T: AsRef<ChatTypeSecret>>(t: T) -> Self { ChatType::Secret(t.as_ref().clone()) }

}

impl AsRef<ChatType> for ChatType {
  fn as_ref(&self) -> &ChatType { self }
}







/// An ordinary chat with a user
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ChatTypePrivate {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  /// User identifier
  user_id: i64,
  
}

impl RObject for ChatTypePrivate {
  #[doc(hidden)] fn td_name(&self) -> &'static str { "chatTypePrivate" }
  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}


impl TDChatType for ChatTypePrivate {}



impl ChatTypePrivate {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
  pub fn builder() -> RTDChatTypePrivateBuilder {
    let mut inner = ChatTypePrivate::default();
    inner.td_name = "chatTypePrivate".to_string();
    RTDChatTypePrivateBuilder { inner }
  }

  pub fn user_id(&self) -> i64 { self.user_id }

}

#[doc(hidden)]
pub struct RTDChatTypePrivateBuilder {
  inner: ChatTypePrivate
}

impl RTDChatTypePrivateBuilder {
  pub fn build(&self) -> ChatTypePrivate { self.inner.clone() }

   
  pub fn user_id(&mut self, user_id: i64) -> &mut Self {
    self.inner.user_id = user_id;
    self
  }

}

impl AsRef<ChatTypePrivate> for ChatTypePrivate {
  fn as_ref(&self) -> &ChatTypePrivate { self }
}

impl AsRef<ChatTypePrivate> for RTDChatTypePrivateBuilder {
  fn as_ref(&self) -> &ChatTypePrivate { &self.inner }
}







/// A basic group (i.e., a chat with 0-200 other users)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ChatTypeBasicGroup {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  /// Basic group identifier
  basic_group_id: i64,
  
}

impl RObject for ChatTypeBasicGroup {
  #[doc(hidden)] fn td_name(&self) -> &'static str { "chatTypeBasicGroup" }
  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}


impl TDChatType for ChatTypeBasicGroup {}



impl ChatTypeBasicGroup {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
  pub fn builder() -> RTDChatTypeBasicGroupBuilder {
    let mut inner = ChatTypeBasicGroup::default();
    inner.td_name = "chatTypeBasicGroup".to_string();
    RTDChatTypeBasicGroupBuilder { inner }
  }

  pub fn basic_group_id(&self) -> i64 { self.basic_group_id }

}

#[doc(hidden)]
pub struct RTDChatTypeBasicGroupBuilder {
  inner: ChatTypeBasicGroup
}

impl RTDChatTypeBasicGroupBuilder {
  pub fn build(&self) -> ChatTypeBasicGroup { self.inner.clone() }

   
  pub fn basic_group_id(&mut self, basic_group_id: i64) -> &mut Self {
    self.inner.basic_group_id = basic_group_id;
    self
  }

}

impl AsRef<ChatTypeBasicGroup> for ChatTypeBasicGroup {
  fn as_ref(&self) -> &ChatTypeBasicGroup { self }
}

impl AsRef<ChatTypeBasicGroup> for RTDChatTypeBasicGroupBuilder {
  fn as_ref(&self) -> &ChatTypeBasicGroup { &self.inner }
}







/// A supergroup (i.e. a chat with up to GetOption("supergroup_max_size") other users), or channel (with unlimited members)
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ChatTypeSupergroup {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  /// Supergroup or channel identifier
  supergroup_id: i64,
  /// True, if the supergroup is a channel
  is_channel: bool,
  
}

impl RObject for ChatTypeSupergroup {
  #[doc(hidden)] fn td_name(&self) -> &'static str { "chatTypeSupergroup" }
  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}


impl TDChatType for ChatTypeSupergroup {}



impl ChatTypeSupergroup {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
  pub fn builder() -> RTDChatTypeSupergroupBuilder {
    let mut inner = ChatTypeSupergroup::default();
    inner.td_name = "chatTypeSupergroup".to_string();
    RTDChatTypeSupergroupBuilder { inner }
  }

  pub fn supergroup_id(&self) -> i64 { self.supergroup_id }

  pub fn is_channel(&self) -> bool { self.is_channel }

}

#[doc(hidden)]
pub struct RTDChatTypeSupergroupBuilder {
  inner: ChatTypeSupergroup
}

impl RTDChatTypeSupergroupBuilder {
  pub fn build(&self) -> ChatTypeSupergroup { self.inner.clone() }

   
  pub fn supergroup_id(&mut self, supergroup_id: i64) -> &mut Self {
    self.inner.supergroup_id = supergroup_id;
    self
  }

   
  pub fn is_channel(&mut self, is_channel: bool) -> &mut Self {
    self.inner.is_channel = is_channel;
    self
  }

}

impl AsRef<ChatTypeSupergroup> for ChatTypeSupergroup {
  fn as_ref(&self) -> &ChatTypeSupergroup { self }
}

impl AsRef<ChatTypeSupergroup> for RTDChatTypeSupergroupBuilder {
  fn as_ref(&self) -> &ChatTypeSupergroup { &self.inner }
}







/// A secret chat with a user
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct ChatTypeSecret {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  /// Secret chat identifier
  secret_chat_id: i64,
  /// User identifier of the secret chat peer
  user_id: i64,
  
}

impl RObject for ChatTypeSecret {
  #[doc(hidden)] fn td_name(&self) -> &'static str { "chatTypeSecret" }
  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}


impl TDChatType for ChatTypeSecret {}



impl ChatTypeSecret {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
  pub fn builder() -> RTDChatTypeSecretBuilder {
    let mut inner = ChatTypeSecret::default();
    inner.td_name = "chatTypeSecret".to_string();
    RTDChatTypeSecretBuilder { inner }
  }

  pub fn secret_chat_id(&self) -> i64 { self.secret_chat_id }

  pub fn user_id(&self) -> i64 { self.user_id }

}

#[doc(hidden)]
pub struct RTDChatTypeSecretBuilder {
  inner: ChatTypeSecret
}

impl RTDChatTypeSecretBuilder {
  pub fn build(&self) -> ChatTypeSecret { self.inner.clone() }

   
  pub fn secret_chat_id(&mut self, secret_chat_id: i64) -> &mut Self {
    self.inner.secret_chat_id = secret_chat_id;
    self
  }

   
  pub fn user_id(&mut self, user_id: i64) -> &mut Self {
    self.inner.user_id = user_id;
    self
  }

}

impl AsRef<ChatTypeSecret> for ChatTypeSecret {
  fn as_ref(&self) -> &ChatTypeSecret { self }
}

impl AsRef<ChatTypeSecret> for RTDChatTypeSecretBuilder {
  fn as_ref(&self) -> &ChatTypeSecret { &self.inner }
}