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

use crate::types::*;
use crate::errors::*;
use uuid::Uuid;




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



/// TRAIT | Describes a photo to be set as a user profile or chat photo
pub trait TDInputChatPhoto: Debug + RObject {}

/// Describes a photo to be set as a user profile or chat photo
#[derive(Debug, Clone, Serialize)]
#[serde(untagged)]
pub enum InputChatPhoto {
  #[doc(hidden)] _Default(()),
  /// An animation in MPEG4 format; must be square, at most 10 seconds long, have width between 160 and 800 and be at most 2MB in size
  Animation(InputChatPhotoAnimation),
  /// A previously used profile photo of the current user
  Previous(InputChatPhotoPrevious),
  /// A static photo in JPEG format
  Static(InputChatPhotoStatic),

}

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

impl<'de> Deserialize<'de> for InputChatPhoto {
  fn deserialize<D>(deserializer: D) -> Result<InputChatPhoto, D::Error> where D: Deserializer<'de> {
    use serde::de::Error;
    rtd_enum_deserialize!(
      InputChatPhoto,
      (inputChatPhotoAnimation, Animation);
      (inputChatPhotoPrevious, Previous);
      (inputChatPhotoStatic, Static);

    )(deserializer)
  }
}

impl RObject for InputChatPhoto {
  #[doc(hidden)] fn td_name(&self) -> &'static str {
    match self {
      InputChatPhoto::Animation(t) => t.td_name(),
      InputChatPhoto::Previous(t) => t.td_name(),
      InputChatPhoto::Static(t) => t.td_name(),

      _ => "-1",
    }
  }
  #[doc(hidden)] fn extra(&self) -> Option<String> {
    match self {
      InputChatPhoto::Animation(t) => t.extra(),
      InputChatPhoto::Previous(t) => t.extra(),
      InputChatPhoto::Static(t) => t.extra(),

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

impl InputChatPhoto {
  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 InputChatPhoto::_Default(_) = self { true } else { false } }

  pub fn is_animation(&self) -> bool { if let InputChatPhoto::Animation(_) = self { true } else { false } }
  pub fn is_previous(&self) -> bool { if let InputChatPhoto::Previous(_) = self { true } else { false } }
  pub fn is_static(&self) -> bool { if let InputChatPhoto::Static(_) = self { true } else { false } }

  pub fn on_animation<F: FnOnce(&InputChatPhotoAnimation)>(&self, fnc: F) -> &Self { if let InputChatPhoto::Animation(t) = self { fnc(t) }; self }
  pub fn on_previous<F: FnOnce(&InputChatPhotoPrevious)>(&self, fnc: F) -> &Self { if let InputChatPhoto::Previous(t) = self { fnc(t) }; self }
  pub fn on_static<F: FnOnce(&InputChatPhotoStatic)>(&self, fnc: F) -> &Self { if let InputChatPhoto::Static(t) = self { fnc(t) }; self }

  pub fn as_animation(&self) -> Option<&InputChatPhotoAnimation> { if let InputChatPhoto::Animation(t) = self { return Some(t) } None }
  pub fn as_previous(&self) -> Option<&InputChatPhotoPrevious> { if let InputChatPhoto::Previous(t) = self { return Some(t) } None }
  pub fn as_static(&self) -> Option<&InputChatPhotoStatic> { if let InputChatPhoto::Static(t) = self { return Some(t) } None }



  pub fn animation<T: AsRef<InputChatPhotoAnimation>>(t: T) -> Self { InputChatPhoto::Animation(t.as_ref().clone()) }

  pub fn previous<T: AsRef<InputChatPhotoPrevious>>(t: T) -> Self { InputChatPhoto::Previous(t.as_ref().clone()) }

  pub fn static_<T: AsRef<InputChatPhotoStatic>>(t: T) -> Self { InputChatPhoto::Static(t.as_ref().clone()) }

}

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







/// An animation in MPEG4 format; must be square, at most 10 seconds long, have width between 160 and 800 and be at most 2MB in size
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct InputChatPhotoAnimation {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Animation to be set as profile photo. Only inputFileLocal and inputFileGenerated are allowed
  animation: InputFile,
  /// Timestamp of the frame, which will be used as static chat photo
  main_frame_timestamp: f32,
  
}

impl RObject for InputChatPhotoAnimation {
  #[doc(hidden)] fn td_name(&self) -> &'static str { "inputChatPhotoAnimation" }
  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}


impl TDInputChatPhoto for InputChatPhotoAnimation {}



impl InputChatPhotoAnimation {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
  pub fn builder() -> RTDInputChatPhotoAnimationBuilder {
    let mut inner = InputChatPhotoAnimation::default();
    inner.td_name = "inputChatPhotoAnimation".to_string();
    inner.extra = Some(Uuid::new_v4().to_string());
    RTDInputChatPhotoAnimationBuilder { inner }
  }

  pub fn animation(&self) -> &InputFile { &self.animation }

  pub fn main_frame_timestamp(&self) -> f32 { self.main_frame_timestamp }

}

#[doc(hidden)]
pub struct RTDInputChatPhotoAnimationBuilder {
  inner: InputChatPhotoAnimation
}

impl RTDInputChatPhotoAnimationBuilder {
  pub fn build(&self) -> InputChatPhotoAnimation { self.inner.clone() }

   
  pub fn animation<T: AsRef<InputFile>>(&mut self, animation: T) -> &mut Self {
    self.inner.animation = animation.as_ref().clone();
    self
  }

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

}

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

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







/// A previously used profile photo of the current user
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct InputChatPhotoPrevious {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Identifier of the current user's profile photo to reuse
  chat_photo_id: isize,
  
}

impl RObject for InputChatPhotoPrevious {
  #[doc(hidden)] fn td_name(&self) -> &'static str { "inputChatPhotoPrevious" }
  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}


impl TDInputChatPhoto for InputChatPhotoPrevious {}



impl InputChatPhotoPrevious {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
  pub fn builder() -> RTDInputChatPhotoPreviousBuilder {
    let mut inner = InputChatPhotoPrevious::default();
    inner.td_name = "inputChatPhotoPrevious".to_string();
    inner.extra = Some(Uuid::new_v4().to_string());
    RTDInputChatPhotoPreviousBuilder { inner }
  }

  pub fn chat_photo_id(&self) -> isize { self.chat_photo_id }

}

#[doc(hidden)]
pub struct RTDInputChatPhotoPreviousBuilder {
  inner: InputChatPhotoPrevious
}

impl RTDInputChatPhotoPreviousBuilder {
  pub fn build(&self) -> InputChatPhotoPrevious { self.inner.clone() }

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

}

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

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







/// A static photo in JPEG format
#[derive(Debug, Clone, Default, Serialize, Deserialize)]
pub struct InputChatPhotoStatic {
  #[doc(hidden)]
  #[serde(rename(serialize = "@type", deserialize = "@type"))]
  td_name: String,
  #[doc(hidden)]
  #[serde(rename(serialize = "@extra", deserialize = "@extra"))]
  extra: Option<String>,
  /// Photo to be set as profile photo. Only inputFileLocal and inputFileGenerated are allowed
  photo: InputFile,
  
}

impl RObject for InputChatPhotoStatic {
  #[doc(hidden)] fn td_name(&self) -> &'static str { "inputChatPhotoStatic" }
  #[doc(hidden)] fn extra(&self) -> Option<String> { self.extra.clone() }
  fn to_json(&self) -> RTDResult<String> { Ok(serde_json::to_string(self)?) }
}


impl TDInputChatPhoto for InputChatPhotoStatic {}



impl InputChatPhotoStatic {
  pub fn from_json<S: AsRef<str>>(json: S) -> RTDResult<Self> { Ok(serde_json::from_str(json.as_ref())?) }
  pub fn builder() -> RTDInputChatPhotoStaticBuilder {
    let mut inner = InputChatPhotoStatic::default();
    inner.td_name = "inputChatPhotoStatic".to_string();
    inner.extra = Some(Uuid::new_v4().to_string());
    RTDInputChatPhotoStaticBuilder { inner }
  }

  pub fn photo(&self) -> &InputFile { &self.photo }

}

#[doc(hidden)]
pub struct RTDInputChatPhotoStaticBuilder {
  inner: InputChatPhotoStatic
}

impl RTDInputChatPhotoStaticBuilder {
  pub fn build(&self) -> InputChatPhotoStatic { self.inner.clone() }

   
  pub fn photo<T: AsRef<InputFile>>(&mut self, photo: T) -> &mut Self {
    self.inner.photo = photo.as_ref().clone();
    self
  }

}

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

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