mlb-api 1.0.5

Endpoints for MLB's public Statcast API.
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
//! A description of a person in baseball.
//!
//! Person works through multi-level definition.
//!
//! 1. [`PersonId`], which deserializes a:
//! ```json
//! "person": {
//!     "id": 660271,
//!     "link": "/api/v1/people/660271"
//! }
//! ```
//! 2. [`NamedPerson`], which deserializes a:
//! ```json
//! "person": {
//!     "id": 660271,
//!     "link": "/api/v1/people/660271",
//!     "fullName": "Shohei Ohtani"
//! }
//! ```
//! 3. [`Person`], which deserializes a lot of extra fields, see <http://statsapi.mlb.com/api/v1/people/660271>.
//! Technically, [`Person`] is actually an enum which separates fields supplied for [`Ballplayer`]s (handedness, draft year, etc.), and fields available to people like coaches and umpires (such as last name, age, etc.) [`RegularPerson`].
//!
//! This module also contains [`person_hydrations`](crate::person_hydrations), which are used to get additional data about people when making requests.

pub mod free_agents;
pub mod stats;
pub mod players;

use crate::cache::Requestable;
use crate::draft::School;
use crate::hydrations::Hydrations;
use crate::{Copyright, Gender, Handedness, HeightMeasurement};
use crate::request::RequestURL;
use bon::Builder;
use chrono::{Local, NaiveDate};
use derive_more::{Deref, DerefMut, Display, From};
use serde::{Deserialize, Deserializer};
use serde::de::Error;
use serde_with::{serde_as, DefaultOnError};
use std::fmt::{Debug, Display, Formatter};
use std::hash::{Hash, Hasher};
use std::ops::{Deref, DerefMut};
use crate::meta::NamedPosition;
use crate::team::NamedTeam;

#[cfg(feature = "cache")]
use crate::{rwlock_const_new, RwLock, cache::CacheTable};

/// Response containing a list of people
#[derive(Debug, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
#[serde(bound = "H: PersonHydrations")]
pub struct PeopleResponse<H: PersonHydrations> {
	pub copyright: Copyright,
	#[serde(default)]
	pub people: Vec<Person<H>>,
}

/// A baseball player.
///
/// [`Deref`]s to [`RegularPerson`]
#[derive(Debug, Deref, DerefMut, Deserialize, Clone)]
#[serde(rename_all = "camelCase")]
#[serde(bound = "H: PersonHydrations")]
pub struct Ballplayer<H: PersonHydrations> {
	#[serde(deserialize_with = "crate::try_from_str")]
	#[serde(default)]
	pub primary_number: Option<u8>,
	#[serde(flatten)]
	pub birth_data: BirthData,
	#[serde(flatten)]
	pub body_measurements: BodyMeasurements,
	pub gender: Gender,
	pub draft_year: Option<u16>,
	#[serde(rename = "mlbDebutDate")]
	pub mlb_debut: Option<NaiveDate>,
	pub bat_side: Handedness,
	pub pitch_hand: Handedness,
	#[serde(flatten)]
	pub strike_zone: StrikeZoneMeasurements,
	#[serde(rename = "nickName")]
	pub nickname: Option<String>,

	#[deref]
	#[deref_mut]
	#[serde(flatten)]
	pub inner: Box<RegularPerson<H>>,
}

/// A regular person; detailed-name stuff.
///
/// [`Deref`]s to [`NamedPerson`]
#[derive(Debug, Deserialize, Deref, DerefMut, Clone)]
#[serde(rename_all = "camelCase")]
#[serde(bound = "H: PersonHydrations")]
pub struct RegularPerson<H: PersonHydrations> {
	pub primary_position: NamedPosition,
	// '? ? Brown' in 1920 does not have a first name or a middle name, rather than dealing with Option and making everyone hate this API, the better approach is an empty String.
	#[serde(default)]
	pub first_name: String,
	#[serde(rename = "nameSuffix")]
	pub suffix: Option<String>,
	#[serde(default)] // this is how their API does it, so I'll copy that.
	pub middle_name: String,
	#[serde(default)]
	pub last_name: String,
	#[serde(default)]
	#[serde(rename = "useName")]
	pub use_first_name: String,
	#[serde(default)]
	pub use_last_name: String,
	#[serde(default)]
	pub boxscore_name: String,

	#[serde(default)]
	pub is_player: bool,
	#[serde(default)]
	pub is_verified: bool,
	#[serde(default)]
	pub active: bool,

	#[deref]
	#[deref_mut]
	#[serde(flatten)]
	pub inner: NamedPerson,

	#[serde(flatten)]
	pub extras: H,
}

impl<H: PersonHydrations> RegularPerson<H> {
	#[must_use]
	pub fn name_first_last(&self) -> String {
		format!("{0} {1}", self.use_first_name, self.use_last_name)
	}

	#[must_use]
	pub fn name_last_first(&self) -> String {
		format!("{1}, {0}", self.use_first_name, self.use_last_name)
	}

	#[must_use]
	pub fn name_last_first_initial(&self) -> String {
		self.use_first_name.chars().next().map_or_else(|| self.use_last_name.clone(), |char| format!("{1}, {0}", char, self.use_last_name))
	}

	#[must_use]
	pub fn name_first_initial_last(&self) -> String {
		self.use_first_name.chars().next().map_or_else(|| self.use_last_name.clone(), |char| format!("{0} {1}", char, self.use_last_name))
	}

	#[must_use]
	pub fn name_fml(&self) -> String {
		format!("{0} {1} {2}", self.use_first_name, self.middle_name, self.use_last_name)
	}

	#[must_use]
	pub fn name_lfm(&self) -> String {
		format!("{2}, {0} {1}", self.use_first_name, self.middle_name, self.use_last_name)
	}
}

/// A person with a name.
///
/// [`Deref`]s to [`PersonId`]
#[derive(Debug, Deserialize, Clone, Eq)]
#[serde(rename_all = "camelCase")]
pub struct NamedPerson {
	pub full_name: String,

	#[serde(flatten)]
	pub id: PersonId,
}

impl Hash for NamedPerson {
	fn hash<H: Hasher>(&self, state: &mut H) {
		self.id.hash(state);
	}
}

impl NamedPerson {
	#[must_use]
	pub(crate) fn unknown_person() -> Self {
		Self {
			full_name: "null".to_owned(),
			id: PersonId::new(0),
		}
	}

	#[must_use]
	pub fn is_unknown(&self) -> bool {
		*self.id == 0
	}
}

id!(#[doc = "A [`u32`] that represents a person."] PersonId { id: u32 });

/// A complete person response for a hydrated request. Ballplayers have more fields.
#[derive(Debug, Clone, From)]
pub enum Person<H: PersonHydrations = ()> {
	Ballplayer(Ballplayer<H>),
	Regular(RegularPerson<H>),
}

impl<'de, H: PersonHydrations> Deserialize<'de> for Person<H> {
	#[allow(clippy::too_many_lines, reason = "still easy to understand cause low logic lines")]
	fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
	where
		D: Deserializer<'de>
	{
		#[serde_as]
		#[derive(Deserialize)]
		#[serde(bound = "H2: PersonHydrations")]
		struct Repr<H2: PersonHydrations> {
			#[serde(flatten)]
			regular: RegularPerson<H2>,
			#[serde_as(deserialize_as = "DefaultOnError")]
			#[serde(flatten, default)]
			ballplayer: Option<BallplayerContent>,
		}

		#[derive(Deserialize)]
		struct BallplayerContent {
			#[serde(deserialize_with = "crate::try_from_str")]
			#[serde(default)]
			primary_number: Option<u8>,
			#[serde(flatten)]
			birth_data: BirthData,
			#[serde(flatten)]
			body_measurements: BodyMeasurements,
			gender: Gender,
			draft_year: Option<u16>,
			#[serde(rename = "mlbDebutDate")]
			mlb_debut: Option<NaiveDate>,
			bat_side: Handedness,
			pitch_hand: Handedness,
			#[serde(flatten)]
			strike_zone: StrikeZoneMeasurements,
			#[serde(rename = "nickName")]
			nickname: Option<String>,
		}

		let Repr { regular, ballplayer } = Repr::<H>::deserialize(deserializer)?;

		Ok(match ballplayer {
			Some(BallplayerContent {
				primary_number,
				birth_data,
				body_measurements,
				gender,
				draft_year,
				mlb_debut,
				bat_side,
				pitch_hand,
				strike_zone,
				nickname,
			}) => Self::Ballplayer(Ballplayer {
				primary_number,
				birth_data,
				body_measurements,
				gender,
				draft_year,
				mlb_debut,
				bat_side,
				pitch_hand,
				strike_zone,
				nickname,
				inner: Box::new(regular),
			}),
			None => Self::Regular(regular),
		})
	}
}

impl<H: PersonHydrations> Person<H> {
	#[must_use]
	pub const fn as_ballplayer(&self) -> Option<&Ballplayer<H>> {
		match self {
			Self::Ballplayer(x) => Some(x),
			Self::Regular(_) => None,
		}
	}
}

impl<H: PersonHydrations> Person<H> {
	#[must_use]
	pub const fn as_ballplayer_mut(&mut self) -> Option<&mut Ballplayer<H>> {
		match self {
			Self::Ballplayer(x) => Some(x),
			Self::Regular(_) => None,
		}
	}
}

impl<H: PersonHydrations> Person<H> {
	#[must_use]
	pub fn into_ballplayer(self) -> Option<Ballplayer<H>> {
		match self {
			Self::Ballplayer(x) => Some(x),
			Self::Regular(_) => None,
		}
	}
}

impl<H: PersonHydrations> Deref for Person<H> {
	type Target = RegularPerson<H>;

	fn deref(&self) -> &Self::Target {
		match self {
			Self::Ballplayer(x) => x,
			Self::Regular(x) => x,
		}
	}
}

impl<H: PersonHydrations> DerefMut for Person<H> {
	fn deref_mut(&mut self) -> &mut Self::Target {
		match self {
			Self::Ballplayer(x) => x,
			Self::Regular(x) => x,
		}
	}
}

impl<H1: PersonHydrations, H2: PersonHydrations> PartialEq<Person<H2>> for Person<H1> {
	fn eq(&self, other: &Person<H2>) -> bool {
		self.id == other.id
	}
}

impl<H1: PersonHydrations, H2: PersonHydrations> PartialEq<Ballplayer<H2>> for Ballplayer<H1> {
	fn eq(&self, other: &Ballplayer<H2>) -> bool {
		self.id == other.id
	}
}

impl<H1: PersonHydrations, H2: PersonHydrations> PartialEq<RegularPerson<H2>> for RegularPerson<H1> {
	fn eq(&self, other: &RegularPerson<H2>) -> bool {
		self.id == other.id
	}
}

id_only_eq_impl!(NamedPerson, id);

/// Returns a [`PeopleResponse`].
#[derive(Builder)]
#[builder(derive(Into))]
pub struct PersonRequest<H: PersonHydrations> {
	#[builder(into)]
	id: PersonId,

	#[builder(into)]
	hydrations: H::RequestData,
}

impl PersonRequest<()> {
	pub fn for_id(id: impl Into<PersonId>) -> PersonRequestBuilder<(), person_request_builder::SetHydrations<person_request_builder::SetId>> {
		Self::builder().id(id).hydrations(())
	}
}

impl<H: PersonHydrations, S: person_request_builder::State + person_request_builder::IsComplete> crate::request::RequestURLBuilderExt for PersonRequestBuilder<H, S> {
	type Built = PersonRequest<H>;
}

impl<H: PersonHydrations> Display for PersonRequest<H> {
	fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
		let hydration_text = H::hydration_text(&self.hydrations);
		if hydration_text.is_empty() {
			write!(f, "http://statsapi.mlb.com/api/v1/people/{}", self.id)
		} else {
			write!(f, "http://statsapi.mlb.com/api/v1/people/{}?hydrate={hydration_text}", self.id)
		}
	}
}

impl<H: PersonHydrations> RequestURL for PersonRequest<H> {
	type Response = PeopleResponse<H>;
}

/// The number on the back of a jersey, useful for radix sorts maybe??
#[repr(transparent)]
#[derive(Debug, Deref, Display, PartialEq, Eq, Copy, Clone, Hash, From)]
pub struct JerseyNumber(u8);

impl<'de> Deserialize<'de> for JerseyNumber {
	fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
	where
		D: Deserializer<'de>,
	{
		String::deserialize(deserializer)?.parse::<u8>().map(JerseyNumber).map_err(D::Error::custom)
	}
}

/// Data regarding birthplace.
#[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BirthData {
	pub birth_date: NaiveDate,
	pub birth_city: String,
	#[serde(rename = "birthStateProvince")]
	pub birth_state_or_province: Option<String>,
	pub birth_country: String,
}

impl BirthData {
	#[must_use]
	pub fn current_age(&self) -> u16 {
		Local::now().naive_local().date().years_since(self.birth_date).and_then(|x| u16::try_from(x).ok()).unwrap_or(0)
	}
}

/// Height and weight
#[derive(Debug, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct BodyMeasurements {
	pub height: HeightMeasurement,
	pub weight: u16,
}

/// Strike zone dimensions, measured in feet from the ground.
#[derive(Debug, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct StrikeZoneMeasurements {
	pub strike_zone_top: f64,
	pub strike_zone_bottom: f64,
}

/// Data regarding preferred team, likely for showcasing the player with a certain look regardless of the time.
#[serde_as]
#[derive(Debug, Deserialize, PartialEq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct PreferredTeamData {
	#[serde(default)]
	#[serde_as(deserialize_as = "DefaultOnError")]
	pub jersey_number: Option<JerseyNumber>,
	pub position: NamedPosition,
	pub team: NamedTeam,
}

/// Relative to the ballplayer, father, son, etc.
#[derive(Debug, Deserialize, PartialEq, Eq, Clone)]
#[serde(rename_all = "camelCase")]
pub struct Relative {
	pub has_stats: bool,
	pub relation: String,
	#[serde(flatten)]
	pub person: NamedPerson,
}

/// Schools the ballplayer went to.
#[derive(Debug, Deserialize, PartialEq, Clone, Default)]
pub struct Education {
	#[serde(default)]
	pub highschools: Vec<School>,
	#[serde(default)]
	pub colleges: Vec<School>,
}

/// A type that is made with [`person_hydrations!`](crate::person_hydrations)
pub trait PersonHydrations: Hydrations {}

impl PersonHydrations for () {}

/// Creates hydrations for a person
/// 
/// ## Examples
///```no_run
/// person_hydrations! {
///     pub struct TestHydrations {  ->  pub struct TestHydrations {
///         awards,                     ->      awards: Vec<Award>,
///         social,                     ->      social: HashMap<String, Vec<String>>,
///         stats: MyStats,             ->      stats: MyStats,
///     }                               ->  }
/// }
///
/// person_hydrations! {
///     pub struct TestHydrations {        ->  pub struct TestHydrations {
///         stats: { [Season] + [Hitting] },  ->      stats: TestHydrationsInlineStats,
///     }                                     ->  }
/// }
///
/// let request = PersonRequest::<TestHydrations>::builder()
///     .id(660_271)
///     .hydrations(TestHydrations::builder())
///     .build();
///
/// let response = request.get().await.unwrap();
///```
///
/// ## Person Hydrations
/// <u>Note: Fields must appear in exactly this order (or be omitted)</u>
///
/// | Name             | Type                             |
/// |------------------|----------------------------------|
/// | `awards`         | [`Vec<Award>`]                   |
/// | `current_team`   | [`Team`]                         |
/// | `depth_charts`   | [`Vec<RosterEntry>`]             |
/// | `draft`          | [`Vec<DraftPick>`]               |
/// | `education`      | [`Education`]                    |
/// | `jobs`           | [`Vec<EmployedPerson>`]          |
/// | `nicknames`      | [`Vec<String>`]                  |
/// | `preferred_team` | [`Team`]                         |
/// | `relatives`      | [`Vec<Relative>`]                |
/// | `roster_entries` | [`Vec<RosterEntry>`]             |
/// | `transactions`   | [`Vec<Transaction>`]             |
/// | `social`         | [`HashMap<String, Vec<String>>`] |
/// | `stats`          | [`stats_hydrations!`]            |
/// | `external_references` | [`Vec<ExternalReference>`]  |
///
/// [`Vec<Award>`]: crate::awards::Award
/// [`Team`]: crate::team::Team
/// [`Vec<RosterEntry>`]: crate::team::roster::RosterEntry
/// [`Vec<DraftPick>`]: crate::draft::DraftPick
/// [`Education`]: Education
/// [`Vec<EmployedPerson>`]: crate::jobs::EmployedPerson
/// [`Vec<String>`]: String
/// [`Team`]: crate::team::Team
/// [`Vec<Relative>`]: Relative
/// [`Vec<RosterEntry>`]: crate::team::rosterRosterEntry
/// [`Vec<Transaction>`]: crate::transactions::Transaction
/// [`HashMap<String, Vec<String>>`]: std::collections::HashMap
/// [`stats_hydrations!`]: crate::stats_hydrations
/// [`Vec<ExternalReference>`]: crate::types::ExternalReference
#[macro_export]
macro_rules! person_hydrations {
	(@ inline_structs [stats: { $($contents:tt)* } $(, $($rest:tt)*)?] $vis:vis struct $name:ident { $($field_tt:tt)* }) => {
        $crate::macro_use::pastey::paste! {
            $crate::stats_hydrations! {
                $vis struct [<$name InlineStats>] {
                    $($contents)*
                }
            }

            $crate::person_hydrations! { @ inline_structs [$($($rest)*)?]
                $vis struct $name {
                    $($field_tt)*
                    stats: [<$name InlineStats>],
                }
            }
        }
    };
    (@ inline_structs [$marker:ident : { $($contents:tt)* } $(, $($rest:tt)*)?] $vis:vis struct $name:ident { $($field_tt:tt)* }) => {
        ::core::compile_error!("Found unknown inline struct");
    };
    (@ inline_structs [$marker:ident $(: $value:ty)? $(, $($rest:tt)*)?] $vis:vis struct $name:ident { $($field_tt:tt)* }) => {
        $crate::macro_use::pastey::paste! {
            $crate::person_hydrations! { @ inline_structs [$($($rest)*)?]
                $vis struct $name {
                    $($field_tt)*
                    $marker $(: $value)?,
                }
            }
        }
    };
    (@ inline_structs [$(,)?] $vis:vis struct $name:ident { $($field_tt:tt)* }) => {
        $crate::macro_use::pastey::paste! {
            $crate::person_hydrations! { @ actual
                $vis struct $name {
                    $($field_tt)*
                }
            }
        }
    };
    (@ actual
		$vis:vis struct $name:ident {
			$(awards $awards_comma:tt)?
			$(current_team $current_team_comma:tt)?
			$(depth_charts $depth_charts_comma:tt)?
			$(draft $draft_comma:tt)?
			$(education $education_comma:tt)?
			$(jobs $jobs_comma:tt)?
			$(nicknames $nicknames_comma:tt)?
			$(preferred_team $preferred_team_comma:tt)?
			$(relatives $relatives_comma:tt)?
			$(roster_entries $roster_entries_comma:tt)?
			$(transactions $transactions_comma:tt)?
			$(social $social_comma:tt)?
			$(stats: $stats:ty ,)?
			$(external_references $external_references_comma:tt)?
		}
    ) => {
		$crate::macro_use::pastey::paste! {
			#[derive(::core::fmt::Debug, $crate::macro_use::serde::Deserialize, ::core::cmp::PartialEq, ::core::clone::Clone)]
			#[serde(rename_all = "camelCase")]
			$vis struct $name {
				$(#[serde(default)] pub awards: ::std::vec::Vec<$crate::awards::Award> $awards_comma)?
				$(pub current_team: ::core::option::Option<$crate::team::NamedTeam> $current_team_comma)?
				$(#[serde(default)] pub depth_charts: ::std::vec::Vec<$crate::team::roster::RosterEntry> $depth_charts_comma)?
				$(#[serde(default, rename = "drafts")] pub draft: ::std::vec::Vec<$crate::draft::DraftPick> $draft_comma)?
				$(#[serde(default)] pub education: $crate::person::Education $education_comma)?
				$(#[serde(default, rename = "jobEntries")] pub jobs: ::std::vec::Vec<$crate::jobs::EmployedPerson> $jobs_comma)?
				$(#[serde(default)] pub nicknames: ::std::vec::Vec<String> $nicknames_comma)?
				$(pub preferred_team: ::core::option::Option<$crate::person::PreferredTeamData> $preferred_team_comma)?
				$(#[serde(default)] pub relatives: ::std::vec::Vec<$crate::person::Relative> $relatives_comma)?
				$(#[serde(default)] pub roster_entries: ::std::vec::Vec<$crate::team::roster::RosterEntry> $roster_entries_comma)?
				$(#[serde(default)] pub transactions: ::std::vec::Vec<$crate::transactions::Transaction> $transactions_comma)?
				$(#[serde(flatten)] pub stats: $stats ,)?
				$(#[serde(default, rename = "social")] pub socials: ::std::collections::HashMap<String, Vec<String>> $social_comma)?
				$(#[serde(default, rename = "xrefIds")] pub external_references: ::std::vec::Vec<$crate::ExternalReference> $external_references_comma)?
			}

			impl $crate::person::PersonHydrations for $name {}

			impl $crate::hydrations::Hydrations for $name {
				type RequestData = [<$name RequestData>];

				fn hydration_text(_data: &Self::RequestData) -> ::std::borrow::Cow<'static, str> {
					let text = ::std::borrow::Cow::Borrowed(::std::concat!(
						$("awards," $awards_comma)?
						$("currentTeam," $current_team_comma)?
						$("depthCharts," $depth_charts_comma)?
						$("draft," $draft_comma)?
						$("education," $education_comma)?
						$("jobs," $jobs_comma)?
						$("nicknames," $nicknames_comma)?
						$("preferredTeam," $preferred_team_comma)?
						$("relatives," $relatives_comma)?
						$("rosterEntries," $roster_entries_comma)?
						$("transactions," $transactions_comma)?
						$("social," $social_comma)?
						$("xrefId," $external_references_comma)?
					));

					$(
					let text = ::std::borrow::Cow::Owned(::std::format!("{text}stats({}),", <$stats as $crate::hydrations::Hydrations>::hydration_text(&_data.stats)));
					)?

					text
				}
			}

			#[derive($crate::macro_use::bon::Builder)]
			#[builder(derive(Into))]
			$vis struct [<$name RequestData>] {
				$(#[builder(into)] stats: <$stats as $crate::hydrations::Hydrations>::RequestData,)?
			}

			impl $name {
				#[allow(unused, reason = "potentially unused if the builder is Default")]
				pub fn builder() -> [<$name RequestDataBuilder>] {
					[<$name RequestData>]::builder()
				}
			}

			impl ::core::default::Default for [<$name RequestData>]
			where
				$(for<'no_rfc_2056> <$stats as $crate::hydrations::Hydrations>::RequestData: ::core::default::Default,)?
			{
				fn default() -> Self {
					Self {
						$(stats: <<$stats as $crate::hydrations::Hydrations>::RequestData as ::core::default::Default>::default(),)?
					}
				}
			}
		}
    };
	($vis:vis struct $name:ident {
		$($tt:tt)*
	}) => {
		$crate::person_hydrations! { @ inline_structs [$($tt)*] $vis struct $name {} }
	};
}

#[cfg(feature = "cache")]
static CACHE: RwLock<CacheTable<Person<()>>> = rwlock_const_new(CacheTable::new());

impl Requestable for Person<()> {
	type Identifier = PersonId;
	type URL = PersonRequest<()>;

	fn id(&self) -> &Self::Identifier {
		&self.id
	}

	fn url_for_id(id: &Self::Identifier) -> Self::URL {
		PersonRequest::for_id(*id).build()
	}

	fn get_entries(response: <Self::URL as RequestURL>::Response) -> impl IntoIterator<Item = Self>
	where
		Self: Sized,
	{
		response.people
	}

	#[cfg(feature = "cache")]
	fn get_cache_table() -> &'static RwLock<CacheTable<Self>>
	where
		Self: Sized,
	{
		&CACHE
	}
}

entrypoint!(PersonId => Person);
entrypoint!(NamedPerson.id => Person);
entrypoint!(for < H > RegularPerson < H > . id => Person < > where H: PersonHydrations);
entrypoint!(for < H > Ballplayer < H > . id => Person < > where H: PersonHydrations);

#[cfg(test)]
mod tests {
	use crate::person::players::PlayersRequest;
	use crate::request::RequestURLBuilderExt;
	use crate::sport::SportId;
	use super::*;
	use crate::TEST_YEAR;

	#[tokio::test]
	async fn no_hydrations() {
		person_hydrations! {
			pub struct EmptyHydrations {}
		}

		let _ = PersonRequest::<()>::for_id(665_489).build_and_get().await.unwrap();
		let _ = PersonRequest::<EmptyHydrations>::builder().id(665_489).hydrations(EmptyHydrationsRequestData::default()).build_and_get().await.unwrap();
	}

	#[tokio::test]
	async fn all_but_stats_hydrations() {
		person_hydrations! {
			pub struct AllButStatHydrations {
				awards,
				current_team,
				depth_charts,
				draft,
				education,
				jobs,
				nicknames,
				preferred_team,
				relatives,
				roster_entries,
				transactions,
				social,
				external_references
			}
		}

		let _person = PersonRequest::<AllButStatHydrations>::builder().hydrations(AllButStatHydrationsRequestData::default()).id(665_489).build_and_get().await.unwrap().people.into_iter().next().unwrap();
	}

	#[rustfmt::skip]
	#[tokio::test]
	async fn only_stats_hydrations() {
		person_hydrations! {
			pub struct StatOnlyHydrations {
				stats: { [Sabermetrics] + [Pitching] },
			}
		}

		let player = PlayersRequest::<()>::for_sport(SportId::MLB)
			.season(TEST_YEAR)
			.build_and_get()
			.await
			.unwrap()
			.people
			.into_iter()
			.find(|player| player.full_name == "Kevin Gausman")
			.unwrap();

		let request = PersonRequest::<StatOnlyHydrations>::builder()
			.id(player.id)
			.hydrations(StatOnlyHydrations::builder()
				.stats(StatOnlyHydrationsInlineStats::builder()
					.season(2023)
					// .situation(SituationCodeId::new("h"))
				)
			).build();
		println!("{request}");
		let player = request.get()
			.await
			.unwrap()
			.people
			.into_iter()
			.next()
			.unwrap();

		dbg!(&player.extras.stats);
	}
}