|
| 1 | +//! Public match metadata and bounded history queries. |
| 2 | +use schemars::JsonSchema; |
| 3 | +use serde::{Deserialize, Serialize}; |
| 4 | + |
| 5 | +/// Current lifecycle status derived from the event log. |
| 6 | +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] |
| 7 | +#[derive(Clone, Copy, Debug, PartialEq, Eq, Serialize, Deserialize, JsonSchema)] |
| 8 | +#[serde(rename_all = "snake_case")] |
| 9 | +pub enum MatchStatus { |
| 10 | + /// The engine is waiting for another move. |
| 11 | + Active, |
| 12 | + /// The game reached a terminal result or a length cap. |
| 13 | + Finished, |
| 14 | +} |
| 15 | + |
| 16 | +/// Public metadata, excluding private state, seeds and player reasoning. |
| 17 | +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] |
| 18 | +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)] |
| 19 | +pub struct MatchMetadata { |
| 20 | + /// Match identifier. |
| 21 | + pub match_id: String, |
| 22 | + /// Registered game identifier. |
| 23 | + pub game_id: String, |
| 24 | + /// Engine version used for reconstruction. |
| 25 | + pub engine_version: String, |
| 26 | + /// Current lifecycle status. |
| 27 | + pub status: MatchStatus, |
| 28 | + /// Accepted action count. |
| 29 | + pub turn: u64, |
| 30 | + /// Seats currently required to act. |
| 31 | + pub to_act: Vec<u8>, |
| 32 | + /// Per-seat returns. |
| 33 | + pub returns: Vec<f64>, |
| 34 | + /// Rules ended play. |
| 35 | + pub terminated: bool, |
| 36 | + /// A length or external cap ended play. |
| 37 | + pub truncated: bool, |
| 38 | + /// Creation timestamp in Unix milliseconds. |
| 39 | + pub created_at_ms: u64, |
| 40 | +} |
| 41 | + |
| 42 | +fn default_limit() -> u32 { |
| 43 | + 50 |
| 44 | +} |
| 45 | + |
| 46 | +/// Cursor query for local match history. |
| 47 | +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema, utoipa::IntoParams))] |
| 48 | +#[cfg_attr(feature = "openapi", into_params(parameter_in = Query))] |
| 49 | +#[derive(Clone, Debug, Serialize, Deserialize, JsonSchema)] |
| 50 | +#[serde(deny_unknown_fields)] |
| 51 | +pub struct MatchHistoryQuery { |
| 52 | + /// Exclusive match-id cursor; omit for the first page. |
| 53 | + pub after: Option<String>, |
| 54 | + /// Restrict results to one registered game. |
| 55 | + pub game_id: Option<String>, |
| 56 | + /// Restrict results to active or finished games. |
| 57 | + pub status: Option<MatchStatus>, |
| 58 | + /// Maximum records scanned before filtering, from 1 to 100. |
| 59 | + #[serde(default = "default_limit")] |
| 60 | + pub limit: u32, |
| 61 | +} |
| 62 | + |
| 63 | +impl Default for MatchHistoryQuery { |
| 64 | + fn default() -> Self { |
| 65 | + Self { |
| 66 | + after: None, |
| 67 | + game_id: None, |
| 68 | + status: None, |
| 69 | + limit: default_limit(), |
| 70 | + } |
| 71 | + } |
| 72 | +} |
| 73 | + |
| 74 | +/// One bounded page; filters can produce an empty page with a continuation cursor. |
| 75 | +#[cfg_attr(feature = "openapi", derive(utoipa::ToSchema))] |
| 76 | +#[derive(Clone, Debug, PartialEq, Serialize, Deserialize, JsonSchema)] |
| 77 | +pub struct MatchHistory { |
| 78 | + /// Matching records from this page, in ascending match-id order. |
| 79 | + pub matches: Vec<MatchMetadata>, |
| 80 | + /// Exclusive cursor for the next page; null means the scan is exhausted. |
| 81 | + pub next: Option<String>, |
| 82 | +} |
0 commit comments