Skip to main content

mlb_api/requests/meta/
game_status.rs

1use serde::Deserialize;
2
3id!(GameStatusId { detailedState: String });
4
5/// Detailed game status (use [`AbstractGameCode`] for simpler responses)
6#[derive(Debug, Deserialize, PartialEq, Eq, Copy, Clone)]
7pub enum CodedGameState {
8	/// Game has not begun, but is scheduled to occur
9	#[serde(rename = "S")]
10	Scheduled,
11
12	/// Game is currently undergoing pregame activities (such as warming up, or a slight delay before start)
13	#[serde(rename = "P")]
14	PreGame,
15
16	/// Game is underway.
17	#[serde(rename = "I")]
18	InProgress,
19
20	/// Manager is submitting a challenge
21	#[serde(rename = "M")]
22	ManagerChallenge,
23
24	/// Umpires are reviewing a play
25	#[serde(rename = "N")]
26	UmpireReview,
27
28	/// Game is postponed; has not begun but moved to a later date -- typically double-header.
29	#[serde(rename = "D")]
30	Postponed,
31
32	/// Game is canceled and never began. Removed from total # of games played, no rescheduling.
33	#[serde(rename = "C")]
34	Cancelled,
35
36	/// Game was finished.
37	#[serde(rename = "F", alias = "O")] // unaware of the difference
38	Finished,
39
40	/// Game was suspended, will be played on a later date.
41	#[serde(rename = "T", alias = "U")] // unaware of the difference
42	Suspended,
43
44	/// Game was forfeited.
45	#[serde(rename = "Q", alias = "R")] // unaware of the difference
46	Forfeit,
47
48	/// Game is being written?? (Likely means that the official scorer is in the process of doing the finishing touches)
49	#[serde(rename = "W")]
50	Writing,
51
52	/// Game state is unknown (typically assume the game was completed)
53	#[serde(rename = "X")]
54	Unknown,
55}
56
57/// Basic game status code, describes whether the game is in the past (finished), present (underway), or future (scheduled).
58#[derive(Debug, Deserialize, PartialEq, Eq, Copy, Clone)]
59pub enum AbstractGameCode {
60	/// Game has not begun
61	#[serde(rename = "P")]
62	Preview,
63
64	/// Game is underway
65	#[serde(rename = "L")]
66	Live,
67
68	/// Game is finished
69	#[serde(rename = "F")]
70	Finished,
71
72	/// Used for [`CodedGameStatus::Writing`] and [`CodedGameStatus::Unknown`], typically best to assume game is finished.
73	#[serde(rename = "O")]
74	Other,
75}
76
77impl AbstractGameCode {
78	#[must_use]
79	pub const fn has_begun(self) -> bool {
80		matches!(self, Self::Live | Self::Finished | Self::Other)
81	}
82
83	#[must_use]
84	pub const fn has_ended(self) -> bool {
85		matches!(self, Self::Finished | Self::Other)
86	}
87
88	#[must_use]
89	pub const fn is_preview(self) -> bool {
90		matches!(self, Self::Preview)
91	}
92
93	#[must_use]
94	pub const fn is_live(self) -> bool {
95		matches!(self, Self::Live)
96	}
97
98	#[must_use]
99	pub const fn is_finished(self) -> bool {
100		matches!(self, Self::Finished)
101	}
102
103	#[must_use]
104	pub const fn is_unknown(self) -> bool {
105		matches!(self, Self::Other)
106	}
107}
108
109#[derive(Debug, Deserialize, Clone)]
110#[serde(rename_all = "camelCase")]
111pub struct GameStatus {
112	pub abstract_game_state: String,
113	pub coded_game_state: CodedGameState,
114	pub status_code: String,
115	pub reason: Option<String>,
116	pub abstract_game_code: AbstractGameCode,
117	#[serde(flatten)]
118	pub id: GameStatusId,
119}
120
121id_only_eq_impl!(GameStatus, id);
122meta_kind_impl!("gameStatus" => GameStatus);
123tiered_request_entry_cache_impl!(GameStatus.id: GameStatusId);
124test_impl!(GameStatus);