Skip to main content

tgbot/types/definitions/
gift.rs

1use serde::{Deserialize, Serialize};
2
3use crate::{
4    api::{Method, Payload},
5    types::{Chat, ChatId, Integer, ParseMode, Sticker, TextEntities, TextEntity, User},
6};
7
8/// Describes the types of gifts that can be gifted to a user or a chat.
9#[derive(Clone, Copy, Debug, Default, Deserialize, PartialEq, PartialOrd, Serialize)]
10pub struct AcceptedGiftTypes {
11    /// Whether transfers of unique gifts from channels are accepted.
12    pub gifts_from_channels: bool,
13    /// Whether limited regular gifts are accepted.
14    pub limited_gifts: bool,
15    /// Whether a Telegram Premium subscription is accepted.
16    pub premium_subscription: bool,
17    /// Whether unique gifts or gifts that can be upgraded to unique for free are accepted.
18    pub unique_gifts: bool,
19    /// Whether unlimited regular gifts are accepted.
20    pub unlimited_gifts: bool,
21}
22
23impl AcceptedGiftTypes {
24    /// Sets a new value for the `gifts_from_channels` flag.
25    ///
26    /// # Arguments
27    ///
28    /// * `value` - Whether transfers of unique gifts from channels are accepted.
29    pub fn with_gifts_from_channels(mut self, value: bool) -> Self {
30        self.gifts_from_channels = value;
31        self
32    }
33
34    /// Sets a new value for the `limited_gifts` flag.
35    ///
36    /// # Arguments
37    ///
38    /// * `value` - Whether limited regular gifts are accepted.
39    pub fn with_limited_gifts(mut self, value: bool) -> Self {
40        self.limited_gifts = value;
41        self
42    }
43
44    /// Sets a new value for the `premium_subscription` flag.
45    ///
46    /// # Arguments
47    ///
48    /// * `value` - Whether a Telegram Premium subscription is accepted.
49    pub fn with_premium_subscription(mut self, value: bool) -> Self {
50        self.premium_subscription = value;
51        self
52    }
53
54    /// Sets a new value for the `unique_gifts` flag.
55    ///
56    /// # Arguments
57    ///
58    /// * `value` - Whether unique gifts or gifts that can be upgraded to unique for free are accepted.
59    pub fn with_unique_gifts(mut self, value: bool) -> Self {
60        self.unique_gifts = value;
61        self
62    }
63
64    /// Sets a new value for the `unlimited_gifts` flag.
65    ///
66    /// # Arguments
67    ///
68    /// * `value` - Whether unlimited regular gifts are accepted.
69    pub fn with_unlimited_gifts(mut self, value: bool) -> Self {
70        self.unlimited_gifts = value;
71        self
72    }
73}
74
75/// Represents a gift that can be sent by the bot.
76#[serde_with::skip_serializing_none]
77#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
78pub struct Gift {
79    /// Unique identifier of the gift.
80    pub id: String,
81    /// The number of Telegram Stars that must be paid to send the sticker.
82    pub star_count: Integer,
83    /// The sticker that represents the gift.
84    pub sticker: Sticker,
85    /// Background of the gift.
86    pub background: Option<GiftBackground>,
87    /// Whether the gift can be used (after being upgraded) to customize a user's appearance.
88    pub has_colors: Option<bool>,
89    /// Whether the gift can only be purchased by Telegram Premium subscribers.
90    pub is_premium: Option<bool>,
91    /// The number of remaining gifts of this type that can be sent by the bot; for limited gifts only.
92    pub personal_remaining_count: Option<Integer>,
93    /// The total number of gifts of this type that can be sent by the bot; for limited gifts only.
94    pub personal_total_count: Option<Integer>,
95    /// Information about the chat that published the gift.
96    pub publisher_chat: Option<Chat>,
97    /// The number of remaining gifts of this type that can be sent;
98    /// for limited gifts only.
99    pub remaining_count: Option<Integer>,
100    /// The total number of the gifts of this type that can be sent;
101    /// for limited gifts only.
102    pub total_count: Option<Integer>,
103    /// The total number of different unique gifts that can be obtained by upgrading the gift.
104    pub unique_gift_variant_count: Option<Integer>,
105    /// The number of Telegram Stars that must be paid to upgrade the gift to a unique one.
106    pub upgrade_star_count: Option<Integer>,
107}
108
109impl Gift {
110    /// Creates a new `Gift`.
111    ///
112    /// # Arguments
113    ///
114    /// * `id` - Unique identifier of the gift.
115    /// * `sticker` - The sticker that represents the gift.
116    /// * `star_count` - The number of Telegram Stars that must be paid to send the sticker.
117    pub fn new<T>(id: T, sticker: Sticker, star_count: Integer) -> Self
118    where
119        T: Into<String>,
120    {
121        Self {
122            id: id.into(),
123            star_count,
124            sticker,
125            background: None,
126            has_colors: None,
127            is_premium: None,
128            personal_remaining_count: None,
129            personal_total_count: None,
130            publisher_chat: None,
131            remaining_count: None,
132            total_count: None,
133            unique_gift_variant_count: None,
134            upgrade_star_count: None,
135        }
136    }
137
138    /// Sets a new background
139    ///
140    /// # Arguments
141    ///
142    /// * `value` - Background of the gift.
143    pub fn with_background(mut self, value: GiftBackground) -> Self {
144        self.background = Some(value);
145        self
146    }
147
148    /// Sets a new value for the `has_colors` flag.
149    ///
150    /// # Arguments
151    ///
152    /// * `value` - Whether the gift can be used (after being upgraded) to customize a user's appearance.
153    pub fn with_has_colors(mut self, value: bool) -> Self {
154        self.has_colors = Some(value);
155        self
156    }
157
158    /// Sets a new value for the `is_premium` flag.
159    ///
160    /// # Arguments
161    ///
162    /// * `value` - Whether the gift can only be purchased by Telegram Premium subscribers.
163    pub fn with_is_premium(mut self, value: bool) -> Self {
164        self.is_premium = Some(value);
165        self
166    }
167
168    /// Sets a new personal remaining count.
169    ///
170    /// # Arguments
171    ///
172    /// * `value` - The number of remaining gifts of this type that can be sent by the bot; for limited gifts only.
173    pub fn with_personal_remaining_count(mut self, value: Integer) -> Self {
174        self.personal_remaining_count = Some(value);
175        self
176    }
177
178    /// Sets a new personal total count.
179    ///
180    /// # Arguments
181    ///
182    /// * `value` - The total number of gifts of this type that can be sent by the bot; for limited gifts only.
183    pub fn with_personal_total_count(mut self, value: Integer) -> Self {
184        self.personal_total_count = Some(value);
185        self
186    }
187
188    /// Sets a new publisher chat.
189    ///
190    /// # Arguments
191    ///
192    /// * `value` - Information about the chat that published the gift.
193    pub fn with_publisher_chat<T>(mut self, value: T) -> Self
194    where
195        T: Into<Chat>,
196    {
197        self.publisher_chat = Some(value.into());
198        self
199    }
200
201    /// Sets a new remaining count.
202    ///
203    /// # Arguments
204    ///
205    /// * `value` - The number of remaining gifts of this type that can be sent.
206    pub fn with_remaining_count(mut self, value: Integer) -> Self {
207        self.remaining_count = Some(value);
208        self
209    }
210
211    /// Sets a new total count.
212    ///
213    /// # Arguments
214    ///
215    /// * `value` - The total number of the gifts of this type that can be sent.
216    pub fn with_total_count(mut self, value: Integer) -> Self {
217        self.total_count = Some(value);
218        self
219    }
220
221    /// Sets a new unique gift variant count.
222    ///
223    /// # Arguments
224    ///
225    /// * `value` - The total number of different unique gifts that can be obtained by upgrading the gift.
226    pub fn with_unique_gift_variant_count(mut self, value: Integer) -> Self {
227        self.unique_gift_variant_count = Some(value);
228        self
229    }
230
231    /// Sets a new upgrade star count.
232    ///
233    /// # Arguments
234    ///
235    /// * `value` - The number of Telegram Stars that must be paid to upgrade the gift to a unique one.
236    pub fn with_upgrade_star_count(mut self, value: Integer) -> Self {
237        self.upgrade_star_count = Some(value);
238        self
239    }
240}
241
242/// Describes the background of a gift.
243#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
244pub struct GiftBackground {
245    /// Center color of the background in RGB format
246    pub center_color: Integer,
247    /// Edge color of the background in RGB format
248    pub edge_color: Integer,
249    /// Text color of the background in RGB format
250    pub text_color: Integer,
251}
252
253/// Describes a service message about a regular gift that was sent or received.
254#[serde_with::skip_serializing_none]
255#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
256pub struct GiftInfo {
257    /// Information about the gift.
258    pub gift: Gift,
259    /// Whether the gift can be upgraded to a unique gift.
260    pub can_be_upgraded: Option<bool>,
261    /// Number of Telegram Stars that can be claimed by the receiver by converting the gift;
262    /// omitted if conversion to Telegram Stars is impossible.
263    pub convert_star_count: Option<Integer>,
264    /// Special entities that appear in the text.
265    pub entities: Option<TextEntities>,
266    /// Whether the sender and gift text are shown only to the gift receiver;
267    /// otherwise, everyone will be able to see them.
268    pub is_private: Option<bool>,
269    /// Whether the gift's upgrade was purchased after the gift was sent.
270    pub is_upgrade_separate: Option<bool>,
271    /// Unique identifier of the received gift for the bot;
272    /// only present for gifts received on behalf of business accounts.
273    pub owned_gift_id: Option<String>,
274    /// Number of Telegram Stars that were prepaid by the sender for the ability to upgrade the gift.
275    pub prepaid_upgrade_star_count: Option<Integer>,
276    /// Text of the message that was added to the gift.
277    pub text: Option<String>,
278    /// Unique number reserved for this gift when upgraded.
279    ///
280    /// See the number field in [`crate::types::UniqueGift`].
281    pub unique_gift_number: Option<Integer>,
282}
283
284impl GiftInfo {
285    /// Creates a new `GiftInfo`.
286    ///
287    /// # Arguments
288    ///
289    /// * `gift` - Information about the gift.
290    pub fn new(gift: Gift) -> Self {
291        Self {
292            gift,
293            can_be_upgraded: None,
294            convert_star_count: None,
295            entities: None,
296            is_private: None,
297            is_upgrade_separate: None,
298            owned_gift_id: None,
299            prepaid_upgrade_star_count: None,
300            text: None,
301            unique_gift_number: None,
302        }
303    }
304
305    /// Sets a new value for the `can_be_upgraded` flag.
306    ///
307    /// # Arguments
308    ///
309    /// * `value` - Whether the gift can be upgraded to a unique gift.
310    pub fn with_can_be_upgraded(mut self, value: bool) -> Self {
311        self.can_be_upgraded = Some(value);
312        self
313    }
314
315    /// Sets a new convert star count.
316    ///
317    /// # Arguments
318    ///
319    /// * `value` - Number of Telegram Stars that can be claimed by the receiver by converting the gift;
320    ///   omitted if conversion to Telegram Stars is impossible.
321    pub fn with_convert_star_count(mut self, value: Integer) -> Self {
322        self.convert_star_count = Some(value);
323        self
324    }
325
326    /// Sets a new list of entities.
327    ///
328    /// # Arguments
329    ///
330    /// * `value` - Special entities that appear in the text.
331    pub fn with_entities<T>(mut self, value: T) -> Self
332    where
333        T: IntoIterator<Item = TextEntity>,
334    {
335        self.entities = Some(TextEntities::from_iter(value));
336        self
337    }
338
339    /// Sets a new value for the `is_private` flag.
340    ///
341    /// # Arguments
342    ///
343    /// * `value` - Whether the sender and gift text are shown only to the gift receiver;
344    ///   otherwise, everyone will be able to see them.
345    pub fn with_is_private(mut self, value: bool) -> Self {
346        self.is_private = Some(value);
347        self
348    }
349
350    /// Sets a new value for the `is_upgrade_separate` flag.
351    ///
352    /// # Arguments
353    ///
354    /// * `value` - Whether the gift's upgrade was purchased after the gift was sent.
355    pub fn with_is_upgrade_separate(mut self, value: bool) -> Self {
356        self.is_upgrade_separate = Some(value);
357        self
358    }
359
360    /// Sets a new owned gift ID.
361    ///
362    /// # Arguments
363    ///
364    /// * `value` - Unique identifier of the received gift for the bot;
365    ///   only present for gifts received on behalf of business accounts.
366    pub fn with_owned_gift_id<T>(mut self, value: T) -> Self
367    where
368        T: Into<String>,
369    {
370        self.owned_gift_id = Some(value.into());
371        self
372    }
373
374    /// Sets a new prepaid upgrade star count.
375    ///
376    /// # Arguments
377    ///
378    /// * `value` - Number of Telegram Stars that were prepaid by the sender for the ability to upgrade the gift.
379    pub fn with_prepaid_upgrade_star_count(mut self, value: Integer) -> Self {
380        self.prepaid_upgrade_star_count = Some(value);
381        self
382    }
383
384    /// Sets a new text.
385    ///
386    /// # Arguments
387    ///
388    /// * `value` - Text of the message that was added to the gift.
389    pub fn with_text<T>(mut self, value: T) -> Self
390    where
391        T: Into<String>,
392    {
393        self.text = Some(value.into());
394        self
395    }
396
397    /// Sets a new unique gift number.
398    ///
399    /// # Arguments
400    ///
401    /// * `value` - Unique number reserved for this gift when upgraded.
402    pub fn with_unique_gift_number(mut self, value: Integer) -> Self {
403        self.unique_gift_number = Some(value);
404        self
405    }
406}
407
408/// Represent a list of gifts.
409#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
410pub struct Gifts {
411    gifts: Vec<Gift>,
412}
413
414impl<T> From<T> for Gifts
415where
416    T: IntoIterator<Item = Gift>,
417{
418    fn from(value: T) -> Self {
419        Self {
420            gifts: value.into_iter().collect(),
421        }
422    }
423}
424
425/// Returns the list of gifts that can be sent by the bot to users.
426#[derive(Clone, Copy, Debug, PartialEq, PartialOrd)]
427pub struct GetAvailableGifts;
428
429impl Method for GetAvailableGifts {
430    type Response = Gifts;
431
432    fn into_payload(self) -> Payload {
433        Payload::empty("getAvailableGifts")
434    }
435}
436
437/// Returns the gifts received and owned by a managed business account.
438///
439/// Requires the `can_view_gifts_and_stars` business bot right.
440#[serde_with::skip_serializing_none]
441#[derive(Clone, Debug, Serialize)]
442pub struct GetBusinessAccountGifts {
443    business_connection_id: String,
444    exclude_from_blockchain: Option<bool>,
445    exclude_limited_non_upgradable: Option<bool>,
446    exclude_limited_upgradable: Option<bool>,
447    exclude_saved: Option<bool>,
448    exclude_unique: Option<bool>,
449    exclude_unlimited: Option<bool>,
450    exclude_unsaved: Option<bool>,
451    limit: Option<Integer>,
452    offset: Option<String>,
453    sort_by_price: Option<bool>,
454}
455
456impl GetBusinessAccountGifts {
457    /// Creates a new `GetBusinessAccountGifts`.
458    ///
459    /// # Arguments
460    ///
461    /// * `business_connection_id` - Unique identifier of the business connection.
462    pub fn new<T>(business_connection_id: T) -> Self
463    where
464        T: Into<String>,
465    {
466        Self {
467            business_connection_id: business_connection_id.into(),
468            exclude_from_blockchain: None,
469            exclude_limited_non_upgradable: None,
470            exclude_limited_upgradable: None,
471            exclude_saved: None,
472            exclude_unique: None,
473            exclude_unlimited: None,
474            exclude_unsaved: None,
475            limit: None,
476            offset: None,
477            sort_by_price: None,
478        }
479    }
480
481    /// Sets a new value for the `exclude_from_blockchain` flag.
482    ///
483    /// # Arguments
484    ///
485    /// * `value` - Whether to exclude gifts that were assigned from the TON blockchain
486    ///   and can't be resold or transferred in Telegram.
487    pub fn with_exclude_from_blockchain(mut self, value: bool) -> Self {
488        self.exclude_from_blockchain = Some(value);
489        self
490    }
491
492    /// Sets a new value for the `exclude_limited_non_upgradable` flag.
493    ///
494    /// # Arguments
495    ///
496    /// * `value` - Whether to exclude gifts that can be purchased
497    ///   a limited number of times and can't be upgraded to unique.
498    pub fn with_exclude_limited_non_upgradable(mut self, value: bool) -> Self {
499        self.exclude_limited_non_upgradable = Some(value);
500        self
501    }
502
503    /// Sets a new value for the `exclude_limited_upgradable` flag.
504    ///
505    /// # Arguments
506    ///
507    /// * `value` - Whether to exclude gifts that can be purchased
508    ///   a limited number of times and can be upgraded to unique
509    pub fn with_exclude_limited_upgradable(mut self, value: bool) -> Self {
510        self.exclude_limited_upgradable = Some(value);
511        self
512    }
513
514    /// Sets a new value for the `exclude_saved` flag.
515    ///
516    /// # Arguments
517    ///
518    /// * `value` - Whether to exclude gifts that are saved to the account's profile page.
519    pub fn with_exclude_saved(mut self, value: bool) -> Self {
520        self.exclude_saved = Some(value);
521        self
522    }
523
524    /// Sets a new value for the `exclude_unique` flag.
525    ///
526    /// # Arguments
527    ///
528    /// * `value` - Whether to exclude unique gifts.
529    pub fn with_exclude_unique(mut self, value: bool) -> Self {
530        self.exclude_unique = Some(value);
531        self
532    }
533
534    /// Sets a new value for the `exclude_unlimited` flag.
535    ///
536    /// # Arguments
537    ///
538    /// * `value` - Whether to exclude gifts that can be purchased an unlimited number of times.
539    pub fn with_exclude_unlimited(mut self, value: bool) -> Self {
540        self.exclude_unlimited = Some(value);
541        self
542    }
543
544    /// Sets a new value for the `exclude_unsaved` flag.
545    ///
546    /// # Arguments
547    ///
548    /// * `value` - Whether to exclude gifts that aren't saved to the account's profile page.
549    pub fn with_exclude_unsaved(mut self, value: bool) -> Self {
550        self.exclude_unsaved = Some(value);
551        self
552    }
553
554    /// Sets a new limit.
555    ///
556    /// # Arguments
557    ///
558    /// * `value` - The maximum number of gifts to be returned; 1-100; defaults to 100.
559    pub fn with_limit(mut self, value: Integer) -> Self {
560        self.limit = Some(value);
561        self
562    }
563
564    /// Sets a new offset.
565    ///
566    /// # Arguments
567    ///
568    /// * `value` - Offset of the first entry to return as received from the previous request;
569    ///   use empty string to get the first chunk of results.
570    pub fn with_offset<T>(mut self, value: T) -> Self
571    where
572        T: Into<String>,
573    {
574        self.offset = Some(value.into());
575        self
576    }
577
578    /// Sets a new value for the `sort_by_price` flag.
579    ///
580    /// # Arguments
581    ///
582    /// * `value` - Whether to sort results by gift price instead of send date;
583    ///   sorting is applied before pagination.
584    pub fn with_sort_by_price(mut self, value: bool) -> Self {
585        self.sort_by_price = Some(value);
586        self
587    }
588}
589
590impl Method for GetBusinessAccountGifts {
591    type Response = OwnedGifts;
592
593    fn into_payload(self) -> Payload {
594        Payload::json("getBusinessAccountGifts", self)
595    }
596}
597
598/// Returns the gifts owned by a chat.
599#[serde_with::skip_serializing_none]
600#[derive(Clone, Debug, Serialize)]
601pub struct GetChatGifts {
602    chat_id: ChatId,
603    exclude_from_blockchain: Option<bool>,
604    exclude_limited_non_upgradable: Option<bool>,
605    exclude_limited_upgradable: Option<bool>,
606    exclude_saved: Option<bool>,
607    exclude_unique: Option<bool>,
608    exclude_unlimited: Option<bool>,
609    exclude_unsaved: Option<bool>,
610    limit: Option<Integer>,
611    offset: Option<String>,
612    sort_by_price: Option<bool>,
613}
614
615impl GetChatGifts {
616    /// Creates a new `GetChatGifts`.
617    ///
618    /// # Arguments
619    ///
620    /// * `chat_id` - Unique identifier for the target chat or username of the target channel.
621    pub fn new<T>(chat_id: T) -> Self
622    where
623        T: Into<ChatId>,
624    {
625        Self {
626            chat_id: chat_id.into(),
627            exclude_from_blockchain: None,
628            exclude_limited_non_upgradable: None,
629            exclude_limited_upgradable: None,
630            exclude_saved: None,
631            exclude_unique: None,
632            exclude_unlimited: None,
633            exclude_unsaved: None,
634            limit: None,
635            offset: None,
636            sort_by_price: None,
637        }
638    }
639
640    /// Sets a new value for the `exclude_from_blockchain` flag.
641    ///
642    /// # Arguments
643    ///
644    /// * `value` - Whether to exclude gifts that were assigned from the TON blockchain
645    ///   and can't be resold or transferred in Telegram.
646    pub fn with_exclude_from_blockchain(mut self, value: bool) -> Self {
647        self.exclude_from_blockchain = Some(value);
648        self
649    }
650
651    /// Sets a new value for the `exclude_limited_non_upgradable` flag.
652    ///
653    /// # Arguments
654    ///
655    /// * `value` - Whether to exclude gifts that can be purchased
656    ///   a limited number of times and can't be upgraded to unique.
657    pub fn with_exclude_limited_non_upgradable(mut self, value: bool) -> Self {
658        self.exclude_limited_non_upgradable = Some(value);
659        self
660    }
661
662    /// Sets a new value for the `exclude_limited_upgradable` flag.
663    ///
664    /// # Arguments
665    ///
666    /// * `value` - Whether to exclude gifts that can be purchased
667    ///   a limited number of times and can be upgraded to unique.
668    pub fn with_exclude_limited_upgradable(mut self, value: bool) -> Self {
669        self.exclude_limited_upgradable = Some(value);
670        self
671    }
672
673    /// Sets a new value for the `exclude_saved` flag.
674    ///
675    /// # Arguments
676    ///
677    /// * `value` - Whether to exclude gifts that are saved to the chat's profile page.
678    ///   Always `false`, unless the bot has the `can_post_messages` administrator right in the channel.
679    pub fn with_exclude_saved(mut self, value: bool) -> Self {
680        self.exclude_saved = Some(value);
681        self
682    }
683
684    /// Sets a new value for the `exclude_unique` flag.
685    ///
686    /// # Arguments
687    ///
688    /// * `value` - Whether to exclude unique gifts.
689    pub fn with_exclude_unique(mut self, value: bool) -> Self {
690        self.exclude_unique = Some(value);
691        self
692    }
693
694    /// Sets a new value for the `exclude_unlimited` flag.
695    ///
696    /// # Arguments
697    ///
698    /// * `value` - Whether to exclude gifts that can be purchased an unlimited number of times.
699    pub fn with_exclude_unlimited(mut self, value: bool) -> Self {
700        self.exclude_unlimited = Some(value);
701        self
702    }
703
704    /// Sets a new value for the `exclude_unsaved` flag.
705    ///
706    /// # Arguments
707    ///
708    /// * `value` - Whether to exclude gifts that aren't saved to the chat's profile page.
709    ///   Always `true`, unless the bot has the `can_post_messages` administrator right in the channel.
710    pub fn with_exclude_unsaved(mut self, value: bool) -> Self {
711        self.exclude_unsaved = Some(value);
712        self
713    }
714
715    /// Sets a new limit.
716    ///
717    /// # Arguments
718    ///
719    /// * `value` - The maximum number of gifts to be returned; 1-100. Defaults to 100.
720    pub fn with_limit(mut self, value: Integer) -> Self {
721        self.limit = Some(value);
722        self
723    }
724
725    /// Sets a new offset.
726    ///
727    /// # Arguments
728    ///
729    /// * `value` - Offset of the first entry to return as received from the previous request;
730    ///   use an empty string to get the first chunk of results.
731    pub fn with_offset<T>(mut self, value: T) -> Self
732    where
733        T: Into<String>,
734    {
735        self.offset = Some(value.into());
736        self
737    }
738
739    /// Sets a new value for the `sort_by_price` flag.
740    ///
741    /// # Arguments
742    ///
743    /// * `value` - Whether to sort results by gift price instead of send date.
744    ///   Sorting is applied before pagination.
745    pub fn with_sort_by_price(mut self, value: bool) -> Self {
746        self.sort_by_price = Some(value);
747        self
748    }
749}
750
751impl Method for GetChatGifts {
752    type Response = OwnedGifts;
753
754    fn into_payload(self) -> Payload {
755        Payload::json("getChatGifts", self)
756    }
757}
758
759/// Returns the gifts owned and hosted by a user.
760#[serde_with::skip_serializing_none]
761#[derive(Clone, Debug, Serialize)]
762pub struct GetUserGifts {
763    user_id: Integer,
764    exclude_from_blockchain: Option<bool>,
765    exclude_limited_non_upgradable: Option<bool>,
766    exclude_limited_upgradable: Option<bool>,
767    exclude_unique: Option<bool>,
768    exclude_unlimited: Option<bool>,
769    limit: Option<Integer>,
770    offset: Option<String>,
771    sort_by_price: Option<bool>,
772}
773
774impl GetUserGifts {
775    /// Creates a new `GetUserGifts`.
776    ///
777    /// # Arguments
778    ///
779    /// * `user_id` - Unique identifier of the user.
780    pub fn new(user_id: Integer) -> Self {
781        Self {
782            user_id,
783            exclude_from_blockchain: None,
784            exclude_limited_non_upgradable: None,
785            exclude_limited_upgradable: None,
786            exclude_unique: None,
787            exclude_unlimited: None,
788            limit: None,
789            offset: None,
790            sort_by_price: None,
791        }
792    }
793
794    /// Sets a new value for the `exclude_from_blockchain` flag.
795    ///
796    /// # Arguments
797    ///
798    /// * `value` - Whether to exclude gifts that were assigned from the TON blockchain
799    ///   and can't be resold or transferred in Telegram.
800    pub fn with_exclude_from_blockchain(mut self, value: bool) -> Self {
801        self.exclude_from_blockchain = Some(value);
802        self
803    }
804
805    /// Sets a new value for the `exclude_limited_non_upgradable` flag.
806    ///
807    /// # Arguments
808    ///
809    /// * `value` - Whether to exclude gifts that can be purchased
810    ///   a limited number of times and can't be upgraded to unique.
811    pub fn with_exclude_limited_non_upgradable(mut self, value: bool) -> Self {
812        self.exclude_limited_non_upgradable = Some(value);
813        self
814    }
815
816    /// Sets a new value for the `exclude_limited_upgradable` flag.
817    ///
818    /// # Arguments
819    ///
820    /// * `value` - Whether to exclude gifts that can be purchased
821    ///   a limited number of times and can be upgraded to unique.
822    pub fn with_exclude_limited_upgradable(mut self, value: bool) -> Self {
823        self.exclude_limited_upgradable = Some(value);
824        self
825    }
826
827    /// Sets a new value for the `exclude_unique` flag.
828    ///
829    /// # Arguments
830    ///
831    /// * `value` - Whether to exclude unique gifts.
832    pub fn with_exclude_unique(mut self, value: bool) -> Self {
833        self.exclude_unique = Some(value);
834        self
835    }
836
837    /// Sets a new value for the `exclude_unlimited` flag.
838    ///
839    /// # Arguments
840    ///
841    /// * `value` - Whether to exclude gifts that can be purchased an unlimited number of times.
842    pub fn with_exclude_unlimited(mut self, value: bool) -> Self {
843        self.exclude_unlimited = Some(value);
844        self
845    }
846
847    /// Sets a new limit.
848    ///
849    /// # Arguments
850    ///
851    /// * `value` - The maximum number of gifts to be returned; 1-100. Defaults to 100.
852    pub fn with_limit(mut self, value: Integer) -> Self {
853        self.limit = Some(value);
854        self
855    }
856
857    /// Sets a new offset.
858    ///
859    /// # Arguments
860    ///
861    /// * `value` - Offset of the first entry to return as received from the previous request;
862    ///   use an empty string to get the first chunk of results.
863    pub fn with_offset<T>(mut self, value: T) -> Self
864    where
865        T: Into<String>,
866    {
867        self.offset = Some(value.into());
868        self
869    }
870
871    /// Sets a new value for the `sort_by_price` flag.
872    ///
873    /// # Arguments
874    ///
875    /// * `value` - Whether to sort results by gift price instead of send date.
876    ///   Sorting is applied before pagination.
877    pub fn with_sort_by_price(mut self, value: bool) -> Self {
878        self.sort_by_price = Some(value);
879        self
880    }
881}
882
883impl Method for GetUserGifts {
884    type Response = OwnedGifts;
885
886    fn into_payload(self) -> Payload {
887        Payload::json("getUserGifts", self)
888    }
889}
890
891/// Describes a gift received and owned by a user or a chat.
892#[derive(Clone, Debug, derive_more::From, Deserialize, PartialEq, Serialize)]
893#[serde(tag = "type", rename_all = "snake_case")]
894pub enum OwnedGift {
895    /// A regular gift owned by a user or a chat.
896    #[from(OwnedGiftRegular)]
897    Regular(Box<OwnedGiftRegular>),
898    /// A unique gift received and owned by a user or a chat.
899    #[from(OwnedGiftUnique)]
900    Unique(Box<OwnedGiftUnique>),
901}
902
903/// Describes a regular gift owned by a user or a chat.
904#[serde_with::skip_serializing_none]
905#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
906pub struct OwnedGiftRegular {
907    /// Information about the regular gift.
908    pub gift: Gift,
909    /// Date the gift was sent in Unix time.
910    pub send_date: Integer,
911    /// Whether the gift can be upgraded to a unique gift;
912    /// for gifts received on behalf of business accounts only.
913    pub can_be_upgraded: Option<bool>,
914    /// Number of Telegram Stars that can be claimed by the receiver instead of the gift;
915    /// omitted if the gift cannot be converted to Telegram Stars.
916    pub convert_star_count: Option<Integer>,
917    /// Special entities that appear in the text.
918    pub entities: Option<TextEntities>,
919    /// Whether the sender and gift text are shown only to the gift receiver;
920    /// otherwise, everyone will be able to see them.
921    pub is_private: Option<bool>,
922    /// Whether the gift is displayed on the account's profile page;
923    /// for gifts received on behalf of business accounts only.
924    pub is_saved: Option<bool>,
925    /// Whether the gift's upgrade was purchased after the gift was sent;
926    /// for gifts received on behalf of business accounts only.
927    pub is_upgrade_separate: Option<bool>,
928    /// Unique identifier of the gift for the bot; for gifts received on behalf of business accounts only.
929    pub owned_gift_id: Option<String>,
930    /// Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift.
931    pub prepaid_upgrade_star_count: Option<Integer>,
932    /// Sender of the gift if it is a known user.
933    pub sender_user: Option<User>,
934    /// Text of the message that was added to the gift.
935    pub text: Option<String>,
936    /// Unique number reserved for this gift when upgraded.
937    ///
938    /// See the number field in [`crate::types::UniqueGift`].
939    pub unique_gift_number: Option<Integer>,
940    /// Whether the gift was refunded and isn't available anymore.
941    pub was_refunded: Option<bool>,
942}
943
944impl OwnedGiftRegular {
945    /// Creates a new `OwnedGiftRegular`.
946    ///
947    /// # Arguments
948    ///
949    /// * `gift` - Information about the regular gift.
950    /// * `send_date` - Date the gift was sent in Unix time.
951    pub fn new(gift: Gift, send_date: Integer) -> Self {
952        Self {
953            gift,
954            send_date,
955            can_be_upgraded: None,
956            convert_star_count: None,
957            entities: None,
958            is_private: None,
959            is_saved: None,
960            is_upgrade_separate: None,
961            owned_gift_id: None,
962            prepaid_upgrade_star_count: None,
963            sender_user: None,
964            text: None,
965            unique_gift_number: None,
966            was_refunded: None,
967        }
968    }
969
970    /// Sets a new value for the `can_be_upgraded` flag.
971    ///
972    /// # Arguments
973    ///
974    /// * `value` - Whether the gift can be upgraded to a unique gift;
975    ///   for gifts received on behalf of business accounts only.
976    pub fn with_can_be_upgraded(mut self, value: bool) -> Self {
977        self.can_be_upgraded = Some(value);
978        self
979    }
980
981    /// Sets a new convert star count.
982    ///
983    /// # Arguments
984    ///
985    /// * `value` - Number of Telegram Stars that can be claimed by the receiver instead of the gift;
986    ///   omitted if the gift cannot be converted to Telegram Stars.
987    pub fn with_convert_star_count(mut self, value: Integer) -> Self {
988        self.convert_star_count = Some(value);
989        self
990    }
991
992    /// Sets a new list of text entities.
993    ///
994    /// # Arguments
995    ///
996    /// * `value` - Special entities that appear in the text.
997    pub fn with_entities<T>(mut self, value: T) -> Self
998    where
999        T: IntoIterator<Item = TextEntity>,
1000    {
1001        self.entities = Some(value.into_iter().collect());
1002        self
1003    }
1004
1005    /// Sets a new value for the `is_private` flag.
1006    ///
1007    /// # Arguments
1008    ///
1009    /// * `value` - Whether the sender and gift text are shown only to the gift receiver;
1010    ///   otherwise, everyone will be able to see them.
1011    pub fn with_is_private(mut self, value: bool) -> Self {
1012        self.is_private = Some(value);
1013        self
1014    }
1015
1016    /// Sets a new value for the `is_saved` flag.
1017    ///
1018    /// # Arguments
1019    ///
1020    /// * `value` - Whether the gift is displayed on the account's profile page;
1021    ///   for gifts received on behalf of business accounts only.
1022    pub fn with_is_saved(mut self, value: bool) -> Self {
1023        self.is_saved = Some(value);
1024        self
1025    }
1026
1027    /// Sets a new value for the `is_upgrade_separate` flag.
1028    ///
1029    /// # Arguments
1030    ///
1031    /// * `value` - Whether the gift's upgrade was purchased after the gift was sent;
1032    ///   for gifts received on behalf of business accounts only.
1033    pub fn with_is_upgrade_separate(mut self, value: bool) -> Self {
1034        self.is_upgrade_separate = Some(value);
1035        self
1036    }
1037
1038    /// Sets a new owned gift ID.
1039    ///
1040    /// # Arguments
1041    ///
1042    /// * `value` - Unique identifier of the gift for the bot;
1043    ///   for gifts received on behalf of business accounts only.
1044    pub fn with_owned_gift_id<T>(mut self, value: T) -> Self
1045    where
1046        T: Into<String>,
1047    {
1048        self.owned_gift_id = Some(value.into());
1049        self
1050    }
1051
1052    /// Sets a new prepaid upgrade star count.
1053    ///
1054    /// # Arguments
1055    ///
1056    /// * `value` - Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift.
1057    pub fn with_prepaid_upgrade_star_count(mut self, value: Integer) -> Self {
1058        self.prepaid_upgrade_star_count = Some(value);
1059        self
1060    }
1061
1062    /// Sets a new sender user.
1063    ///
1064    /// # Arguments
1065    ///
1066    /// * `value` - Sender of the gift if it is a known user.
1067    pub fn with_sender_user(mut self, value: User) -> Self {
1068        self.sender_user = Some(value);
1069        self
1070    }
1071
1072    /// Sets a new text.
1073    ///
1074    /// # Arguments
1075    ///
1076    /// * `value` - Text of the message that was added to the gift.
1077    pub fn with_text<T>(mut self, value: T) -> Self
1078    where
1079        T: Into<String>,
1080    {
1081        self.text = Some(value.into());
1082        self
1083    }
1084
1085    /// Sets a new unique gift number.
1086    ///
1087    /// # Arguments
1088    ///
1089    /// * `value` - Unique number reserved for this gift when upgraded.
1090    pub fn with_unique_gift_number(mut self, value: Integer) -> Self {
1091        self.unique_gift_number = Some(value);
1092        self
1093    }
1094
1095    /// Sets a new value for the `was_refunded` flag.
1096    ///
1097    /// # Arguments
1098    ///
1099    /// * `value` - Whether the gift was refunded and isn't available anymore.
1100    pub fn with_was_refunded(mut self, value: bool) -> Self {
1101        self.was_refunded = Some(value);
1102        self
1103    }
1104}
1105
1106/// Describes a unique gift received and owned by a user or a chat.
1107#[serde_with::skip_serializing_none]
1108#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1109pub struct OwnedGiftUnique {
1110    /// Information about the unique gift.
1111    pub gift: UniqueGift,
1112    /// Date the gift was sent in Unix time.
1113    pub send_date: Integer,
1114    /// Number of Telegram Stars that must be paid to transfer the gift;
1115    /// omitted if the bot cannot transfer the gift.
1116    pub transfer_star_count: Option<Integer>,
1117    /// Whether the gift can be transferred to another owner;
1118    /// for gifts received on behalf of business accounts only.
1119    pub can_be_transferred: Option<bool>,
1120    /// Whether the gift is displayed on the account's profile page;
1121    /// for gifts received on behalf of business accounts only.
1122    pub is_saved: Option<bool>,
1123    /// Point in time (Unix timestamp) when the gift can be transferred.
1124    ///
1125    /// If it is in the past, then the gift can be transferred now.
1126    pub next_transfer_date: Option<Integer>,
1127    /// Unique identifier of the received gift for the bot;
1128    /// for gifts received on behalf of business accounts only.
1129    pub owned_gift_id: Option<String>,
1130    /// Sender of the gift if it is a known user.
1131    pub sender_user: Option<User>,
1132}
1133
1134impl OwnedGiftUnique {
1135    /// Creates a new `OwnedGiftUnique`.
1136    ///
1137    /// # Arguments
1138    ///
1139    /// * `gift` - Information about the unique gift.
1140    /// * `send_date` - Date the gift was sent in Unix time.
1141    pub fn new(gift: UniqueGift, send_date: Integer) -> Self {
1142        Self {
1143            gift,
1144            send_date,
1145            transfer_star_count: None,
1146            can_be_transferred: None,
1147            is_saved: None,
1148            next_transfer_date: None,
1149            owned_gift_id: None,
1150            sender_user: None,
1151        }
1152    }
1153
1154    /// Sets a new transfer star count.
1155    ///
1156    /// # Arguments
1157    ///
1158    /// * `value` Number of Telegram Stars that must be paid to transfer the gift;
1159    ///   omitted if the bot cannot transfer the gift.
1160    pub fn with_transfer_star_count(mut self, value: Integer) -> Self {
1161        self.transfer_star_count = Some(value);
1162        self
1163    }
1164
1165    /// Sets a new value for the `can_be_transferred` flag.
1166    ///
1167    /// # Arguments
1168    ///
1169    /// * `value` - Whether the gift can be transferred to another owner;
1170    ///   for gifts received on behalf of business accounts only.
1171    pub fn with_can_be_transferred(mut self, value: bool) -> Self {
1172        self.can_be_transferred = Some(value);
1173        self
1174    }
1175
1176    /// Sets a new value for the `is_saved` flag.
1177    ///
1178    /// # Arguments
1179    ///
1180    /// * `value` - Whether the gift is displayed on the account's profile page;
1181    ///   for gifts received on behalf of business accounts only.
1182    pub fn with_is_saved(mut self, value: bool) -> Self {
1183        self.is_saved = Some(value);
1184        self
1185    }
1186
1187    /// Sets a new next transfer date.
1188    ///
1189    /// # Arguments
1190    ///
1191    /// * `value` - Point in time (Unix timestamp) when the gift can be transferred.
1192    pub fn with_next_transfer_date(mut self, value: Integer) -> Self {
1193        self.next_transfer_date = Some(value);
1194        self
1195    }
1196
1197    /// Sets a new owned gift ID.
1198    ///
1199    /// # Arguments
1200    ///
1201    /// * `value` - Unique identifier of the received gift for the bot;
1202    ///   for gifts received on behalf of business accounts only.
1203    pub fn with_owned_gift_id<T>(mut self, value: T) -> Self
1204    where
1205        T: Into<String>,
1206    {
1207        self.owned_gift_id = Some(value.into());
1208        self
1209    }
1210
1211    /// Sets a new sender user.
1212    ///
1213    /// # Arguments
1214    ///
1215    /// * `value` - Sender of the gift if it is a known user.
1216    pub fn with_sender_user(mut self, value: User) -> Self {
1217        self.sender_user = Some(value);
1218        self
1219    }
1220}
1221
1222/// Contains the list of gifts received and owned by a user or a chat.
1223#[serde_with::skip_serializing_none]
1224#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1225pub struct OwnedGifts {
1226    /// The list of gifts.
1227    pub gifts: Vec<OwnedGift>,
1228    /// The total number of gifts owned by the user or the chat.
1229    pub total_count: Integer,
1230    /// Offset for the next request.
1231    ///
1232    /// If empty, then there are no more results.
1233    pub next_offset: Option<String>,
1234}
1235
1236impl OwnedGifts {
1237    /// Creates a new `OwnedGifts`.
1238    ///
1239    /// # Arguments
1240    ///
1241    /// * `gifts` - The list of gifts.
1242    /// * `total_count` - The total number of gifts owned by the user or the chat.
1243    pub fn new<T>(gifts: T, total_count: Integer) -> Self
1244    where
1245        T: IntoIterator<Item = OwnedGift>,
1246    {
1247        Self {
1248            gifts: gifts.into_iter().collect(),
1249            total_count,
1250            next_offset: None,
1251        }
1252    }
1253
1254    /// Sets a new next offset.
1255    ///
1256    /// # Arguments
1257    ///
1258    /// * `value` - Offset for the next request.
1259    pub fn with_next_offset<T>(mut self, value: T) -> Self
1260    where
1261        T: Into<String>,
1262    {
1263        self.next_offset = Some(value.into());
1264        self
1265    }
1266}
1267
1268/// Describes a unique gift that was upgraded from a regular gift.
1269#[serde_with::skip_serializing_none]
1270#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1271pub struct UniqueGift {
1272    /// Backdrop of the gift.
1273    pub backdrop: UniqueGiftBackdrop,
1274    /// Human-readable name of the regular gift from which this unique gift was upgraded.
1275    pub base_name: String,
1276    /// Identifier of the regular gift from which the gift was upgraded.
1277    pub gift_id: String,
1278    /// Model of the gift.
1279    pub model: UniqueGiftModel,
1280    /// Unique name of the gift. This name can be used in https://t.me/nft/... links and story areas.
1281    pub name: String,
1282    /// Unique number of the upgraded gift among gifts upgraded from the same regular gift.
1283    pub number: Integer,
1284    /// Symbol of the gift.
1285    pub symbol: UniqueGiftSymbol,
1286    /// The color scheme that can be used by the gift's owner for the chat's name,
1287    /// replies to messages and link previews;
1288    /// for business account gifts and gifts that are currently on sale only.
1289    pub colors: Option<UniqueGiftColors>,
1290    /// Whether the gift was used to craft another gift and isn't available anymore.
1291    pub is_burned: Option<bool>,
1292    /// Whether the gift is assigned from the TON blockchain and can't be resold or transferred in Telegram.
1293    pub is_from_blockchain: Option<bool>,
1294    /// Whether the original regular gift was exclusively purchaseable by Telegram Premium subscribers.
1295    pub is_premium: Option<bool>,
1296    /// Information about the chat that published the gift.
1297    pub publisher_chat: Option<Chat>,
1298}
1299
1300impl UniqueGift {
1301    /// Creates a new `UniqueGift`.
1302    ///
1303    /// # Arguments
1304    ///
1305    /// * `backdrop` - Backdrop of the gift.
1306    /// * `base_name` - Human-readable name of the regular gift from which this unique gift was upgraded.
1307    /// * `gift_id` - Identifier of the regular gift from which the gift was upgraded.
1308    /// * `model` - Model of the gift.
1309    /// * `name` - Unique name of the gift. This name can be used in https://t.me/nft/... links and story areas.
1310    /// * `number` - Unique number of the upgraded gift among gifts upgraded from the same regular gift.
1311    /// * `symbol` - Symbol of the gift.
1312    pub fn new<A, B, C>(
1313        backdrop: UniqueGiftBackdrop,
1314        base_name: A,
1315        gift_id: B,
1316        model: UniqueGiftModel,
1317        name: C,
1318        number: Integer,
1319        symbol: UniqueGiftSymbol,
1320    ) -> Self
1321    where
1322        A: Into<String>,
1323        B: Into<String>,
1324        C: Into<String>,
1325    {
1326        Self {
1327            backdrop,
1328            base_name: base_name.into(),
1329            gift_id: gift_id.into(),
1330            model,
1331            name: name.into(),
1332            number,
1333            symbol,
1334            colors: None,
1335            is_burned: None,
1336            is_from_blockchain: None,
1337            is_premium: None,
1338            publisher_chat: None,
1339        }
1340    }
1341
1342    /// Sets new colors.
1343    ///
1344    /// # Arguments
1345    ///
1346    /// * `value` - The color scheme that can be used by the gift's owner.
1347    pub fn with_colors(mut self, value: UniqueGiftColors) -> Self {
1348        self.colors = Some(value);
1349        self
1350    }
1351
1352    /// Sets a new value for the `is_burned` flag.
1353    ///
1354    /// # Arguments
1355    ///
1356    /// * `value` - Whether the gift was used to craft another gift.
1357    pub fn with_is_burned(mut self, value: bool) -> Self {
1358        self.is_burned = Some(value);
1359        self
1360    }
1361
1362    /// Sets a new value for the `is_from_blockchain` flag.
1363    ///
1364    /// # Arguments
1365    ///
1366    /// * `value` - Whether the gift is assigned from the TON blockchain and can't be resold or transferred in Telegram.
1367    pub fn with_is_from_blockchain(mut self, value: bool) -> Self {
1368        self.is_from_blockchain = Some(value);
1369        self
1370    }
1371
1372    /// Sets a new value for the `is_premium` flag.
1373    ///
1374    /// # Arguments
1375    ///
1376    /// * `value` - Whether the original regular gift was exclusively purchaseable by Telegram Premium subscribers.
1377    pub fn with_is_premium(mut self, value: bool) -> Self {
1378        self.is_premium = Some(value);
1379        self
1380    }
1381
1382    /// Sets a new publisher chat.
1383    ///
1384    /// # Arguments
1385    ///
1386    /// * `value` - Information about the chat that published the gift.
1387    pub fn with_publisher_chat<T>(mut self, value: T) -> Self
1388    where
1389        T: Into<Chat>,
1390    {
1391        self.publisher_chat = Some(value.into());
1392        self
1393    }
1394}
1395
1396/// Describes the backdrop of a unique gift.
1397#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1398pub struct UniqueGiftBackdrop {
1399    /// Colors of the backdrop.
1400    pub colors: UniqueGiftBackdropColors,
1401    /// Name of the backdrop.
1402    pub name: String,
1403    /// The number of unique gifts that receive this backdrop for every 1000 gifts upgraded.
1404    pub rarity_per_mille: Integer,
1405}
1406
1407/// Describes the colors of the backdrop of a unique gift.
1408#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1409pub struct UniqueGiftBackdropColors {
1410    /// The color in the center of the backdrop in RGB format
1411    pub center_color: Integer,
1412    /// The color on the edges of the backdrop in RGB format
1413    pub edge_color: Integer,
1414    /// The color to be applied to the symbol in RGB format
1415    pub symbol_color: Integer,
1416    /// The color for the text on the backdrop in RGB format
1417    pub text_color: Integer,
1418}
1419
1420/// Contains information about the color scheme for a user's name,
1421/// message replies and link previews based on a unique gift.
1422#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1423pub struct UniqueGiftColors {
1424    /// Main color used in dark themes; RGB format.
1425    pub dark_theme_main_color: Integer,
1426    /// List of 1-3 additional colors used in dark themes; RGB format.
1427    pub dark_theme_other_colors: Vec<Integer>,
1428    /// Main color used in light themes; RGB format.
1429    pub light_theme_main_color: Integer,
1430    /// List of 1-3 additional colors used in light themes; RGB format.
1431    pub light_theme_other_colors: Vec<Integer>,
1432    /// Custom emoji identifier of the unique gift's model.
1433    pub model_custom_emoji_id: String,
1434    /// Custom emoji identifier of the unique gift's symbol.
1435    pub symbol_custom_emoji_id: String,
1436}
1437
1438/// Describes the model of a unique gift.
1439#[serde_with::skip_serializing_none]
1440#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1441pub struct UniqueGiftModel {
1442    /// Name of the model.
1443    pub name: String,
1444    /// The number of unique gifts that receive this model for every 1000 gifts upgraded.
1445    pub rarity_per_mille: Integer,
1446    /// The sticker that represents the unique gift
1447    pub sticker: Sticker,
1448    /// Rarity of the model if it is a crafted model.
1449    pub rarity: Option<UniqueGiftModelRarity>,
1450}
1451
1452/// Rarity of a unique gift model.
1453#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1454#[serde(rename_all = "snake_case")]
1455pub enum UniqueGiftModelRarity {
1456    /// Epic.
1457    Epic,
1458    /// Legendary.
1459    Legendary,
1460    /// Rare.
1461    Rare,
1462    /// Uncommon.
1463    Uncommon,
1464}
1465
1466/// Describes the symbol shown on the pattern of a unique gift.
1467#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1468pub struct UniqueGiftSymbol {
1469    /// Name of the symbol.
1470    pub name: String,
1471    /// The number of unique gifts that receive this model for every 1000 gifts upgraded.
1472    pub rarity_per_mille: Integer,
1473    /// The sticker that represents the unique gift.
1474    pub sticker: Sticker,
1475}
1476
1477/// Origin of the unique gift.
1478#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1479#[serde(rename_all = "snake_case")]
1480pub enum UniqueGiftOrigin {
1481    /// For upgrades purchased after the gift was sent.
1482    GiftedUpgrade,
1483    /// Gifts bought or sold through gift purchase offers.
1484    Offer,
1485    /// Resale for gifts bought from other users.
1486    Resale,
1487    /// Transfer for gifts transferred from other users or channels.
1488    Transfer,
1489    /// Upgrade for gifts upgraded from regular gifts.
1490    Upgrade,
1491}
1492
1493/// Describes a service message about a unique gift that was sent or received.
1494#[serde_with::skip_serializing_none]
1495#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1496pub struct UniqueGiftInfo {
1497    /// Information about the gift.
1498    pub gift: UniqueGift,
1499    /// Origin of the gift.
1500    pub origin: UniqueGiftOrigin,
1501    /// For gifts bought from other users, the price paid for the gift.
1502    pub last_resale_star_count: Option<Integer>,
1503    /// Point in time (Unix timestamp) when the gift can be transferred.
1504    ///
1505    /// If it is in the past, then the gift can be transferred now.
1506    pub next_transfer_date: Option<Integer>,
1507    /// Unique identifier of the received gift for the bot;
1508    /// only present for gifts received on behalf of business accounts.
1509    pub owned_gift_id: Option<String>,
1510    /// Number of Telegram Stars that must be paid to transfer the gift;
1511    /// omitted if the bot cannot transfer the gift.
1512    pub transfer_star_count: Option<Integer>,
1513}
1514
1515impl UniqueGiftInfo {
1516    /// Creates a new `UniqueGiftInfo`.
1517    ///
1518    /// # Arguments
1519    ///
1520    /// * `gift` - Information about the gift.
1521    /// * `origin` - Origin of the gift.
1522    pub fn new(gift: UniqueGift, origin: UniqueGiftOrigin) -> Self {
1523        Self {
1524            gift,
1525            origin,
1526            last_resale_star_count: None,
1527            next_transfer_date: None,
1528            owned_gift_id: None,
1529            transfer_star_count: None,
1530        }
1531    }
1532
1533    /// Sets a new last resale star count.
1534    ///
1535    /// # Arguments
1536    ///
1537    /// * `value` - The price paid for the gift.
1538    pub fn with_last_resale_star_count(mut self, value: Integer) -> Self {
1539        self.last_resale_star_count = Some(value);
1540        self
1541    }
1542
1543    /// Sets a new next transfer date.
1544    ///
1545    /// # Arguments
1546    ///
1547    /// * `value` - Point in time (Unix timestamp) when the gift can be transferred.
1548    pub fn with_next_transfer_date(mut self, value: Integer) -> Self {
1549        self.next_transfer_date = Some(value);
1550        self
1551    }
1552
1553    /// Sets a new owned gift ID.
1554    ///
1555    /// # Arguments
1556    ///
1557    /// * `value` - Unique identifier of the received gift for the bot;
1558    ///   only present for gifts received on behalf of business accounts.
1559    pub fn with_owned_gift_id<T>(mut self, value: T) -> Self
1560    where
1561        T: Into<String>,
1562    {
1563        self.owned_gift_id = Some(value.into());
1564        self
1565    }
1566
1567    /// Sets a new transfer star count.
1568    ///
1569    /// # Arguments
1570    ///
1571    /// * `value` - Number of Telegram Stars that must be paid to transfer the gift;
1572    ///   omitted if the bot cannot transfer the gift.
1573    pub fn with_transfer_star_count(mut self, value: Integer) -> Self {
1574        self.transfer_star_count = Some(value);
1575        self
1576    }
1577}
1578
1579/// Gifts a Telegram Premium subscription to the given user.
1580#[serde_with::skip_serializing_none]
1581#[derive(Clone, Debug, Serialize)]
1582pub struct GiftPremiumSubscription {
1583    month_count: Integer,
1584    star_count: Integer,
1585    user_id: Integer,
1586    text: Option<String>,
1587    text_entities: Option<TextEntities>,
1588    text_parse_mode: Option<ParseMode>,
1589}
1590
1591impl GiftPremiumSubscription {
1592    /// Creates a new `GiftPremiumSubscription`.
1593    ///
1594    /// # Arguments
1595    ///
1596    /// * `month_count` - Number of months the Telegram Premium subscription will be active for the user;
1597    ///   must be one of 3, 6, or 12.
1598    /// * `star_count` - Number of Telegram Stars to pay for the Telegram Premium subscription;
1599    ///   must be 1000 for 3 months, 1500 for 6 months, and 2500 for 12 months.
1600    /// * `user_id` - Unique identifier of the target user who will receive a Telegram Premium subscription.
1601    pub fn new(month_count: Integer, star_count: Integer, user_id: Integer) -> Self {
1602        Self {
1603            month_count,
1604            star_count,
1605            user_id,
1606            text: None,
1607            text_entities: None,
1608            text_parse_mode: None,
1609        }
1610    }
1611
1612    /// Sets a new text.
1613    ///
1614    /// # Arguments
1615    ///
1616    /// * `value` - Text that will be shown along with the service message about the subscription; 0-128 characters
1617    pub fn with_text<T>(mut self, value: T) -> Self
1618    where
1619        T: Into<String>,
1620    {
1621        self.text = Some(value.into());
1622        self
1623    }
1624
1625    /// Sets a new list of text entities.
1626    ///
1627    /// # Arguments
1628    ///
1629    /// * `value` - A list of special entities that appear in the gift text.
1630    ///   Entities other than “bold”, “italic”, “underline”,
1631    ///   “strikethrough”, “spoiler”, “custom_emoji” and "date_time" are ignored.
1632    pub fn with_text_entities<T>(mut self, value: T) -> Self
1633    where
1634        T: IntoIterator<Item = TextEntity>,
1635    {
1636        self.text_parse_mode = None;
1637        self.text_entities = Some(TextEntities::from_iter(value));
1638        self
1639    }
1640
1641    /// Sets a new text parse mode.
1642    ///
1643    /// # Arguments
1644    ///
1645    /// * `value` - Mode for parsing entities in the text.
1646    ///   Entities other than “bold”, “italic”, “underline”,
1647    ///   “strikethrough”, “spoiler”, “custom_emoji” and "date_time" are ignored.
1648    pub fn with_text_parse_mode(mut self, value: ParseMode) -> Self {
1649        self.text_entities = None;
1650        self.text_parse_mode = Some(value);
1651        self
1652    }
1653}
1654
1655impl Method for GiftPremiumSubscription {
1656    type Response = bool;
1657
1658    fn into_payload(self) -> Payload {
1659        Payload::json("giftPremiumSubscription", self)
1660    }
1661}
1662
1663/// Sends a gift to the given user.
1664///
1665/// The gift can't be converted to Telegram Stars by the user.
1666#[serde_with::skip_serializing_none]
1667#[derive(Clone, Debug, Serialize)]
1668pub struct SendGift {
1669    gift_id: String,
1670    chat_id: Option<ChatId>,
1671    pay_for_upgrade: Option<bool>,
1672    text: Option<String>,
1673    text_parse_mode: Option<ParseMode>,
1674    text_entities: Option<TextEntities>,
1675    user_id: Option<Integer>,
1676}
1677
1678impl SendGift {
1679    /// Creates a new `SendGift` with a `user_id`.
1680    ///
1681    /// # Arguments
1682    ///
1683    /// * `chat_id` - Unique identifier of the target chat that will receive the gift.
1684    /// * `gift_id` - Identifier of the gift
1685    pub fn for_chat_id<A, B>(chat_id: A, gift_id: B) -> Self
1686    where
1687        A: Into<ChatId>,
1688        B: Into<String>,
1689    {
1690        Self {
1691            gift_id: gift_id.into(),
1692            chat_id: Some(chat_id.into()),
1693            pay_for_upgrade: None,
1694            text: None,
1695            text_parse_mode: None,
1696            text_entities: None,
1697            user_id: None,
1698        }
1699    }
1700
1701    /// Creates a new `SendGift` with a `user_id`.
1702    ///
1703    /// # Arguments
1704    ///
1705    /// * `user_id` - Unique identifier of the target user that will receive the gift.
1706    /// * `gift_id` - Identifier of the gift
1707    pub fn for_user_id<T>(user_id: Integer, gift_id: T) -> Self
1708    where
1709        T: Into<String>,
1710    {
1711        Self {
1712            gift_id: gift_id.into(),
1713            chat_id: None,
1714            pay_for_upgrade: None,
1715            text: None,
1716            text_parse_mode: None,
1717            text_entities: None,
1718            user_id: Some(user_id),
1719        }
1720    }
1721
1722    /// Sets a new value for the `pay_for_upgrade` flag.
1723    ///
1724    /// # Arguments
1725    ///
1726    /// * `value` - Whether to pay for the gift upgrade from the bot's balance,
1727    ///   thereby making the upgrade free for the receiver.
1728    pub fn with_pay_for_upgrade(mut self, value: bool) -> Self {
1729        self.pay_for_upgrade = Some(value);
1730        self
1731    }
1732
1733    /// Sets a new text.
1734    ///
1735    /// # Arguments
1736    ///
1737    /// * `value` - Text that will be shown along with the gift; 0-255 characters.
1738    pub fn with_text<T>(mut self, value: T) -> Self
1739    where
1740        T: Into<String>,
1741    {
1742        self.text = Some(value.into());
1743        self
1744    }
1745
1746    /// Sets a new text parse mode.
1747    ///
1748    /// # Arguments
1749    ///
1750    /// * `value` - Mode for parsing entities in the text.
1751    ///
1752    /// Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”,
1753    /// “custom_emoji” and "date_time" are ignored.
1754    ///
1755    /// Text entities will be set to [`None`] when this method is called.
1756    pub fn with_text_parse_mode(mut self, value: ParseMode) -> Self {
1757        self.text_parse_mode = Some(value);
1758        self.text_entities = None;
1759        self
1760    }
1761
1762    /// Sets a new text entities.
1763    ///
1764    /// # Arguments
1765    ///
1766    /// * `value` - A list of special entities that appear in the gift text.
1767    ///
1768    /// Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”,
1769    /// “custom_emoji” and "date_time" are ignored.
1770    ///
1771    /// Text parse mode will be set to [`None`] when this method is called.
1772    pub fn with_text_entities<T>(mut self, value: T) -> Self
1773    where
1774        T: IntoIterator<Item = TextEntity>,
1775    {
1776        self.text_entities = Some(value.into_iter().collect());
1777        self.text_parse_mode = None;
1778        self
1779    }
1780}
1781
1782impl Method for SendGift {
1783    type Response = bool;
1784
1785    fn into_payload(self) -> Payload {
1786        Payload::json("sendGift", self)
1787    }
1788}