use chrono::{DateTime, Utc};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Sport {
pub key: String,
pub group: String,
pub title: String,
pub description: String,
pub active: bool,
pub has_outrights: bool,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Event {
pub id: String,
pub sport_key: String,
pub sport_title: String,
pub commence_time: DateTime<Utc>,
pub home_team: Option<String>,
pub away_team: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EventOdds {
pub id: String,
pub sport_key: String,
pub sport_title: String,
pub commence_time: DateTime<Utc>,
pub home_team: Option<String>,
pub away_team: Option<String>,
pub bookmakers: Vec<Bookmaker>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EventScore {
pub id: String,
pub sport_key: String,
pub sport_title: String,
pub commence_time: DateTime<Utc>,
pub home_team: Option<String>,
pub away_team: Option<String>,
pub completed: bool,
pub scores: Option<Vec<Score>>,
pub last_update: Option<DateTime<Utc>>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Score {
pub name: String,
pub score: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Bookmaker {
pub key: String,
pub title: String,
pub last_update: DateTime<Utc>,
pub markets: Vec<MarketOdds>,
#[serde(skip_serializing_if = "Option::is_none")]
pub link: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub sid: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct MarketOdds {
pub key: String,
pub last_update: Option<DateTime<Utc>>,
pub outcomes: Vec<Outcome>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Outcome {
pub name: String,
pub price: f64,
#[serde(skip_serializing_if = "Option::is_none")]
pub point: Option<f64>,
#[serde(skip_serializing_if = "Option::is_none")]
pub description: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub link: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub multiplier: Option<f64>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Participant {
pub id: String,
pub full_name: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct BookmakerMarkets {
pub key: String,
pub title: String,
pub markets: Vec<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EventMarkets {
pub id: String,
pub sport_key: String,
pub sport_title: String,
pub commence_time: DateTime<Utc>,
pub home_team: Option<String>,
pub away_team: Option<String>,
pub bookmakers: Vec<BookmakerMarkets>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct HistoricalResponse<T> {
pub timestamp: DateTime<Utc>,
pub previous_timestamp: Option<DateTime<Utc>>,
pub next_timestamp: Option<DateTime<Utc>>,
pub data: T,
}
#[derive(Debug, Clone, Default)]
pub struct UsageInfo {
pub requests_remaining: Option<u32>,
pub requests_used: Option<u32>,
pub requests_last: Option<u32>,
}
impl UsageInfo {
pub(crate) fn from_headers(headers: &reqwest::header::HeaderMap) -> Self {
Self {
requests_remaining: headers
.get("x-requests-remaining")
.and_then(|v| v.to_str().ok())
.and_then(|v| v.parse().ok()),
requests_used: headers
.get("x-requests-used")
.and_then(|v| v.to_str().ok())
.and_then(|v| v.parse().ok()),
requests_last: headers
.get("x-requests-last")
.and_then(|v| v.to_str().ok())
.and_then(|v| v.parse().ok()),
}
}
}
#[derive(Debug, Clone)]
pub struct Response<T> {
pub data: T,
pub usage: UsageInfo,
}
impl<T> Response<T> {
pub fn new(data: T, usage: UsageInfo) -> Self {
Self { data, usage }
}
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> Response<U> {
Response {
data: f(self.data),
usage: self.usage,
}
}
}