chesscom_openapi/models/
completed_game.rs

1/*
2 * Chess
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: 1.0
7 * 
8 * Generated by: https://openapi-generator.tech
9 */
10
11
12
13
14#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
15pub struct CompletedGame {
16    #[serde(rename = "white")]
17    pub white: crate::models::PlayerResult,
18    #[serde(rename = "black")]
19    pub black: crate::models::PlayerResult,
20    /// URL of this game
21    #[serde(rename = "url")]
22    pub url: String,
23    /// Current FEN
24    #[serde(rename = "fen")]
25    pub fen: String,
26    /// Current PGN
27    #[serde(rename = "pgn")]
28    pub pgn: String,
29    /// Timestamp of the game start (Daily Chess only)
30    #[serde(rename = "start_time", skip_serializing_if = "Option::is_none")]
31    #[serde(with = "chrono::serde::ts_seconds_option")]
32	pub start_time: Option<chrono::DateTime<chrono::Utc>>,
33    /// Timestamp of the game end
34    #[serde(rename = "end_time")]
35    pub end_time: i32,
36    /// Indicates if the game was rated
37    #[serde(rename = "rated")]
38    pub rated: bool,
39    /// PGN-compliant time control
40    #[serde(rename = "time_control")]
41    pub time_control: String,
42    /// Time-per-move grouping, used for ratings
43    #[serde(rename = "time_class")]
44    pub time_class: TimeClass,
45    /// Game variant information (e.g., \"chess960\")
46    #[serde(rename = "rules")]
47    pub rules: Rules,
48    /// URL pointing to ECO opening (if available)
49    #[serde(rename = "eco", skip_serializing_if = "Option::is_none")]
50    pub eco: Option<String>,
51    /// URL pointing to tournament (if available)
52    #[serde(rename = "tournament", skip_serializing_if = "Option::is_none")]
53    pub tournament: Option<String>,
54    /// URL pointing to team match (if available)
55    #[serde(rename = "match", skip_serializing_if = "Option::is_none")]
56    pub _match: Option<String>,
57}
58
59impl CompletedGame {
60    pub fn new(white: crate::models::PlayerResult, black: crate::models::PlayerResult, url: String, fen: String, pgn: String, end_time: i32, rated: bool, time_control: String, time_class: TimeClass, rules: Rules) -> CompletedGame {
61        CompletedGame {
62            white,
63            black,
64            url,
65            fen,
66            pgn,
67            start_time: None,
68            end_time,
69            rated,
70            time_control,
71            time_class,
72            rules,
73            eco: None,
74            tournament: None,
75            _match: None,
76        }
77    }
78}
79
80/// Time-per-move grouping, used for ratings
81#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
82pub enum TimeClass {
83    #[serde(rename = "daily")]
84    Daily,
85    #[serde(rename = "rapid")]
86    Rapid,
87    #[serde(rename = "blitz")]
88    Blitz,
89    #[serde(rename = "bullet")]
90    Bullet,
91}
92
93impl std::fmt::Display for TimeClass {
94    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
95        match self {
96            TimeClass::Daily => write!(f, "daily"),
97            TimeClass::Rapid => write!(f, "rapid"),
98            TimeClass::Blitz => write!(f, "blitz"),
99            TimeClass::Bullet => write!(f, "bullet"),
100
101        }
102    }
103}
104
105/// Game variant information (e.g., \"chess960\")
106#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash, Serialize, Deserialize)]
107pub enum Rules {
108    #[serde(rename = "chess")]
109    Chess,
110    #[serde(rename = "chess960")]
111    Chess960,
112    #[serde(rename = "bughouse")]
113    Bughouse,
114    #[serde(rename = "kingofthehill")]
115    Kingofthehill,
116    #[serde(rename = "threecheck")]
117    Threecheck,
118    #[serde(rename = "crazyhouse")]
119    Crazyhouse,
120}
121
122impl std::fmt::Display for Rules {
123    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
124        match self {
125            Rules::Chess => write!(f, "chess"),
126            Rules::Chess960 => write!(f, "chess960"),
127            Rules::Bughouse => write!(f, "bughouse"),
128            Rules::Kingofthehill => write!(f, "kingofthehill"),
129            Rules::Threecheck => write!(f, "threecheck"),
130            Rules::Crazyhouse => write!(f, "crazyhouse"),
131
132        }
133    }
134}
135
136