Skip to main content

mlb_api/requests/meta/
situations.rs

1use derive_more::Display;
2use serde::Deserialize;
3
4/// Filters searching through situation codes to filter with multiple situation codes.
5///
6/// Note that with 0 [`SituationCode`](SituationCodeId)s [`SituationCodeFilter::Any`] returns `false` and [`SituationCodeFilter::All`] returns `true`.
7#[derive(Copy, Clone, Default, PartialEq, Eq)]
8pub enum SituationCodeFilter {
9	/// Display results that match <u>all</u> the [`SituationCode`]s selected.
10	All,
11
12	/// Display results that match <u>any</u> the [`SituationCode`]s selected.
13	#[default]
14	Any,
15}
16
17#[derive(Debug, Deserialize, PartialEq, Eq, Copy, Clone, Display)]
18pub enum SituationCodeCategory {
19	/// The environment the game is played in, turf, grass, day, night, home, away.
20	#[serde(rename = "Game")]
21	#[display("Game")]
22	Game,
23
24	/// The month the game is played in
25	#[serde(rename = "Month")]
26	#[display("Month")]
27	Month,
28
29	/// The time in the schedule the game is played, pre-ASG, last 30 days, etc.
30	#[serde(rename = "Timeframe")]
31	#[display("Timeframe")]
32	Timeframe,
33
34	/// Day of the week
35	#[serde(rename = "Day")]
36	#[display("Day")]
37	DayOfWeek,
38
39	/// What kind of opponent you're facing, divisional, league, etc.
40	#[serde(rename = "Opponent")]
41	#[display("Opponent")]
42	Opponent,
43
44	/// Venue-related filters.
45	#[serde(rename = "Venue")]
46	#[display("Venue")]
47	Venue,
48
49	/// General At-Bat filters; LHB, RHP, etc.
50	#[serde(rename = "At-Bat")]
51	#[display("At-Bat")]
52	AtBat,
53
54	/// Scoring data, leading, trailing, how many runs they lead by, etc.
55	#[serde(rename = "Score")]
56	#[display("Score")]
57	GameScore,
58
59	/// Inning filters; extra innings, first inning, etc.
60	#[serde(rename = "Inning")]
61	#[display("Inning")]
62	Inning,
63
64	/// Game result; win, loss, previous was a win, etc.
65	#[serde(rename = "Result")]
66	#[display("Result")]
67	GameResult,
68
69	/// Batting order position
70	#[serde(rename = "Order")]
71	#[display("Order")]
72	BattingOrder,
73
74	/// Runner positions on the bases
75	#[serde(rename = "Runners")]
76	#[display("Runners")]
77	Runners,
78
79	/// Fielding Position
80	#[serde(rename = "Position")]
81	#[display("Position")]
82	Position,
83
84	/// Days of rest, starting, relieving, etc.
85	#[serde(rename = "Pitching")]
86	#[display("Pitching")]
87	Pitching,
88
89	/// Pitch count filters.
90	#[serde(rename = "Pitch Count")]
91	#[display("Pitch Count")]
92	PitchCount,
93
94	/// None out, One out, Two out
95	#[serde(rename = "Outs")]
96	#[display("Outs")]
97	Outs,
98
99	/// 0-0 Count, 3-2 Count, etc.
100	#[serde(rename = "Count")]
101	#[display("Count")]
102	AtBatCount,
103
104	/// Type of pitch thrown
105	#[serde(rename = "Pitch Type")]
106	#[display("Pitch Type")]
107	PitchType,
108}
109
110id!(#[doc = "A [`String`] representing a situation, such as c00 for a 0-0 count"] SituationCodeId { code: String });
111
112/// A specific situation in a game
113///
114/// ## Examples
115/// ```
116/// SituationCode {
117///     category: Some(SituationCodeCategory::AtBatCount),
118///     is_team_active: true,
119///     is_batting_active: true,
120///     is_fielding_active: false,
121///     is_pitching_active: true,
122/// }
123/// ```
124#[allow(clippy::struct_excessive_bools, reason = "false positive")]
125#[derive(Debug, Deserialize, Clone)]
126pub struct SituationCode {
127	#[serde(rename = "navigationMenu", default)]
128	pub category: Option<SituationCodeCategory>,
129	pub description: String,
130	/// If the [`SituationCode`] can be applied to team stats
131	#[serde(rename = "team")]
132	pub is_team_active: bool,
133	/// If the [`SituationCode`] can be applied to hitting stats
134	#[serde(rename = "batting")]
135	pub is_batting_active: bool,
136	/// If the [`SituationCode`] can be applied to fielding stats
137	#[serde(rename = "fielding")]
138	pub is_fielding_active: bool,
139	/// If the [`SituationCode`] can be applied to pitching stats
140	#[serde(rename = "pitching")]
141	pub is_pitching_active: bool,
142	#[serde(flatten)]
143	pub id: SituationCodeId,
144}
145
146id_only_eq_impl!(SituationCode, id);
147meta_kind_impl!("situationCodes" => SituationCode);
148tiered_request_entry_cache_impl!(SituationCode.id: SituationCodeId);
149test_impl!(SituationCode);