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
use chrono::{
DateTime,
TimeZone,
Utc
};
use serde::{
Deserialize,
Serialize,
};
use crate::{
enums::*,
page_info::*,
phase::*,
set::*,
};
/// Equivalent for start.gg PhaseGroupConnection.
#[derive(Clone, Serialize, Deserialize)]
pub struct GGPhaseGroupConnection {
pub nodes: Vec<GGPhaseGroup>,
pub page_info: Option<Box<GGPageInfo>>,
}
impl GGPhaseGroupConnection {
/// 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 PhaseGroup.
///
/// 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 seeds()) 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 GGPhaseGroup {
#[serde(rename(serialize = "bracketType", deserialize = "bracketType"))]
pub bracket_type: Option<i64>,
#[serde(rename(serialize = "bracketUrl", deserialize = "bracketUrl"))]
pub bracket_url: Option<String>,
#[serde(rename(serialize = "displayIdentifier", deserialize = "displayIdentifier"))]
pub display_identifier: Option<String>,
#[serde(rename(serialize = "firstRoundTime", deserialize = "firstRoundTime"))]
pub first_round_time: Option<i64>,
pub id: Option<GGID>,
#[serde(rename(serialize = "numRounds", deserialize = "numRounds"))]
pub num_rounds: Option<i64>,
pub phase: Option<Box<GGPhase>>,
// pub progressions_out: Option<GGProgression>,
// pub rounds: Option<GGRound>,
// pub seed_map: JSON,
// pub seeds: Option<GGSeeds>,
pub sets: Option<GGSetConnection>,
// pub standings: Option<GGStandings>,
#[serde(rename(serialize = "startAt", deserialize = "startAt"))]
pub start_at: Option<i64>,
pub state: Option<i64>,
// pub tiebreaker_order: JSON,
// pub wave: Option<Box<GGWave>>,
}
impl GGPhaseGroup {
/// Returns the bracket type of the phase group.
///
/// Returns zero if not set or wasn't queried.
pub fn bracket_type(&self) -> i64 {
let mut result: i64 = 0;
if self.bracket_type.is_some() {
result = self.bracket_type.unwrap().clone();
}
return result;
}
/// Returns the bracket url of the phase group.
///
/// Returns an empty string if not set or wasn't queried.
pub fn bracket_url(&self) -> String {
let mut result: String = "".to_string();
if self.bracket_url.is_some() {
result = self.bracket_url.clone().unwrap().clone();
}
return result;
}
/// Returns the display indentifier of the phase group.
///
/// Returns an empty string if not set or wasn't queried.
pub fn display_identifier(&self) -> String {
let mut result: String = "".to_string();
if self.display_identifier.is_some() {
result = self.display_identifier.clone().unwrap().clone();
}
return result;
}
/// Returns the time the first round starts.
///
/// Returns zero if not set or wasn't queried.
pub fn first_round_time(&self) -> DateTime<Utc> {
let mut result: i64 = 0;
if self.first_round_time.is_some() {
result = self.first_round_time.unwrap().clone();
}
return Utc.timestamp_opt(result, 0).unwrap();
}
/// Returns the id of the phase group.
///
/// 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 the number of round in the phase group.
///
/// Returns zero if not set or wasn't queried.
pub fn num_rounds(&self) -> i64 {
let mut result: i64 = 0;
if self.num_rounds.is_some() {
result = self.num_rounds.unwrap().clone();
}
return result;
}
/// Returns the phase the phase group is in.
///
/// Returns an empty tournament if not set or wasn't queried.
pub fn phase(&self) -> GGPhase {
let mut result: GGPhase = Default::default();
if self.phase.is_some() {
result = *self.phase.as_ref().unwrap().clone();
}
return result;
}
/// Returns the sets in the phase group.
///
/// Returns an empty vector if not set or wasn't queried.
pub fn sets(&self) -> Vec<GGSet> {
let mut result: Vec<GGSet> = Vec::new();
if self.sets.is_some() {
for set in &self.sets.as_ref().unwrap().nodes {
result.push(set.clone());
}
}
return result;
}
/// Returns the time the phase group starts.
///
/// 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 phase group.
///
/// 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;
}
}