1use super::{impl_query_display, impl_paginated_query};
2use itertools::join;
3use std::collections::HashMap;
4
5use crate::schema::{EventLevel, EventType, Grade, MatchRound, SkillType};
6
7#[derive(Default, Debug, Clone, PartialEq)]
9pub struct EventsQuery {
10 query: HashMap<&'static str, String>,
11}
12
13impl_paginated_query!(EventsQuery);
14impl_query_display!(EventsQuery);
15
16impl EventsQuery {
17 pub fn new() -> Self {
18 Self::default()
19 }
20
21 pub fn id(mut self, id: i32) -> Self {
22 self.query.insert("id%5B%5D", id.to_string());
23 self
24 }
25 pub fn ids(mut self, ids: &[i32]) -> Self {
26 self.query.insert("id%5B%5D", join(ids, ","));
27 self
28 }
29
30 pub fn sku(mut self, sku: i32) -> Self {
31 self.query.insert("sku%5B%5D", sku.to_string());
32 self
33 }
34 pub fn skus(mut self, skus: &[i32]) -> Self {
35 self.query.insert("sku%5B%5D", join(skus, ","));
36 self
37 }
38
39 pub fn team(mut self, team: i32) -> Self {
40 self.query.insert("team%5B%5D", team.to_string());
41 self
42 }
43 pub fn teams(mut self, teams: &[i32]) -> Self {
44 self.query.insert("team%5B%5D", join(teams, ","));
45 self
46 }
47
48 pub fn season(mut self, season: i32) -> Self {
49 self.query.insert("season%5B%5D", season.to_string());
50 self
51 }
52 pub fn seasons(mut self, seasons: &[i32]) -> Self {
53 self.query.insert("season%5B%5D", join(seasons, ","));
54 self
55 }
56
57 pub fn start(mut self, start: String) -> Self {
58 self.query.insert("start", start);
59 self
60 }
61 pub fn end(mut self, end: String) -> Self {
62 self.query.insert("end", end);
63 self
64 }
65
66 pub fn region(mut self, region: String) -> Self {
67 self.query.insert("start", region);
68 self
69 }
70
71 pub fn level(mut self, level: EventLevel) -> Self {
72 self.query.insert("level%5B%5D", level.to_string());
73 self
74 }
75 pub fn levels(mut self, levels: &[EventLevel]) -> Self {
76 self.query.insert("season%5B%5D", join(levels, ","));
77 self
78 }
79
80 pub fn my_events(mut self, my_events: bool) -> Self {
81 self.query.insert("my_events", my_events.to_string());
82 self
83 }
84
85 pub fn event_type(mut self, event_type: EventType) -> Self {
86 self.query
87 .insert("event_type%5B%5D", event_type.to_string());
88 self
89 }
90 pub fn event_types(mut self, event_types: &[EventType]) -> Self {
91 self.query.insert("season%5B%5D", join(event_types, ","));
92 self
93 }
94}
95
96#[derive(Default, Debug, Clone, PartialEq)]
98pub struct EventTeamsQuery {
99 query: HashMap<&'static str, String>,
100}
101
102impl_paginated_query!(EventTeamsQuery);
103impl_query_display!(EventTeamsQuery);
104
105impl EventTeamsQuery {
106 pub fn new() -> Self {
107 Self::default()
108 }
109
110 pub fn number(mut self, number: String) -> Self {
111 self.query.insert("number%5B%5D", number.to_string());
112 self
113 }
114 pub fn numbers(mut self, numbers: Vec<String>) -> Self {
115 self.query.insert("number%5B%5D", join(numbers, ","));
116 self
117 }
118
119 pub fn registered(mut self, number: String) -> Self {
120 self.query.insert("registered", number.to_string());
121 self
122 }
123
124 pub fn grade(mut self, grade: Grade) -> Self {
125 self.query.insert("grade%5B%5D", grade.to_string());
126 self
127 }
128 pub fn grades(mut self, grades: &[Grade]) -> Self {
129 self.query.insert("grade%5B%5D", join(grades, ","));
130 self
131 }
132
133 pub fn country(mut self, country: i32) -> Self {
134 self.query.insert("country%5B%5D", country.to_string());
135 self
136 }
137 pub fn countries(mut self, countrys: &[i32]) -> Self {
138 self.query.insert("country%5B%5D", join(countrys, ","));
139 self
140 }
141
142 pub fn my_teams(mut self, my_teams: bool) -> Self {
143 self.query.insert("myTeams", my_teams.to_string());
144 self
145 }
146}
147
148#[derive(Default, Debug, Clone, PartialEq)]
150pub struct EventSkillsQuery {
151 query: HashMap<&'static str, String>,
152}
153
154impl_paginated_query!(EventSkillsQuery);
155impl_query_display!(EventSkillsQuery);
156
157impl EventSkillsQuery {
158 pub fn new() -> Self {
159 Self::default()
160 }
161
162 pub fn team(mut self, team: i32) -> Self {
163 self.query.insert("team%5B%5D", team.to_string());
164 self
165 }
166 pub fn teams(mut self, teams: &[i32]) -> Self {
167 self.query.insert("team%5B%5D", join(teams, ","));
168 self
169 }
170
171 pub fn skill_type(mut self, skill_type: SkillType) -> Self {
172 self.query.insert("type%5B%5D", skill_type.to_string());
173 self
174 }
175 pub fn skill_types(mut self, skill_types: &[SkillType]) -> Self {
176 self.query.insert("type%5B%5D", join(skill_types, ","));
177 self
178 }
179}
180
181#[derive(Default, Debug, Clone, PartialEq)]
183pub struct EventAwardsQuery {
184 query: HashMap<&'static str, String>,
185}
186
187impl_paginated_query!(EventAwardsQuery);
188impl_query_display!(EventAwardsQuery);
189
190impl EventAwardsQuery {
191 pub fn new() -> Self {
192 Self::default()
193 }
194
195 pub fn team(mut self, team: i32) -> Self {
196 self.query.insert("team%5B%5D", team.to_string());
197 self
198 }
199 pub fn teams(mut self, teams: &[i32]) -> Self {
200 self.query.insert("team%5B%5D", join(teams, ","));
201 self
202 }
203
204 pub fn winner(mut self, winner: String) -> Self {
205 self.query.insert("winner%5B%5D", winner.to_string());
206 self
207 }
208 pub fn winners(mut self, winners: Vec<String>) -> Self {
209 self.query.insert("winner%5B%5D", join(winners, ","));
210 self
211 }
212}
213
214#[derive(Default, Debug, Clone, PartialEq)]
216pub struct DivisionMatchesQuery {
217 query: HashMap<&'static str, String>,
218}
219
220impl_paginated_query!(DivisionMatchesQuery);
221impl_query_display!(DivisionMatchesQuery);
222
223impl DivisionMatchesQuery {
224 pub fn new() -> Self {
225 Self::default()
226 }
227
228 pub fn team(mut self, team: i32) -> Self {
229 self.query.insert("team%5B%5D", team.to_string());
230 self
231 }
232 pub fn teams(mut self, teams: &[i32]) -> Self {
233 self.query.insert("team%5B%5D", join(teams, ","));
234 self
235 }
236
237 pub fn round(mut self, round: MatchRound) -> Self {
238 self.query.insert("round%5B%5D", (round as i32).to_string());
239 self
240 }
241 pub fn rounds(mut self, rounds: &[MatchRound]) -> Self {
242 self.query.insert(
243 "round%5B%5D",
244 join(rounds.iter().map(|round| round.clone() as i32), ","),
245 );
246 self
247 }
248
249 pub fn instance(mut self, instance: i32) -> Self {
250 self.query.insert("instance%5B%5D", instance.to_string());
251 self
252 }
253 pub fn instances(mut self, instances: &[i32]) -> Self {
254 self.query.insert("instance%5B%5D", join(instances, ","));
255 self
256 }
257
258 pub fn matchnum(mut self, matchnum: i32) -> Self {
259 self.query.insert("matchnum%5B%5D", matchnum.to_string());
260 self
261 }
262 pub fn matchnums(mut self, matchnums: &[i32]) -> Self {
263 self.query.insert("matchnum%5B%5D", join(matchnums, ","));
264 self
265 }
266}
267
268
269#[derive(Default, Debug, Clone, PartialEq)]
271pub struct DivisionRankingsQuery {
272 query: HashMap<&'static str, String>,
273}
274
275impl_paginated_query!(DivisionRankingsQuery);
276impl_query_display!(DivisionRankingsQuery);
277
278impl DivisionRankingsQuery {
279 pub fn new() -> Self {
280 Self::default()
281 }
282
283 pub fn team(mut self, team: i32) -> Self {
284 self.query.insert("team%5B%5D", team.to_string());
285 self
286 }
287 pub fn teams(mut self, teams: &[i32]) -> Self {
288 self.query.insert("team%5B%5D", join(teams, ","));
289 self
290 }
291
292 pub fn rank(mut self, rank: i32) -> Self {
293 self.query.insert("rank%5B%5D", rank.to_string());
294 self
295 }
296 pub fn ranks(mut self, ranks: &[i32]) -> Self {
297 self.query.insert("rank%5B%5D", join(ranks, ","));
298 self
299 }
300}