gegen_data/
types.rs

1use std::collections::HashMap;
2
3use chrono::{DateTime, Utc, serde::ts_seconds};
4use serde::{Deserialize, Serialize};
5
6#[derive(Serialize)]
7pub(crate) struct LiveScoreQueryParams {
8    pub(crate) offset: u8,
9}
10
11#[derive(Debug, Deserialize)]
12#[serde(rename_all = "camelCase")]
13pub struct LiveScoresResponse {
14    pub matches: Vec<Match>,
15}
16
17#[derive(Debug, Deserialize, Clone)]
18#[serde(rename_all = "camelCase")]
19pub struct Match {
20    pub id: String,
21    /// 1: first half
22    /// 2: second half
23    /// 5: penalties
24    /// 10: half time
25    /// 14: full time
26    /// 16: yet to start
27    pub period: usize,
28    pub time: Option<usize>,
29    pub status: Status,
30    pub comp: Competition,
31    #[serde(with = "ts_seconds")]
32    pub date: DateTime<Utc>,
33    pub home: Team,
34    pub away: Team,
35    pub score: Option<HashMap<ScoreKey, Score>>,
36    pub events: Option<Vec<Event>>,
37    #[serde(with = "ts_seconds")]
38    pub updated: DateTime<Utc>,
39}
40
41#[derive(Debug, Deserialize, Clone)]
42#[serde(rename_all = "camelCase", tag = "entity_type")]
43pub enum Event {
44    Sub(SubEvent),
45    Goal(GoalEvent),
46    Card(CardEvent),
47    Var(VAREvent),
48    Pen(PenaltyEvent),
49}
50
51impl Event {
52    pub fn get_team_id(&self) -> &String {
53        match self {
54            Event::Sub(sub_event) => &sub_event.team_id,
55            Event::Goal(goal_event) => &goal_event.team_id,
56            Event::Card(card_event) => &card_event.team_id,
57            Event::Var(varevent) => &varevent.team_id,
58            Event::Pen(penalty_event) => &penalty_event.team_id,
59        }
60    }
61
62    pub fn get_time_str(&self) -> &String {
63        match self {
64            Event::Sub(sub_event) => &sub_event.time_str,
65            Event::Goal(goal_event) => &goal_event.time_str,
66            Event::Card(card_event) => &card_event.time_str,
67            Event::Var(varevent) => &varevent.time_str,
68            Event::Pen(penalty_event) => &penalty_event.time_str,
69        }
70    }
71}
72
73#[derive(Debug, Deserialize, Clone)]
74#[serde(rename_all = "camelCase", tag = "entity_type")]
75pub struct PenaltyEvent {
76    pub period_id: u8,
77    pub min: u16,
78    pub time_str: String,
79    pub team_id: String,
80    pub player_id: String,
81    pub player_name: String,
82    pub outcome: PenaltyOutcome,
83    pub pen_num: usize,
84}
85
86#[derive(Debug, Deserialize, Clone)]
87#[serde(rename_all = "camelCase")]
88pub enum PenaltyOutcome {
89    Saved,
90    Scored,
91    Missed,
92}
93
94#[derive(Debug, Deserialize, Clone)]
95#[serde(rename_all = "camelCase")]
96pub struct VAREvent {
97    pub period_id: u8,
98    pub min: u16,
99    pub time_str: String,
100    pub team_id: String,
101    pub player_id: String,
102    pub player_name: String,
103    #[serde(rename = "type")]
104    pub var_type: String,
105    pub outcome: Option<String>,
106    pub decision: String,
107}
108
109#[derive(Debug, Deserialize, Clone)]
110#[serde(rename_all = "camelCase")]
111pub struct CardEvent {
112    pub period_id: u8,
113    pub min: u16,
114    pub time_str: String,
115    pub player_name: Option<String>,
116    pub reason: Option<String>,
117    pub team_id: String,
118    #[serde(rename = "type")]
119    pub card_type: Card,
120}
121
122#[derive(Debug, Deserialize, Clone)]
123pub enum Card {
124    #[serde(rename = "YC")]
125    Yellow,
126    #[serde(rename = "Y2C")]
127    SecondYellow,
128    #[serde(rename = "RC")]
129    Red,
130}
131
132#[derive(Debug, Deserialize, Clone)]
133#[serde(rename_all = "camelCase")]
134pub struct GoalEvent {
135    pub period_id: u8,
136    pub min: u16,
137    pub time_str: String,
138    pub team_id: String,
139    pub player_id: String,
140    pub player_name: String,
141    pub player_2_name: Option<String>,
142    #[serde(rename = "type")]
143    pub goal_type: GoalType,
144    pub score: Option<[u8; 2]>,
145}
146
147#[derive(Debug, Deserialize, Clone, Copy)]
148pub enum GoalType {
149    #[serde(rename = "G")]
150    Goal,
151    #[serde(rename = "PG")]
152    Penalty,
153    #[serde(rename = "OG")]
154    OwnGoal,
155}
156
157#[derive(Debug, Deserialize, Clone)]
158#[serde(rename_all = "camelCase")]
159pub struct SubEvent {
160    pub period_id: u8,
161    pub min: u16,
162    pub time_str: String,
163    pub team_id: String,
164    pub player_id: String,
165    pub player_name: String,
166    pub player2_id: String,
167    pub player2_name: String,
168}
169
170#[derive(Hash, Eq, PartialEq, PartialOrd, Ord, Debug, Deserialize, Clone, Copy)]
171#[serde(rename_all = "camelCase")]
172pub enum ScoreKey {
173    Ft,
174    Ht,
175    Total,
176    Aggregate,
177    TotalUnconfirmed,
178    Pen,
179    Et,
180}
181
182#[derive(Debug, Deserialize, Clone, Copy, Default)]
183#[serde(rename_all = "camelCase")]
184pub struct Score {
185    pub home: u8,
186    pub away: u8,
187}
188
189#[derive(Debug, Deserialize, Clone)]
190#[serde(rename_all = "camelCase")]
191pub struct Competition {
192    pub id: String,
193    pub name: String,
194    pub country: Country,
195}
196
197#[derive(Debug, Deserialize, Clone)]
198#[serde(rename_all = "camelCase")]
199pub struct Country {
200    pub id: String,
201    pub full_name: String,
202}
203
204// If eithier element is null then the team is TBC
205#[derive(Debug, Deserialize, Clone)]
206#[serde(rename_all = "camelCase")]
207pub struct Team {
208    pub id: Option<String>,
209    pub name: Option<String>,
210}
211
212#[derive(Debug, Deserialize, Clone, Copy)]
213#[serde(rename_all = "camelCase")]
214pub enum Status {
215    Played,
216    Fixture,
217    Playing,
218    Postponed,
219}