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 pub last_update: DateTime<Utc>,
100 pub markets: Vec<MarketOdds>,
102 #[serde(skip_serializing_if = "Option::is_none")]
104 pub link: Option<String>,
105 #[serde(skip_serializing_if = "Option::is_none")]
107 pub sid: Option<String>,
108}
109
110#[derive(Debug, Clone, Serialize, Deserialize)]
112pub struct MarketOdds {
113 pub key: String,
115 pub last_update: Option<DateTime<Utc>>,
117 pub outcomes: Vec<Outcome>,
119}
120
121#[derive(Debug, Clone, Serialize, Deserialize)]
123pub struct Outcome {
124 pub name: String,
126 pub price: f64,
128 #[serde(skip_serializing_if = "Option::is_none")]
130 pub point: Option<f64>,
131 #[serde(skip_serializing_if = "Option::is_none")]
133 pub description: Option<String>,
134 #[serde(skip_serializing_if = "Option::is_none")]
136 pub link: Option<String>,
137 #[serde(skip_serializing_if = "Option::is_none")]
139 pub multiplier: Option<f64>,
140}
141
142#[derive(Debug, Clone, Serialize, Deserialize)]
144pub struct Participant {
145 pub id: String,
147 pub full_name: String,
149}
150
151#[derive(Debug, Clone, Serialize, Deserialize)]
153pub struct BookmakerMarkets {
154 pub key: String,
156 pub title: String,
158 pub markets: Vec<String>,
160}
161
162#[derive(Debug, Clone, Serialize, Deserialize)]
164pub struct EventMarkets {
165 pub id: String,
167 pub sport_key: String,
169 pub sport_title: String,
171 pub commence_time: DateTime<Utc>,
173 pub home_team: Option<String>,
175 pub away_team: Option<String>,
177 pub bookmakers: Vec<BookmakerMarkets>,
179}
180
181#[derive(Debug, Clone, Serialize, Deserialize)]
183pub struct HistoricalResponse<T> {
184 pub timestamp: DateTime<Utc>,
186 pub previous_timestamp: Option<DateTime<Utc>>,
188 pub next_timestamp: Option<DateTime<Utc>>,
190 pub data: T,
192}
193
194#[derive(Debug, Clone, Default)]
196pub struct UsageInfo {
197 pub requests_remaining: Option<u32>,
199 pub requests_used: Option<u32>,
201 pub requests_last: Option<u32>,
203}
204
205impl UsageInfo {
206 pub(crate) fn from_headers(headers: &reqwest::header::HeaderMap) -> Self {
208 Self {
209 requests_remaining: headers
210 .get("x-requests-remaining")
211 .and_then(|v| v.to_str().ok())
212 .and_then(|v| v.parse().ok()),
213 requests_used: headers
214 .get("x-requests-used")
215 .and_then(|v| v.to_str().ok())
216 .and_then(|v| v.parse().ok()),
217 requests_last: headers
218 .get("x-requests-last")
219 .and_then(|v| v.to_str().ok())
220 .and_then(|v| v.parse().ok()),
221 }
222 }
223}
224
225#[derive(Debug, Clone)]
227pub struct Response<T> {
228 pub data: T,
230 pub usage: UsageInfo,
232}
233
234impl<T> Response<T> {
235 pub fn new(data: T, usage: UsageInfo) -> Self {
237 Self { data, usage }
238 }
239
240 pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Response<U> {
242 Response {
243 data: f(self.data),
244 usage: self.usage,
245 }
246 }
247}