1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
use serde::{Deserialize, Serialize};
/// This object represents a message about the completion of a giveaway with public winners.
/// Currently, it can be one of
/// - [`crate::types::GiveawayWinnersPremium`]
/// - [`crate::types::GiveawayWinnersStar`]
/// # Documentation
/// <https://core.telegram.org/bots/api#giveawaywinners>
#[derive(Clone, Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum GiveawayWinners {
Premium(crate::types::GiveawayWinnersPremium),
Star(crate::types::GiveawayWinnersStar),
}
impl GiveawayWinners {
/// Helper method for field `additional_chat_count`.
///
/// The number of other chats the user had to join in order to be eligible for the giveaway
#[must_use]
pub fn additional_chat_count(&self) -> Option<i64> {
match self {
Self::Premium(val) => val.additional_chat_count,
Self::Star(val) => val.additional_chat_count,
}
}
/// Helper method for field `chat`.
///
/// The chat that created the giveaway
#[must_use]
pub fn chat(&self) -> &crate::types::Chat {
match self {
Self::Premium(val) => val.chat.as_ref(),
Self::Star(val) => val.chat.as_ref(),
}
}
/// Helper method for field `giveaway_message_id`.
///
/// Identifier of the message with the giveaway in the chat
#[must_use]
pub fn giveaway_message_id(&self) -> i64 {
match self {
Self::Premium(val) => val.giveaway_message_id,
Self::Star(val) => val.giveaway_message_id,
}
}
/// Helper method for field `only_new_members`.
///
/// `true`, if only users who had joined the chats after the giveaway started were eligible to win
#[must_use]
pub fn only_new_members(&self) -> Option<bool> {
match self {
Self::Premium(val) => val.only_new_members,
Self::Star(val) => val.only_new_members,
}
}
/// Helper method for field `premium_subscription_month_count`.
///
/// The number of months the Telegram Premium subscription won from the giveaway will be active for; for Telegram Premium giveaways only
#[must_use]
pub fn premium_subscription_month_count(&self) -> Option<i64> {
match self {
Self::Premium(val) => Some(val.premium_subscription_month_count),
Self::Star(_) => None,
}
}
/// Helper method for field `prize_description`.
///
/// Description of additional giveaway prize
#[must_use]
pub fn prize_description(&self) -> Option<&str> {
match self {
Self::Premium(val) => val.prize_description.as_deref(),
Self::Star(val) => val.prize_description.as_deref(),
}
}
/// Helper method for field `prize_star_count`.
///
/// The number of Telegram Stars that were split between giveaway winners; for Telegram Star giveaways only
#[must_use]
pub fn prize_star_count(&self) -> Option<i64> {
match self {
Self::Star(val) => Some(val.prize_star_count),
Self::Premium(_) => None,
}
}
/// Helper method for field `unclaimed_prize_count`.
///
/// Number of undistributed prizes
#[must_use]
pub fn unclaimed_prize_count(&self) -> Option<i64> {
match self {
Self::Premium(val) => val.unclaimed_prize_count,
Self::Star(val) => val.unclaimed_prize_count,
}
}
/// Helper method for field `was_refunded`.
///
/// `true`, if the giveaway was canceled because the payment for it was refunded
#[must_use]
pub fn was_refunded(&self) -> Option<bool> {
match self {
Self::Premium(val) => val.was_refunded,
Self::Star(val) => val.was_refunded,
}
}
/// Helper method for field `winner_count`.
///
/// Total number of winners in the giveaway
#[must_use]
pub fn winner_count(&self) -> i64 {
match self {
Self::Premium(val) => val.winner_count,
Self::Star(val) => val.winner_count,
}
}
/// Helper method for field `winners`.
///
/// List of up to 100 winners of the giveaway
#[must_use]
pub fn winners(&self) -> &[crate::types::User] {
match self {
Self::Premium(val) => val.winners.as_ref(),
Self::Star(val) => val.winners.as_ref(),
}
}
/// Helper method for field `winners_selection_date`.
///
/// Point in time (Unix timestamp) when winners of the giveaway were selected
#[must_use]
pub fn winners_selection_date(&self) -> i64 {
match self {
Self::Premium(val) => val.winners_selection_date,
Self::Star(val) => val.winners_selection_date,
}
}
/// Helper method for nested field `first_name`.
#[must_use]
pub fn first_name(&self) -> Option<&str> {
crate::types::Chat::first_name(self.chat())
}
/// Helper method for nested field `id`.
#[must_use]
pub fn id(&self) -> i64 {
crate::types::Chat::id(self.chat())
}
/// Helper method for nested field `is_direct_messages`.
#[must_use]
pub fn is_direct_messages(&self) -> Option<bool> {
crate::types::Chat::is_direct_messages(self.chat())
}
/// Helper method for nested field `is_forum`.
#[must_use]
pub fn is_forum(&self) -> Option<bool> {
crate::types::Chat::is_forum(self.chat())
}
/// Helper method for nested field `last_name`.
#[must_use]
pub fn last_name(&self) -> Option<&str> {
crate::types::Chat::last_name(self.chat())
}
/// Helper method for nested field `title`.
#[must_use]
pub fn title(&self) -> Option<&str> {
crate::types::Chat::title(self.chat())
}
/// Helper method for nested field `username`.
#[must_use]
pub fn username(&self) -> Option<&str> {
crate::types::Chat::username(self.chat())
}
}
impl From<crate::types::GiveawayWinnersPremium> for GiveawayWinners {
fn from(val: crate::types::GiveawayWinnersPremium) -> Self {
Self::Premium(val)
}
}
impl TryFrom<GiveawayWinners> for crate::types::GiveawayWinnersPremium {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: GiveawayWinners) -> Result<Self, Self::Error> {
match val {
GiveawayWinners::Premium(inner) => Ok(inner),
GiveawayWinners::Star(_) => Err(Self::Error::new(
stringify!(GiveawayWinners),
stringify!(GiveawayWinnersPremium),
)),
}
}
}
impl From<crate::types::GiveawayWinnersStar> for GiveawayWinners {
fn from(val: crate::types::GiveawayWinnersStar) -> Self {
Self::Star(val)
}
}
impl TryFrom<GiveawayWinners> for crate::types::GiveawayWinnersStar {
type Error = crate::errors::ConvertToTypeError;
fn try_from(val: GiveawayWinners) -> Result<Self, Self::Error> {
match val {
GiveawayWinners::Star(inner) => Ok(inner),
GiveawayWinners::Premium(_) => Err(Self::Error::new(
stringify!(GiveawayWinners),
stringify!(GiveawayWinnersStar),
)),
}
}
}