1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
use chrono::{
DateTime,
TimeZone,
Utc
};
use serde::{
Deserialize,
Serialize,
};
use crate::{
entrant::*,
enums::*,
page_info::*,
phase::*,
phase_group::*,
standing::*,
tournament::*,
};
/// Equivalent for start.gg EventConnection.
#[derive(Clone, Default, Serialize, Deserialize)]
pub struct GGEventConnection {
pub nodes: Vec<GGEvent>,
pub page_info: Option<Box<GGPageInfo>>,
}
impl GGEventConnection {
/// Returns the page info of the connection.
///
/// Returns empty page info if not set or wasn't queried.
pub fn page_info(&self) -> GGPageInfo {
let mut result: GGPageInfo = Default::default();
if self.page_info.is_some() {
result = *self.page_info.as_ref().unwrap().clone();
}
return result;
}
}
/// Equivalent for start.gg Event.
///
/// Each element in the structure is optional, allowing a user to only query values they want.
/// Given each is an option and not a requirement, a method is included for each element with the same name.
/// These methods will unwrap and return the proper value without any unwrapping or references needed.
/// Certain methods (see entrants()) will return a vector of the data type instead of a connection to a vector, done to simplify the API and make the start.gg api easier to work with.
#[derive(Clone, Default, Serialize, Deserialize)]
pub struct GGEvent {
#[serde(rename(serialize = "checkInBuffer", deserialize = "checkInBuffer"))]
pub check_in_buffer: Option<i64>,
#[serde(rename(serialize = "checkInDuration", deserialize = "checkInDuration"))]
pub check_in_duration: Option<i64>,
#[serde(rename(serialize = "checkInEnabled", deserialize = "checkInEnabled"))]
pub check_in_enabled: Option<bool>,
#[serde(rename(serialize = "competitionTier", deserialize = "competitionTier"))]
pub competition_tier: Option<i64>,
#[serde(rename(serialize = "createdAt", deserialize = "createdAt"))]
pub created_at: Option<i64>,
#[serde(rename(serialize = "deckSubmissionDeadline", deserialize = "deckSubmissionDeadline"))]
pub deck_submission_deadline: Option<i64>,
pub entrants: Option<GGEntrantConnection>,
#[serde(rename(serialize = "hasDecks", deserialize = "hasDecks"))]
pub has_decks: Option<bool>,
#[serde(rename(serialize = "hasTasks", deserialize = "hasTasks"))]
pub has_tasks: Option<bool>,
pub id: Option<GGID>,
// pub images: Option<Vec<GGImage>>,
#[serde(rename(serialize = "isOnline", deserialize = "isOnline"))]
pub is_online: Option<bool>,
// pub league: Option<GGLeague>,
#[serde(rename(serialize = "matchRulesMarkdown", deserialize = "matchRulesMarkdown"))]
pub match_rules_markdown: Option<String>,
pub name: Option<String>,
#[serde(rename(serialize = "numEntrants", deserialize = "numEntrants"))]
pub num_entrants: Option<i64>,
#[serde(rename(serialize = "phaseGroups", deserialize = "phaseGroups"))]
pub phase_groups: Option<Vec<GGPhaseGroup>>,
pub phases: Option<Vec<GGPhase>>,
// #[serde(rename(serialize = "prizingInfo", deserialize = "prizingInfo"))]
// pub prizing_info: JSON,
// pub publishing: JSON,
#[serde(rename(serialize = "rulesMarkdown", deserialize = "rulesMarkdown"))]
pub rules_markdown: Option<String>,
#[serde(rename(serialize = "rulesetId", deserialize = "rulesetId"))]
pub ruleset_id: Option<i64>,
// pub sets: Option<GGSets>,
pub slug: Option<String>,
pub standings: Option<GGStandingConnection>,
#[serde(rename(serialize = "startAt", deserialize = "startAt"))]
pub start_at: Option<i64>,
pub state: Option<i64>,
// pub stations: Option<GGStations>,
#[serde(rename(serialize = "teamManagementDeadline", deserialize = "teamManagementDeadline"))]
pub team_management_deadline: Option<i64>,
#[serde(rename(serialize = "teamNameAllowed", deserialize = "teamNameAllowed"))]
pub team_name_allowed: Option<bool>,
// #[serde(rename(serialize = "teamRosterSize", deserialize = "teamRosterSize"))]
// pub team_roster_size: Option<GGTeamRosterSize>,
pub tournament: Option<Box<GGTournament>>,
pub r#type: Option<i64>,
#[serde(rename(serialize = "updatedAt", deserialize = "updatedAt"))]
pub updated_at: Option<i64>,
#[serde(rename(serialize = "useEventSeeds", deserialize = "useEventSeeds"))]
pub use_event_seeds: Option<bool>,
#[serde(rename(serialize = "userEntrant", deserialize = "userEntrant"))]
pub user_entrant: Option<Box<GGEntrant>>,
// pub videogame: Option<GGVideogame>,
// pub waves: Option<Vec<GGWave>>,
}
impl GGEvent {
/// Returns the check in buffer of the event.
///
/// Returns zero if not set or wasn't queried.
pub fn check_in_buffer(&self) -> i64 {
let mut result: i64 = 0;
if self.check_in_buffer.is_some() {
result = self.check_in_buffer.unwrap().clone();
}
return result;
}
/// Returns the check in duration of the event.
///
/// Returns zero if not set or wasn't queried.
pub fn check_in_duration(&self) -> i64 {
let mut result: i64 = 0;
if self.check_in_duration.is_some() {
result = self.check_in_duration.unwrap().clone();
}
return result;
}
/// Returns if the event has check in enabled.
///
/// Returns false if not set or wasn't queried.
pub fn check_in_enabled(&self) -> bool {
let mut result: bool = false;
if self.check_in_enabled.is_some() {
result = self.check_in_enabled.unwrap().clone();
}
return result;
}
/// Returns the competition tier of the event.
///
/// Returns zero if not set or wasn't queried.
pub fn competition_tier(&self) -> i64 {
let mut result: i64 = 0;
if self.competition_tier.is_some() {
result = self.competition_tier.unwrap().clone();
}
return result;
}
/// Returns the time the event was created.
///
/// Returns zero if not set or wasn't queried.
pub fn created_at(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.created_at.is_some() {
result = self.created_at.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the deck submission deadline of the event.
///
/// Returns zero if not set or wasn't queried.
pub fn deck_submission_deadline(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.deck_submission_deadline.is_some() {
result = self.deck_submission_deadline.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the entrants in the event.
///
/// Returns an empty vector if not set or wasn't queried.
pub fn entrants(&self) -> Vec<GGEntrant> {
let mut result: Vec<GGEntrant> = Vec::new();
if self.entrants.is_some() {
for entrant in &self.entrants.as_ref().unwrap().nodes {
result.push(entrant.clone());
}
}
return result;
}
/// Returns if the event has decks.
///
/// Returns false if not set or wasn't queried.
pub fn has_decks(&self) -> bool {
let mut result: bool = false;
if self.has_decks.is_some() {
result = self.has_decks.unwrap().clone();
}
return result;
}
/// Returns if the event has tasks.
///
/// Returns false if not set or wasn't queried.
pub fn has_tasks(&self) -> bool {
let mut result: bool = false;
if self.has_tasks.is_some() {
result = self.has_tasks.unwrap().clone();
}
return result;
}
/// Returns the id of the event.
///
/// Returns zero if not set or wasn't queried.
pub fn id(&self) -> GGID {
let mut result: GGID = GGID::Int(0);
if self.id.is_some() {
match self.id.clone().unwrap() {
GGID::Int(_) => result = self.id.as_ref().unwrap().clone(),
GGID::String(_) => result = self.id.as_ref().unwrap().clone(),
};
}
return result;
}
/// Returns if the event is online.
///
/// Returns false if not set or wasn't queried.
pub fn is_online(&self) -> bool {
let mut result: bool = false;
if self.is_online.is_some() {
result = self.is_online.unwrap().clone();
}
return result;
}
/// Returns the match rules of the event.
///
/// Returns an empty string if not set or wasn't queried.
pub fn match_rules_markdown(&self) -> String {
let mut result: String = "".to_string();
if self.match_rules_markdown.is_some() {
result = self.match_rules_markdown.clone().unwrap().clone();
}
return result;
}
/// Returns the name of the event.
///
/// Returns an empty string if not set or wasn't queried.
pub fn name(&self) -> String {
let mut result: String = "".to_string();
if self.name.is_some() {
result = self.name.clone().unwrap().clone();
}
return result;
}
/// Returns the number of entrants in the event.
///
/// Returns zero if not set or wasn't queried.
pub fn num_entrants(&self) -> i64 {
let mut result: i64 = 0;
if self.num_entrants.is_some() {
result = self.num_entrants.unwrap().clone();
}
return result;
}
/// Returns the phase groups in the event.
///
/// Returns an empty vector if not set or wasn't queried.
pub fn phase_groups(&self) -> Vec<GGPhaseGroup> {
let mut result: Vec<GGPhaseGroup> = Vec::new();
if self.phase_groups.is_some() {
for phase_group in self.phase_groups.as_ref().unwrap() {
result.push(phase_group.clone());
}
}
return result;
}
/// Returns the phases in the event.
///
/// Returns an empty vector if not set or wasn't queried.
pub fn phases(&self) -> Vec<GGPhase> {
let mut result: Vec<GGPhase> = Vec::new();
if self.phases.is_some() {
for phase in self.phases.as_ref().unwrap() {
result.push(phase.clone());
}
}
return result;
}
/// Returns the rules of the event.
///
/// Returns an empty string if not set or wasn't queried.
pub fn rules_markdown(&self) -> String {
let mut result: String = "".to_string();
if self.rules_markdown.is_some() {
result = self.rules_markdown.clone().unwrap().clone();
}
return result;
}
/// Returns the ruleset id of the event.
///
/// Returns zero if not set or wasn't queried.
pub fn ruleset_id(&self) -> i64 {
let mut result: i64 = 0;
if self.ruleset_id.is_some() {
result = self.ruleset_id.unwrap().clone();
}
return result;
}
/// Returns the slug of the event.
///
/// Returns an empty string if not set or wasn't queried.
pub fn slug(&self) -> String {
let mut result: String = "".to_string();
if self.slug.is_some() {
result = self.slug.clone().unwrap().clone();
}
return result;
}
/// Returns the standings of the event.
///
/// Returns an empty vector if not set or wasn't queried.
pub fn standings(&self) -> Vec<GGStanding> {
let mut result: Vec<GGStanding> = Vec::new();
if self.standings.is_some() {
for standing in &self.standings.as_ref().unwrap().nodes {
result.push(standing.clone());
}
}
return result;
}
/// Returns the start time of the event.
///
/// Returns zero if not set or wasn't queried.
pub fn start_at(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.start_at.is_some() {
result = self.start_at.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the state of the event.
///
/// Returns zero if not set or wasn't queried.
pub fn state(&self) -> i64 {
let mut result: i64 = 0;
if self.state.is_some() {
result = self.state.unwrap().clone();
}
return result;
}
/// Returns the team management deadline of the event.
///
/// Returns zero if not set or wasn't queried.
pub fn team_management_deadline(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.team_management_deadline.is_some() {
result = self.team_management_deadline.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns if the event allows team names.
///
/// Returns false if not set or wasn't queried.
pub fn team_name_allowed(&self) -> bool {
let mut result: bool = false;
if self.team_name_allowed.is_some() {
result = self.team_name_allowed.unwrap().clone();
}
return result;
}
/// Returns the tournament the event is in.
///
/// Returns an empty tournament if not set or wasn't queried.
pub fn tournament(&self) -> GGTournament {
let mut result: GGTournament = Default::default();
if self.tournament.is_some() {
result = *self.tournament.as_ref().unwrap().clone();
}
return result;
}
/// Returns the type of the event.
///
/// Returns zero if not set or wasn't queried.
pub fn r#type(&self) -> i64 {
let mut result: i64 = 0;
if self.r#type.is_some() {
result = self.r#type.unwrap().clone();
}
return result;
}
/// Returns the time the event was last updated.
///
/// Returns zero if not set or wasn't queried.
pub fn updated_at(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.updated_at.is_some() {
result = self.updated_at.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns if the event uses event seeds.
///
/// Returns false if not set or wasn't queried.
pub fn use_event_seeds(&self) -> bool {
let mut result: bool = false;
if self.use_event_seeds.is_some() {
result = self.use_event_seeds.unwrap().clone();
}
return result;
}
/// Returns an entrant for a specific user in the event.
///
/// Returns an empty entrant if not set or wasn't queried.
pub fn user_entrant(&self) -> GGEntrant {
let mut result: GGEntrant = Default::default();
if self.user_entrant.is_some() {
result = *self.user_entrant.as_ref().unwrap().clone();
}
return result;
}
}