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
use serde::{Deserialize, Serialize};
/// This object describes a gift received and owned by a user or a chat. Currently, it can be one of
/// - [`crate::types::OwnedGiftRegular`]
/// - [`crate::types::OwnedGiftUnique`]
/// # Documentation
/// <https://core.telegram.org/bots/api#ownedgift>
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(tag = "type", rename_all = "snake_case")]
pub enum OwnedGift {
Regular(crate::types::OwnedGiftRegular),
Unique(crate::types::OwnedGiftUnique),
}
impl OwnedGift {
/// Helper method for field `can_be_transferred`.
///
/// `true`, if the gift can be transferred to another owner; for gifts received on behalf of business accounts only
#[must_use]
pub fn can_be_transferred(&self) -> Option<bool> {
match self {
Self::Unique(val) => val.can_be_transferred,
Self::Regular(_) => None,
}
}
/// Helper method for field `can_be_upgraded`.
///
/// `true`, if the gift can be upgraded to a unique gift; for gifts received on behalf of business accounts only
#[must_use]
pub fn can_be_upgraded(&self) -> Option<bool> {
match self {
Self::Regular(val) => val.can_be_upgraded,
Self::Unique(_) => None,
}
}
/// Helper method for field `convert_star_count`.
///
/// Number of Telegram Stars that can be claimed by the receiver instead of the gift; omitted if the gift cannot be converted to Telegram Stars; for gifts received on behalf of business accounts only
#[must_use]
pub fn convert_star_count(&self) -> Option<i64> {
match self {
Self::Regular(val) => val.convert_star_count,
Self::Unique(_) => None,
}
}
/// Helper method for field `entities`.
///
/// Special entities that appear in the text
#[must_use]
pub fn entities(&self) -> Option<&[crate::types::MessageEntity]> {
match self {
Self::Regular(val) => val.entities.as_deref(),
Self::Unique(_) => None,
}
}
/// Helper method for field `is_private`.
///
/// `true`, if the sender and gift text are shown only to the gift receiver; otherwise, everyone will be able to see them
#[must_use]
pub fn is_private(&self) -> Option<bool> {
match self {
Self::Regular(val) => val.is_private,
Self::Unique(_) => None,
}
}
/// Helper method for field `is_saved`.
///
/// `true`, if the gift is displayed on the account's profile page; for gifts received on behalf of business accounts only
#[must_use]
pub fn is_saved(&self) -> Option<bool> {
match self {
Self::Regular(val) => val.is_saved,
Self::Unique(val) => val.is_saved,
}
}
/// Helper method for field `is_upgrade_separate`.
///
/// `true`, if the gift's upgrade was purchased after the gift was sent; for gifts received on behalf of business accounts only
#[must_use]
pub fn is_upgrade_separate(&self) -> Option<bool> {
match self {
Self::Regular(val) => val.is_upgrade_separate,
Self::Unique(_) => None,
}
}
/// Helper method for field `next_transfer_date`.
///
/// Point in time (Unix timestamp) when the gift can be transferred. If it is in the past, then the gift can be transferred now
#[must_use]
pub fn next_transfer_date(&self) -> Option<i64> {
match self {
Self::Unique(val) => val.next_transfer_date,
Self::Regular(_) => None,
}
}
/// Helper method for field `owned_gift_id`.
///
/// # Variants
/// - `OwnedGiftRegular`. Unique identifier of the gift for the bot; for gifts received on behalf of business accounts only
/// - `OwnedGiftUnique`. Unique identifier of the received gift for the bot; for gifts received on behalf of business accounts only
#[must_use]
pub fn owned_gift_id(&self) -> Option<&str> {
match self {
Self::Regular(val) => val.owned_gift_id.as_deref(),
Self::Unique(val) => val.owned_gift_id.as_deref(),
}
}
/// Helper method for field `prepaid_upgrade_star_count`.
///
/// Number of Telegram Stars that were paid for the ability to upgrade the gift
#[must_use]
pub fn prepaid_upgrade_star_count(&self) -> Option<i64> {
match self {
Self::Regular(val) => val.prepaid_upgrade_star_count,
Self::Unique(_) => None,
}
}
/// Helper method for field `send_date`.
///
/// Date the gift was sent in Unix time
#[must_use]
pub fn send_date(&self) -> i64 {
match self {
Self::Regular(val) => val.send_date,
Self::Unique(val) => val.send_date,
}
}
/// Helper method for field `sender_user`.
///
/// Sender of the gift if it is a known user
#[must_use]
pub fn sender_user(&self) -> Option<&crate::types::User> {
match self {
Self::Regular(val) => val.sender_user.as_deref(),
Self::Unique(val) => val.sender_user.as_deref(),
}
}
/// Helper method for field `text`.
///
/// Text of the message that was added to the gift
#[must_use]
pub fn text(&self) -> Option<&str> {
match self {
Self::Regular(val) => val.text.as_deref(),
Self::Unique(_) => None,
}
}
/// Helper method for field `transfer_star_count`.
///
/// Number of Telegram Stars that must be paid to transfer the gift; omitted if the bot cannot transfer the gift
#[must_use]
pub fn transfer_star_count(&self) -> Option<i64> {
match self {
Self::Unique(val) => val.transfer_star_count,
Self::Regular(_) => None,
}
}
/// Helper method for field `unique_gift_number`.
///
/// Unique number reserved for this gift when upgraded. See the number field in [`crate::types::UniqueGift`]
#[must_use]
pub fn unique_gift_number(&self) -> Option<i64> {
match self {
Self::Regular(val) => val.unique_gift_number,
Self::Unique(_) => None,
}
}
/// Helper method for field `was_refunded`.
///
/// `true`, if the gift was refunded and isn't available anymore
#[must_use]
pub fn was_refunded(&self) -> Option<bool> {
match self {
Self::Regular(val) => val.was_refunded,
Self::Unique(_) => None,
}
}
/// Helper method for nested field `added_to_attachment_menu`.
#[must_use]
pub fn added_to_attachment_menu(&self) -> Option<bool> {
self.sender_user()
.and_then(|inner| inner.added_to_attachment_menu)
}
/// Helper method for nested field `allows_users_to_create_topics`.
#[must_use]
pub fn allows_users_to_create_topics(&self) -> Option<bool> {
self.sender_user()
.and_then(|inner| inner.allows_users_to_create_topics)
}
/// Helper method for nested field `can_connect_to_business`.
#[must_use]
pub fn can_connect_to_business(&self) -> Option<bool> {
self.sender_user()
.and_then(|inner| inner.can_connect_to_business)
}
/// Helper method for nested field `can_join_groups`.
#[must_use]
pub fn can_join_groups(&self) -> Option<bool> {
self.sender_user().and_then(|inner| inner.can_join_groups)
}
/// Helper method for nested field `can_manage_bots`.
#[must_use]
pub fn can_manage_bots(&self) -> Option<bool> {
self.sender_user().and_then(|inner| inner.can_manage_bots)
}
/// Helper method for nested field `can_read_all_group_messages`.
#[must_use]
pub fn can_read_all_group_messages(&self) -> Option<bool> {
self.sender_user()
.and_then(|inner| inner.can_read_all_group_messages)
}
/// Helper method for nested field `first_name`.
#[must_use]
pub fn first_name(&self) -> Option<&str> {
self.sender_user().map(|inner| inner.first_name.as_ref())
}
/// Helper method for nested field `has_main_web_app`.
#[must_use]
pub fn has_main_web_app(&self) -> Option<bool> {
self.sender_user().and_then(|inner| inner.has_main_web_app)
}
/// Helper method for nested field `has_topics_enabled`.
#[must_use]
pub fn has_topics_enabled(&self) -> Option<bool> {
self.sender_user()
.and_then(|inner| inner.has_topics_enabled)
}
/// Helper method for nested field `id`.
#[must_use]
pub fn id(&self) -> Option<i64> {
self.sender_user().map(|inner| inner.id)
}
/// Helper method for nested field `is_bot`.
#[must_use]
pub fn is_bot(&self) -> Option<bool> {
self.sender_user().map(|inner| inner.is_bot)
}
/// Helper method for nested field `is_premium`.
#[must_use]
pub fn is_premium(&self) -> Option<bool> {
self.sender_user().and_then(|inner| inner.is_premium)
}
/// Helper method for nested field `language_code`.
#[must_use]
pub fn language_code(&self) -> Option<&str> {
self.sender_user()
.and_then(|inner| inner.language_code.as_deref())
}
/// Helper method for nested field `last_name`.
#[must_use]
pub fn last_name(&self) -> Option<&str> {
self.sender_user()
.and_then(|inner| inner.last_name.as_deref())
}
/// Helper method for nested field `supports_inline_queries`.
#[must_use]
pub fn supports_inline_queries(&self) -> Option<bool> {
self.sender_user()
.and_then(|inner| inner.supports_inline_queries)
}
/// Helper method for nested field `username`.
#[must_use]
pub fn username(&self) -> Option<&str> {
self.sender_user()
.and_then(|inner| inner.username.as_deref())
}
}
impl From<crate::types::OwnedGiftRegular> for OwnedGift {
fn from(val: crate::types::OwnedGiftRegular) -> Self {
Self::Regular(val)
}
}
impl TryFrom<OwnedGift> for crate::types::OwnedGiftRegular {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: OwnedGift) -> Result<Self, Self::Error> {
match val {
OwnedGift::Regular(inner) => Ok(inner),
OwnedGift::Unique(_) => Err(Self::Error::new(
stringify!(OwnedGift),
stringify!(OwnedGiftRegular),
)),
}
}
}
impl From<crate::types::OwnedGiftUnique> for OwnedGift {
fn from(val: crate::types::OwnedGiftUnique) -> Self {
Self::Unique(val)
}
}
impl TryFrom<OwnedGift> for crate::types::OwnedGiftUnique {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: OwnedGift) -> Result<Self, Self::Error> {
match val {
OwnedGift::Unique(inner) => Ok(inner),
OwnedGift::Regular(_) => Err(Self::Error::new(
stringify!(OwnedGift),
stringify!(OwnedGiftUnique),
)),
}
}
}