1use chrono::{DateTime, Utc};
4use serde::{Deserialize, Serialize};
5
6#[derive(Debug, Clone, Serialize, Deserialize)]
8pub struct Sport {
9 pub key: String,
11 pub group: String,
13 pub title: String,
15 pub description: String,
17 pub active: bool,
19 pub has_outrights: bool,
21}
22
23#[derive(Debug, Clone, Serialize, Deserialize)]
25pub struct Event {
26 pub id: String,
28 pub sport_key: String,
30 pub sport_title: String,
32 pub commence_time: DateTime<Utc>,
34 pub home_team: Option<String>,
36 pub away_team: Option<String>,
38}
39
40#[derive(Debug, Clone, Serialize, Deserialize)]
42pub struct EventOdds {
43 pub id: String,
45 pub sport_key: String,
47 pub sport_title: String,
49 pub commence_time: DateTime<Utc>,
51 pub home_team: Option<String>,
53 pub away_team: Option<String>,
55 pub bookmakers: Vec<Bookmaker>,
57}
58
59#[derive(Debug, Clone, Serialize, Deserialize)]
61pub struct EventScore {
62 pub id: String,
64 pub sport_key: String,
66 pub sport_title: String,
68 pub commence_time: DateTime<Utc>,
70 pub home_team: Option<String>,
72 pub away_team: Option<String>,
74 pub completed: bool,
76 pub scores: Option<Vec<Score>>,
78 pub last_update: Option<DateTime<Utc>>,
80}
81
82#[derive(Debug, Clone, Serialize, Deserialize)]
84pub struct Score {
85 pub name: String,
87 pub score: String,
89}
90
91#[derive(Debug, Clone, Serialize, Deserialize)]
93pub struct Bookmaker {
94 pub key: String,
96 pub title: String,
98 #[serde(skip_serializing_if = "Option::is_none")]
100 pub last_update: Option<DateTime<Utc>>,
101 pub markets: Vec<MarketOdds>,
103 #[serde(skip_serializing_if = "Option::is_none")]
105 pub link: Option<String>,
106 #[serde(skip_serializing_if = "Option::is_none")]
108 pub sid: Option<String>,
109}
110
111#[derive(Debug, Clone, Serialize, Deserialize)]
113pub struct MarketOdds {
114 pub key: String,
116 pub last_update: Option<DateTime<Utc>>,
118 pub outcomes: Vec<Outcome>,
120}
121
122#[derive(Debug, Clone, Serialize, Deserialize)]
124pub struct Outcome {
125 pub name: String,
127 pub price: f64,
129 #[serde(skip_serializing_if = "Option::is_none")]
131 pub point: Option<f64>,
132 #[serde(skip_serializing_if = "Option::is_none")]
134 pub description: Option<String>,
135 #[serde(skip_serializing_if = "Option::is_none")]
137 pub link: Option<String>,
138 #[serde(skip_serializing_if = "Option::is_none")]
140 pub multiplier: Option<f64>,
141}
142
143#[derive(Debug, Clone, Serialize, Deserialize)]
145pub struct Participant {
146 pub id: String,
148 pub full_name: String,
150}
151
152#[derive(Debug, Clone, Serialize, Deserialize)]
154pub struct MarketInfo {
155 pub key: String,
157 pub last_update: Option<DateTime<Utc>>,
159}
160
161#[derive(Debug, Clone, Serialize, Deserialize)]
163pub struct BookmakerMarkets {
164 pub key: String,
166 pub title: String,
168 pub markets: Vec<MarketInfo>,
170}
171
172#[derive(Debug, Clone, Serialize, Deserialize)]
174pub struct EventMarkets {
175 pub id: String,
177 pub sport_key: String,
179 pub sport_title: String,
181 pub commence_time: DateTime<Utc>,
183 pub home_team: Option<String>,
185 pub away_team: Option<String>,
187 pub bookmakers: Vec<BookmakerMarkets>,
189}
190
191#[derive(Debug, Clone, Serialize, Deserialize)]
193pub struct HistoricalResponse<T> {
194 pub timestamp: DateTime<Utc>,
196 pub previous_timestamp: Option<DateTime<Utc>>,
198 pub next_timestamp: Option<DateTime<Utc>>,
200 pub data: T,
202}
203
204#[derive(Debug, Clone, Default)]
206pub struct UsageInfo {
207 pub requests_remaining: Option<u32>,
209 pub requests_used: Option<u32>,
211 pub requests_last: Option<u32>,
213}
214
215impl UsageInfo {
216 pub(crate) fn from_headers(headers: &reqwest::header::HeaderMap) -> Self {
218 Self {
219 requests_remaining: headers
220 .get("x-requests-remaining")
221 .and_then(|v| v.to_str().ok())
222 .and_then(|v| v.parse().ok()),
223 requests_used: headers
224 .get("x-requests-used")
225 .and_then(|v| v.to_str().ok())
226 .and_then(|v| v.parse().ok()),
227 requests_last: headers
228 .get("x-requests-last")
229 .and_then(|v| v.to_str().ok())
230 .and_then(|v| v.parse().ok()),
231 }
232 }
233}
234
235#[derive(Debug, Clone)]
237pub struct Response<T> {
238 pub data: T,
240 pub usage: UsageInfo,
242}
243
244impl<T> Response<T> {
245 pub fn new(data: T, usage: UsageInfo) -> Self {
247 Self { data, usage }
248 }
249
250 pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Response<U> {
252 Response {
253 data: f(self.data),
254 usage: self.usage,
255 }
256 }
257}