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")]
894#[allow(clippy::large_enum_variant)]
895pub enum OwnedGift {
896    /// A regular gift owned by a user or a chat.
897    Regular(OwnedGiftRegular),
898    /// A unique gift received and owned by a user or a chat.
899    Unique(OwnedGiftUnique),
900}
901
902/// Describes a regular gift owned by a user or a chat.
903#[serde_with::skip_serializing_none]
904#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
905pub struct OwnedGiftRegular {
906    /// Information about the regular gift.
907    pub gift: Gift,
908    /// Date the gift was sent in Unix time.
909    pub send_date: Integer,
910    /// Whether the gift can be upgraded to a unique gift;
911    /// for gifts received on behalf of business accounts only.
912    pub can_be_upgraded: Option<bool>,
913    /// Number of Telegram Stars that can be claimed by the receiver instead of the gift;
914    /// omitted if the gift cannot be converted to Telegram Stars.
915    pub convert_star_count: Option<Integer>,
916    /// Special entities that appear in the text.
917    pub entities: Option<TextEntities>,
918    /// Whether the sender and gift text are shown only to the gift receiver;
919    /// otherwise, everyone will be able to see them.
920    pub is_private: Option<bool>,
921    /// Whether the gift is displayed on the account's profile page;
922    /// for gifts received on behalf of business accounts only.
923    pub is_saved: Option<bool>,
924    /// Whether the gift's upgrade was purchased after the gift was sent;
925    /// for gifts received on behalf of business accounts only.
926    pub is_upgrade_separate: Option<bool>,
927    /// Unique identifier of the gift for the bot; for gifts received on behalf of business accounts only.
928    pub owned_gift_id: Option<String>,
929    /// Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift.
930    pub prepaid_upgrade_star_count: Option<Integer>,
931    /// Sender of the gift if it is a known user.
932    pub sender_user: Option<User>,
933    /// Text of the message that was added to the gift.
934    pub text: Option<String>,
935    /// Unique number reserved for this gift when upgraded.
936    ///
937    /// See the number field in [`crate::types::UniqueGift`].
938    pub unique_gift_number: Option<Integer>,
939    /// Whether the gift was refunded and isn't available anymore.
940    pub was_refunded: Option<bool>,
941}
942
943impl OwnedGiftRegular {
944    /// Creates a new `OwnedGiftRegular`.
945    ///
946    /// # Arguments
947    ///
948    /// * `gift` - Information about the regular gift.
949    /// * `send_date` - Date the gift was sent in Unix time.
950    pub fn new(gift: Gift, send_date: Integer) -> Self {
951        Self {
952            gift,
953            send_date,
954            can_be_upgraded: None,
955            convert_star_count: None,
956            entities: None,
957            is_private: None,
958            is_saved: None,
959            is_upgrade_separate: None,
960            owned_gift_id: None,
961            prepaid_upgrade_star_count: None,
962            sender_user: None,
963            text: None,
964            unique_gift_number: None,
965            was_refunded: None,
966        }
967    }
968
969    /// Sets a new value for the `can_be_upgraded` flag.
970    ///
971    /// # Arguments
972    ///
973    /// * `value` - Whether the gift can be upgraded to a unique gift;
974    ///   for gifts received on behalf of business accounts only.
975    pub fn with_can_be_upgraded(mut self, value: bool) -> Self {
976        self.can_be_upgraded = Some(value);
977        self
978    }
979
980    /// Sets a new convert star count.
981    ///
982    /// # Arguments
983    ///
984    /// * `value` - Number of Telegram Stars that can be claimed by the receiver instead of the gift;
985    ///   omitted if the gift cannot be converted to Telegram Stars.
986    pub fn with_convert_star_count(mut self, value: Integer) -> Self {
987        self.convert_star_count = Some(value);
988        self
989    }
990
991    /// Sets a new list of text entities.
992    ///
993    /// # Arguments
994    ///
995    /// * `value` - Special entities that appear in the text.
996    pub fn with_entities<T>(mut self, value: T) -> Self
997    where
998        T: IntoIterator<Item = TextEntity>,
999    {
1000        self.entities = Some(value.into_iter().collect());
1001        self
1002    }
1003
1004    /// Sets a new value for the `is_private` flag.
1005    ///
1006    /// # Arguments
1007    ///
1008    /// * `value` - Whether the sender and gift text are shown only to the gift receiver;
1009    ///   otherwise, everyone will be able to see them.
1010    pub fn with_is_private(mut self, value: bool) -> Self {
1011        self.is_private = Some(value);
1012        self
1013    }
1014
1015    /// Sets a new value for the `is_saved` flag.
1016    ///
1017    /// # Arguments
1018    ///
1019    /// * `value` - Whether the gift is displayed on the account's profile page;
1020    ///   for gifts received on behalf of business accounts only.
1021    pub fn with_is_saved(mut self, value: bool) -> Self {
1022        self.is_saved = Some(value);
1023        self
1024    }
1025
1026    /// Sets a new value for the `is_upgrade_separate` flag.
1027    ///
1028    /// # Arguments
1029    ///
1030    /// * `value` - Whether the gift's upgrade was purchased after the gift was sent;
1031    ///   for gifts received on behalf of business accounts only.
1032    pub fn with_is_upgrade_separate(mut self, value: bool) -> Self {
1033        self.is_upgrade_separate = Some(value);
1034        self
1035    }
1036
1037    /// Sets a new owned gift ID.
1038    ///
1039    /// # Arguments
1040    ///
1041    /// * `value` - Unique identifier of the gift for the bot;
1042    ///   for gifts received on behalf of business accounts only.
1043    pub fn with_owned_gift_id<T>(mut self, value: T) -> Self
1044    where
1045        T: Into<String>,
1046    {
1047        self.owned_gift_id = Some(value.into());
1048        self
1049    }
1050
1051    /// Sets a new prepaid upgrade star count.
1052    ///
1053    /// # Arguments
1054    ///
1055    /// * `value` - Number of Telegram Stars that were paid by the sender for the ability to upgrade the gift.
1056    pub fn with_prepaid_upgrade_star_count(mut self, value: Integer) -> Self {
1057        self.prepaid_upgrade_star_count = Some(value);
1058        self
1059    }
1060
1061    /// Sets a new sender user.
1062    ///
1063    /// # Arguments
1064    ///
1065    /// * `value` - Sender of the gift if it is a known user.
1066    pub fn with_sender_user(mut self, value: User) -> Self {
1067        self.sender_user = Some(value);
1068        self
1069    }
1070
1071    /// Sets a new text.
1072    ///
1073    /// # Arguments
1074    ///
1075    /// * `value` - Text of the message that was added to the gift.
1076    pub fn with_text<T>(mut self, value: T) -> Self
1077    where
1078        T: Into<String>,
1079    {
1080        self.text = Some(value.into());
1081        self
1082    }
1083
1084    /// Sets a new unique gift number.
1085    ///
1086    /// # Arguments
1087    ///
1088    /// * `value` - Unique number reserved for this gift when upgraded.
1089    pub fn with_unique_gift_number(mut self, value: Integer) -> Self {
1090        self.unique_gift_number = Some(value);
1091        self
1092    }
1093
1094    /// Sets a new value for the `was_refunded` flag.
1095    ///
1096    /// # Arguments
1097    ///
1098    /// * `value` - Whether the gift was refunded and isn't available anymore.
1099    pub fn with_was_refunded(mut self, value: bool) -> Self {
1100        self.was_refunded = Some(value);
1101        self
1102    }
1103}
1104
1105/// Describes a unique gift received and owned by a user or a chat.
1106#[serde_with::skip_serializing_none]
1107#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1108pub struct OwnedGiftUnique {
1109    /// Information about the unique gift.
1110    pub gift: UniqueGift,
1111    /// Date the gift was sent in Unix time.
1112    pub send_date: Integer,
1113    /// Number of Telegram Stars that must be paid to transfer the gift;
1114    /// omitted if the bot cannot transfer the gift.
1115    pub transfer_star_count: Option<Integer>,
1116    /// Whether the gift can be transferred to another owner;
1117    /// for gifts received on behalf of business accounts only.
1118    pub can_be_transferred: Option<bool>,
1119    /// Whether the gift is displayed on the account's profile page;
1120    /// for gifts received on behalf of business accounts only.
1121    pub is_saved: Option<bool>,
1122    /// Point in time (Unix timestamp) when the gift can be transferred.
1123    ///
1124    /// If it is in the past, then the gift can be transferred now.
1125    pub next_transfer_date: Option<Integer>,
1126    /// Unique identifier of the received gift for the bot;
1127    /// for gifts received on behalf of business accounts only.
1128    pub owned_gift_id: Option<String>,
1129    /// Sender of the gift if it is a known user.
1130    pub sender_user: Option<User>,
1131}
1132
1133impl OwnedGiftUnique {
1134    /// Creates a new `OwnedGiftUnique`.
1135    ///
1136    /// # Arguments
1137    ///
1138    /// * `gift` - Information about the unique gift.
1139    /// * `send_date` - Date the gift was sent in Unix time.
1140    pub fn new(gift: UniqueGift, send_date: Integer) -> Self {
1141        Self {
1142            gift,
1143            send_date,
1144            transfer_star_count: None,
1145            can_be_transferred: None,
1146            is_saved: None,
1147            next_transfer_date: None,
1148            owned_gift_id: None,
1149            sender_user: None,
1150        }
1151    }
1152
1153    /// Sets a new transfer star count.
1154    ///
1155    /// # Arguments
1156    ///
1157    /// * `value` Number of Telegram Stars that must be paid to transfer the gift;
1158    ///   omitted if the bot cannot transfer the gift.
1159    pub fn with_transfer_star_count(mut self, value: Integer) -> Self {
1160        self.transfer_star_count = Some(value);
1161        self
1162    }
1163
1164    /// Sets a new value for the `can_be_transferred` flag.
1165    ///
1166    /// # Arguments
1167    ///
1168    /// * `value` - Whether the gift can be transferred to another owner;
1169    ///   for gifts received on behalf of business accounts only.
1170    pub fn with_can_be_transferred(mut self, value: bool) -> Self {
1171        self.can_be_transferred = Some(value);
1172        self
1173    }
1174
1175    /// Sets a new value for the `is_saved` flag.
1176    ///
1177    /// # Arguments
1178    ///
1179    /// * `value` - Whether the gift is displayed on the account's profile page;
1180    ///   for gifts received on behalf of business accounts only.
1181    pub fn with_is_saved(mut self, value: bool) -> Self {
1182        self.is_saved = Some(value);
1183        self
1184    }
1185
1186    /// Sets a new next transfer date.
1187    ///
1188    /// # Arguments
1189    ///
1190    /// * `value` - Point in time (Unix timestamp) when the gift can be transferred.
1191    pub fn with_next_transfer_date(mut self, value: Integer) -> Self {
1192        self.next_transfer_date = Some(value);
1193        self
1194    }
1195
1196    /// Sets a new owned gift ID.
1197    ///
1198    /// # Arguments
1199    ///
1200    /// * `value` - Unique identifier of the received gift for the bot;
1201    ///   for gifts received on behalf of business accounts only.
1202    pub fn with_owned_gift_id<T>(mut self, value: T) -> Self
1203    where
1204        T: Into<String>,
1205    {
1206        self.owned_gift_id = Some(value.into());
1207        self
1208    }
1209
1210    /// Sets a new sender user.
1211    ///
1212    /// # Arguments
1213    ///
1214    /// * `value` - Sender of the gift if it is a known user.
1215    pub fn with_sender_user(mut self, value: User) -> Self {
1216        self.sender_user = Some(value);
1217        self
1218    }
1219}
1220
1221/// Contains the list of gifts received and owned by a user or a chat.
1222#[serde_with::skip_serializing_none]
1223#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1224pub struct OwnedGifts {
1225    /// The list of gifts.
1226    pub gifts: Vec<OwnedGift>,
1227    /// The total number of gifts owned by the user or the chat.
1228    pub total_count: Integer,
1229    /// Offset for the next request.
1230    ///
1231    /// If empty, then there are no more results.
1232    pub next_offset: Option<String>,
1233}
1234
1235impl OwnedGifts {
1236    /// Creates a new `OwnedGifts`.
1237    ///
1238    /// # Arguments
1239    ///
1240    /// * `gifts` - The list of gifts.
1241    /// * `total_count` - The total number of gifts owned by the user or the chat.
1242    pub fn new<T>(gifts: T, total_count: Integer) -> Self
1243    where
1244        T: IntoIterator<Item = OwnedGift>,
1245    {
1246        Self {
1247            gifts: gifts.into_iter().collect(),
1248            total_count,
1249            next_offset: None,
1250        }
1251    }
1252
1253    /// Sets a new next offset.
1254    ///
1255    /// # Arguments
1256    ///
1257    /// * `value` - Offset for the next request.
1258    pub fn with_next_offset<T>(mut self, value: T) -> Self
1259    where
1260        T: Into<String>,
1261    {
1262        self.next_offset = Some(value.into());
1263        self
1264    }
1265}
1266
1267/// Describes a unique gift that was upgraded from a regular gift.
1268#[serde_with::skip_serializing_none]
1269#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1270pub struct UniqueGift {
1271    /// Backdrop of the gift.
1272    pub backdrop: UniqueGiftBackdrop,
1273    /// Human-readable name of the regular gift from which this unique gift was upgraded.
1274    pub base_name: String,
1275    /// Identifier of the regular gift from which the gift was upgraded.
1276    pub gift_id: String,
1277    /// Model of the gift.
1278    pub model: UniqueGiftModel,
1279    /// Unique name of the gift. This name can be used in https://t.me/nft/... links and story areas.
1280    pub name: String,
1281    /// Unique number of the upgraded gift among gifts upgraded from the same regular gift.
1282    pub number: Integer,
1283    /// Symbol of the gift.
1284    pub symbol: UniqueGiftSymbol,
1285    /// The color scheme that can be used by the gift's owner for the chat's name,
1286    /// replies to messages and link previews;
1287    /// for business account gifts and gifts that are currently on sale only.
1288    pub colors: Option<UniqueGiftColors>,
1289    /// Whether the gift is assigned from the TON blockchain and can't be resold or transferred in Telegram.
1290    pub is_from_blockchain: Option<bool>,
1291    /// Whether the original regular gift was exclusively purchaseable by Telegram Premium subscribers.
1292    pub is_premium: Option<bool>,
1293    /// Information about the chat that published the gift.
1294    pub publisher_chat: Option<Chat>,
1295}
1296
1297impl UniqueGift {
1298    /// Creates a new `UniqueGift`.
1299    ///
1300    /// # Arguments
1301    ///
1302    /// * `backdrop` - Backdrop of the gift.
1303    /// * `base_name` - Human-readable name of the regular gift from which this unique gift was upgraded.
1304    /// * `gift_id` - Identifier of the regular gift from which the gift was upgraded.
1305    /// * `model` - Model of the gift.
1306    /// * `name` - Unique name of the gift. This name can be used in https://t.me/nft/... links and story areas.
1307    /// * `number` - Unique number of the upgraded gift among gifts upgraded from the same regular gift.
1308    /// * `symbol` - Symbol of the gift.
1309    pub fn new<A, B, C>(
1310        backdrop: UniqueGiftBackdrop,
1311        base_name: A,
1312        gift_id: B,
1313        model: UniqueGiftModel,
1314        name: C,
1315        number: Integer,
1316        symbol: UniqueGiftSymbol,
1317    ) -> Self
1318    where
1319        A: Into<String>,
1320        B: Into<String>,
1321        C: Into<String>,
1322    {
1323        Self {
1324            backdrop,
1325            base_name: base_name.into(),
1326            gift_id: gift_id.into(),
1327            model,
1328            name: name.into(),
1329            number,
1330            symbol,
1331            colors: None,
1332            is_from_blockchain: None,
1333            is_premium: None,
1334            publisher_chat: None,
1335        }
1336    }
1337
1338    /// Sets new colors.
1339    ///
1340    /// # Arguments
1341    ///
1342    /// * `value` - The color scheme that can be used by the gift's owner.
1343    pub fn with_colors(mut self, value: UniqueGiftColors) -> Self {
1344        self.colors = Some(value);
1345        self
1346    }
1347
1348    /// Sets a new value for the `is_from_blockchain` flag.
1349    ///
1350    /// # Arguments
1351    ///
1352    /// * `value` - Whether the gift is assigned from the TON blockchain and can't be resold or transferred in Telegram.
1353    pub fn with_is_from_blockchain(mut self, value: bool) -> Self {
1354        self.is_from_blockchain = Some(value);
1355        self
1356    }
1357
1358    /// Sets a new value for the `is_premium` flag.
1359    ///
1360    /// # Arguments
1361    ///
1362    /// * `value` - Whether the original regular gift was exclusively purchaseable by Telegram Premium subscribers.
1363    pub fn with_is_premium(mut self, value: bool) -> Self {
1364        self.is_premium = Some(value);
1365        self
1366    }
1367
1368    /// Sets a new publisher chat.
1369    ///
1370    /// # Arguments
1371    ///
1372    /// * `value` - Information about the chat that published the gift.
1373    pub fn with_publisher_chat<T>(mut self, value: T) -> Self
1374    where
1375        T: Into<Chat>,
1376    {
1377        self.publisher_chat = Some(value.into());
1378        self
1379    }
1380}
1381
1382/// Describes the backdrop of a unique gift.
1383#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1384pub struct UniqueGiftBackdrop {
1385    /// Colors of the backdrop.
1386    pub colors: UniqueGiftBackdropColors,
1387    /// Name of the backdrop.
1388    pub name: String,
1389    /// The number of unique gifts that receive this backdrop for every 1000 gifts upgraded.
1390    pub rarity_per_mille: Integer,
1391}
1392
1393/// Describes the colors of the backdrop of a unique gift.
1394#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1395pub struct UniqueGiftBackdropColors {
1396    /// The color in the center of the backdrop in RGB format
1397    pub center_color: Integer,
1398    /// The color on the edges of the backdrop in RGB format
1399    pub edge_color: Integer,
1400    /// The color to be applied to the symbol in RGB format
1401    pub symbol_color: Integer,
1402    /// The color for the text on the backdrop in RGB format
1403    pub text_color: Integer,
1404}
1405
1406/// Contains information about the color scheme for a user's name,
1407/// message replies and link previews based on a unique gift.
1408#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1409pub struct UniqueGiftColors {
1410    /// Main color used in dark themes; RGB format.
1411    pub dark_theme_main_color: Integer,
1412    /// List of 1-3 additional colors used in dark themes; RGB format.
1413    pub dark_theme_other_colors: Vec<Integer>,
1414    /// Main color used in light themes; RGB format.
1415    pub light_theme_main_color: Integer,
1416    /// List of 1-3 additional colors used in light themes; RGB format.
1417    pub light_theme_other_colors: Vec<Integer>,
1418    /// Custom emoji identifier of the unique gift's model.
1419    pub model_custom_emoji_id: String,
1420    /// Custom emoji identifier of the unique gift's symbol.
1421    pub symbol_custom_emoji_id: String,
1422}
1423
1424/// Describes the model of a unique gift.
1425#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1426pub struct UniqueGiftModel {
1427    /// Name of the model.
1428    pub name: String,
1429    /// The number of unique gifts that receive this model for every 1000 gifts upgraded.
1430    pub rarity_per_mille: Integer,
1431    /// The sticker that represents the unique gift
1432    pub sticker: Sticker,
1433}
1434
1435/// Describes the symbol shown on the pattern of a unique gift.
1436#[derive(Clone, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1437pub struct UniqueGiftSymbol {
1438    /// Name of the symbol.
1439    pub name: String,
1440    /// The number of unique gifts that receive this model for every 1000 gifts upgraded.
1441    pub rarity_per_mille: Integer,
1442    /// The sticker that represents the unique gift.
1443    pub sticker: Sticker,
1444}
1445
1446/// Origin of the unique gift.
1447#[derive(Clone, Copy, Debug, Deserialize, PartialEq, PartialOrd, Serialize)]
1448#[serde(rename_all = "snake_case")]
1449pub enum UniqueGiftOrigin {
1450    /// For upgrades purchased after the gift was sent.
1451    GiftedUpgrade,
1452    /// Gifts bought or sold through gift purchase offers.
1453    Offer,
1454    /// Resale for gifts bought from other users.
1455    Resale,
1456    /// Transfer for gifts transferred from other users or channels.
1457    Transfer,
1458    /// Upgrade for gifts upgraded from regular gifts.
1459    Upgrade,
1460}
1461
1462/// Describes a service message about a unique gift that was sent or received.
1463#[serde_with::skip_serializing_none]
1464#[derive(Clone, Debug, Deserialize, PartialEq, Serialize)]
1465pub struct UniqueGiftInfo {
1466    /// Information about the gift.
1467    pub gift: UniqueGift,
1468    /// Origin of the gift.
1469    pub origin: UniqueGiftOrigin,
1470    /// For gifts bought from other users, the price paid for the gift.
1471    pub last_resale_star_count: Option<Integer>,
1472    /// Point in time (Unix timestamp) when the gift can be transferred.
1473    ///
1474    /// If it is in the past, then the gift can be transferred now.
1475    pub next_transfer_date: Option<Integer>,
1476    /// Unique identifier of the received gift for the bot;
1477    /// only present for gifts received on behalf of business accounts.
1478    pub owned_gift_id: Option<String>,
1479    /// Number of Telegram Stars that must be paid to transfer the gift;
1480    /// omitted if the bot cannot transfer the gift.
1481    pub transfer_star_count: Option<Integer>,
1482}
1483
1484impl UniqueGiftInfo {
1485    /// Creates a new `UniqueGiftInfo`.
1486    ///
1487    /// # Arguments
1488    ///
1489    /// * `gift` - Information about the gift.
1490    /// * `origin` - Origin of the gift.
1491    pub fn new(gift: UniqueGift, origin: UniqueGiftOrigin) -> Self {
1492        Self {
1493            gift,
1494            origin,
1495            last_resale_star_count: None,
1496            next_transfer_date: None,
1497            owned_gift_id: None,
1498            transfer_star_count: None,
1499        }
1500    }
1501
1502    /// Sets a new last resale star count.
1503    ///
1504    /// # Arguments
1505    ///
1506    /// * `value` - The price paid for the gift.
1507    pub fn with_last_resale_star_count(mut self, value: Integer) -> Self {
1508        self.last_resale_star_count = Some(value);
1509        self
1510    }
1511
1512    /// Sets a new next transfer date.
1513    ///
1514    /// # Arguments
1515    ///
1516    /// * `value` - Point in time (Unix timestamp) when the gift can be transferred.
1517    pub fn with_next_transfer_date(mut self, value: Integer) -> Self {
1518        self.next_transfer_date = Some(value);
1519        self
1520    }
1521
1522    /// Sets a new owned gift ID.
1523    ///
1524    /// # Arguments
1525    ///
1526    /// * `value` - Unique identifier of the received gift for the bot;
1527    ///   only present for gifts received on behalf of business accounts.
1528    pub fn with_owned_gift_id<T>(mut self, value: T) -> Self
1529    where
1530        T: Into<String>,
1531    {
1532        self.owned_gift_id = Some(value.into());
1533        self
1534    }
1535
1536    /// Sets a new transfer star count.
1537    ///
1538    /// # Arguments
1539    ///
1540    /// * `value` - Number of Telegram Stars that must be paid to transfer the gift;
1541    ///   omitted if the bot cannot transfer the gift.
1542    pub fn with_transfer_star_count(mut self, value: Integer) -> Self {
1543        self.transfer_star_count = Some(value);
1544        self
1545    }
1546}
1547
1548/// Gifts a Telegram Premium subscription to the given user.
1549#[serde_with::skip_serializing_none]
1550#[derive(Clone, Debug, Serialize)]
1551pub struct GiftPremiumSubscription {
1552    month_count: Integer,
1553    star_count: Integer,
1554    user_id: Integer,
1555    text: Option<String>,
1556    text_entities: Option<TextEntities>,
1557    text_parse_mode: Option<ParseMode>,
1558}
1559
1560impl GiftPremiumSubscription {
1561    /// Creates a new `GiftPremiumSubscription`.
1562    ///
1563    /// # Arguments
1564    ///
1565    /// * `month_count` - Number of months the Telegram Premium subscription will be active for the user;
1566    ///   must be one of 3, 6, or 12.
1567    /// * `star_count` - Number of Telegram Stars to pay for the Telegram Premium subscription;
1568    ///   must be 1000 for 3 months, 1500 for 6 months, and 2500 for 12 months.
1569    /// * `user_id` - Unique identifier of the target user who will receive a Telegram Premium subscription.
1570    pub fn new(month_count: Integer, star_count: Integer, user_id: Integer) -> Self {
1571        Self {
1572            month_count,
1573            star_count,
1574            user_id,
1575            text: None,
1576            text_entities: None,
1577            text_parse_mode: None,
1578        }
1579    }
1580
1581    /// Sets a new text.
1582    ///
1583    /// # Arguments
1584    ///
1585    /// * `value` - Text that will be shown along with the service message about the subscription; 0-128 characters
1586    pub fn with_text<T>(mut self, value: T) -> Self
1587    where
1588        T: Into<String>,
1589    {
1590        self.text = Some(value.into());
1591        self
1592    }
1593
1594    /// Sets a new list of text entities.
1595    ///
1596    /// # Arguments
1597    ///
1598    /// * `value` - A list of special entities that appear in the gift text.
1599    ///   Entities other than “bold”, “italic”, “underline”,
1600    ///   “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
1601    pub fn with_text_entities<T>(mut self, value: T) -> Self
1602    where
1603        T: IntoIterator<Item = TextEntity>,
1604    {
1605        self.text_parse_mode = None;
1606        self.text_entities = Some(TextEntities::from_iter(value));
1607        self
1608    }
1609
1610    /// Sets a new text parse mode.
1611    ///
1612    /// # Arguments
1613    ///
1614    /// * `value` - Mode for parsing entities in the text.
1615    ///   Entities other than “bold”, “italic”, “underline”,
1616    ///   “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
1617    pub fn with_text_parse_mode(mut self, value: ParseMode) -> Self {
1618        self.text_entities = None;
1619        self.text_parse_mode = Some(value);
1620        self
1621    }
1622}
1623
1624impl Method for GiftPremiumSubscription {
1625    type Response = bool;
1626
1627    fn into_payload(self) -> Payload {
1628        Payload::json("giftPremiumSubscription", self)
1629    }
1630}
1631
1632/// Sends a gift to the given user.
1633///
1634/// The gift can't be converted to Telegram Stars by the user.
1635#[serde_with::skip_serializing_none]
1636#[derive(Clone, Debug, Serialize)]
1637pub struct SendGift {
1638    gift_id: String,
1639    chat_id: Option<ChatId>,
1640    pay_for_upgrade: Option<bool>,
1641    text: Option<String>,
1642    text_parse_mode: Option<ParseMode>,
1643    text_entities: Option<TextEntities>,
1644    user_id: Option<Integer>,
1645}
1646
1647impl SendGift {
1648    /// Creates a new `SendGift` with a `user_id`.
1649    ///
1650    /// # Arguments
1651    ///
1652    /// * `chat_id` - Unique identifier of the target chat that will receive the gift.
1653    /// * `gift_id` - Identifier of the gift
1654    pub fn for_chat_id<A, B>(chat_id: A, gift_id: B) -> Self
1655    where
1656        A: Into<ChatId>,
1657        B: Into<String>,
1658    {
1659        Self {
1660            gift_id: gift_id.into(),
1661            chat_id: Some(chat_id.into()),
1662            pay_for_upgrade: None,
1663            text: None,
1664            text_parse_mode: None,
1665            text_entities: None,
1666            user_id: None,
1667        }
1668    }
1669
1670    /// Creates a new `SendGift` with a `user_id`.
1671    ///
1672    /// # Arguments
1673    ///
1674    /// * `user_id` - Unique identifier of the target user that will receive the gift.
1675    /// * `gift_id` - Identifier of the gift
1676    pub fn for_user_id<T>(user_id: Integer, gift_id: T) -> Self
1677    where
1678        T: Into<String>,
1679    {
1680        Self {
1681            gift_id: gift_id.into(),
1682            chat_id: None,
1683            pay_for_upgrade: None,
1684            text: None,
1685            text_parse_mode: None,
1686            text_entities: None,
1687            user_id: Some(user_id),
1688        }
1689    }
1690
1691    /// Sets a new value for the `pay_for_upgrade` flag.
1692    ///
1693    /// # Arguments
1694    ///
1695    /// * `value` - Whether to pay for the gift upgrade from the bot's balance,
1696    ///   thereby making the upgrade free for the receiver.
1697    pub fn with_pay_for_upgrade(mut self, value: bool) -> Self {
1698        self.pay_for_upgrade = Some(value);
1699        self
1700    }
1701
1702    /// Sets a new text.
1703    ///
1704    /// # Arguments
1705    ///
1706    /// * `value` - Text that will be shown along with the gift; 0-255 characters.
1707    pub fn with_text<T>(mut self, value: T) -> Self
1708    where
1709        T: Into<String>,
1710    {
1711        self.text = Some(value.into());
1712        self
1713    }
1714
1715    /// Sets a new text parse mode.
1716    ///
1717    /// # Arguments
1718    ///
1719    /// * `value` - Mode for parsing entities in the text.
1720    ///
1721    /// Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
1722    /// Text entities will be set to [`None`] when this method is called.
1723    pub fn with_text_parse_mode(mut self, value: ParseMode) -> Self {
1724        self.text_parse_mode = Some(value);
1725        self.text_entities = None;
1726        self
1727    }
1728
1729    /// Sets a new text entities.
1730    ///
1731    /// # Arguments
1732    ///
1733    /// * `value` - A list of special entities that appear in the gift text.
1734    ///
1735    /// Entities other than “bold”, “italic”, “underline”, “strikethrough”, “spoiler”, and “custom_emoji” are ignored.
1736    /// Text parse mode will be set to [`None`] when this method is called.
1737    pub fn with_text_entities<T>(mut self, value: T) -> Self
1738    where
1739        T: IntoIterator<Item = TextEntity>,
1740    {
1741        self.text_entities = Some(value.into_iter().collect());
1742        self.text_parse_mode = None;
1743        self
1744    }
1745}
1746
1747impl Method for SendGift {
1748    type Response = bool;
1749
1750    fn into_payload(self) -> Payload {
1751        Payload::json("sendGift", self)
1752    }
1753}