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
use crate::errors::Result;
use crate::types::*;
use uuid::Uuid;

use std::fmt::Debug;

/// 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, Deserialize, Serialize, Default)]
#[serde(tag = "@type")]
pub enum InputChatPhoto {
    #[doc(hidden)]
    #[default]
    _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
    #[serde(rename = "inputChatPhotoAnimation")]
    Animation(InputChatPhotoAnimation),
    /// A previously used profile photo of the current user
    #[serde(rename = "inputChatPhotoPrevious")]
    Previous(InputChatPhotoPrevious),
    /// A static photo in JPEG format
    #[serde(rename = "inputChatPhotoStatic")]
    Static(InputChatPhotoStatic),
}

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

            _ => None,
        }
    }
    #[doc(hidden)]
    fn client_id(&self) -> Option<i32> {
        match self {
            InputChatPhoto::Animation(t) => t.client_id(),
            InputChatPhoto::Previous(t) => t.client_id(),
            InputChatPhoto::Static(t) => t.client_id(),

            _ => None,
        }
    }
}

impl InputChatPhoto {
    pub fn from_json<S: AsRef<str>>(json: S) -> Result<Self> {
        Ok(serde_json::from_str(json.as_ref())?)
    }
    #[doc(hidden)]
    pub fn _is_default(&self) -> bool {
        matches!(self, InputChatPhoto::_Default)
    }
}

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 = "@extra", deserialize = "@extra"))]
    extra: Option<String>,
    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
    client_id: Option<i32>,
    /// Animation to be set as profile photo. Only inputFileLocal and inputFileGenerated are allowed

    #[serde(skip_serializing_if = "InputFile::_is_default")]
    animation: InputFile,
    /// Timestamp of the frame, which will be used as static chat photo

    #[serde(default)]
    main_frame_timestamp: f32,
}

impl RObject for InputChatPhotoAnimation {
    #[doc(hidden)]
    fn extra(&self) -> Option<&str> {
        self.extra.as_deref()
    }
    #[doc(hidden)]
    fn client_id(&self) -> Option<i32> {
        self.client_id
    }
}

impl TDInputChatPhoto for InputChatPhotoAnimation {}

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

        InputChatPhotoAnimationBuilder { inner }
    }

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

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

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

#[deprecated]
pub type RTDInputChatPhotoAnimationBuilder = InputChatPhotoAnimationBuilder;

impl InputChatPhotoAnimationBuilder {
    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 InputChatPhotoAnimationBuilder {
    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 = "@extra", deserialize = "@extra"))]
    extra: Option<String>,
    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
    client_id: Option<i32>,
    /// Identifier of the current user's profile photo to reuse

    #[serde(
        deserialize_with = "super::_common::number_from_string",
        serialize_with = "super::_common::string_to_number"
    )]
    #[serde(default)]
    chat_photo_id: i64,
}

impl RObject for InputChatPhotoPrevious {
    #[doc(hidden)]
    fn extra(&self) -> Option<&str> {
        self.extra.as_deref()
    }
    #[doc(hidden)]
    fn client_id(&self) -> Option<i32> {
        self.client_id
    }
}

impl TDInputChatPhoto for InputChatPhotoPrevious {}

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

        InputChatPhotoPreviousBuilder { inner }
    }

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

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

#[deprecated]
pub type RTDInputChatPhotoPreviousBuilder = InputChatPhotoPreviousBuilder;

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

    pub fn chat_photo_id(&mut self, chat_photo_id: i64) -> &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 InputChatPhotoPreviousBuilder {
    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 = "@extra", deserialize = "@extra"))]
    extra: Option<String>,
    #[serde(rename(serialize = "@client_id", deserialize = "@client_id"))]
    client_id: Option<i32>,
    /// Photo to be set as profile photo. Only inputFileLocal and inputFileGenerated are allowed

    #[serde(skip_serializing_if = "InputFile::_is_default")]
    photo: InputFile,
}

impl RObject for InputChatPhotoStatic {
    #[doc(hidden)]
    fn extra(&self) -> Option<&str> {
        self.extra.as_deref()
    }
    #[doc(hidden)]
    fn client_id(&self) -> Option<i32> {
        self.client_id
    }
}

impl TDInputChatPhoto for InputChatPhotoStatic {}

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

        InputChatPhotoStaticBuilder { inner }
    }

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

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

#[deprecated]
pub type RTDInputChatPhotoStaticBuilder = InputChatPhotoStaticBuilder;

impl InputChatPhotoStaticBuilder {
    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 InputChatPhotoStaticBuilder {
    fn as_ref(&self) -> &InputChatPhotoStatic {
        &self.inner
    }
}