lichess_api/model/games/
mod.rs

1pub mod export;
2pub mod import;
3pub mod ongoing;
4pub mod stream;
5
6use crate::model::{Clock, LightUser, PlayerColor, Speed, VariantKey};
7use serde::{Deserialize, Serialize};
8
9#[serde_with::skip_serializing_none]
10#[derive(Clone, Debug, Serialize, Deserialize)]
11#[serde(rename_all = "camelCase")]
12pub struct GameStream {
13    pub id: String,
14    pub rated: bool,
15    pub variant: VariantKey,
16    pub speed: Speed,
17    pub perf: String,
18    pub created_at: u64,
19    pub status: u32,
20    pub status_name: GameStatus,
21    pub players: Players,
22    pub clock: Option<Clock>,
23}
24
25#[serde_with::skip_serializing_none]
26#[derive(Clone, Debug, Serialize, Deserialize)]
27#[serde(rename_all = "camelCase")]
28pub struct GameJson {
29    pub id: String,
30    pub rated: bool,
31    pub variant: VariantKey,
32    pub speed: Speed,
33    pub perf: String,
34    pub created_at: u64,
35    pub last_move_at: Option<u64>,
36    pub status: GameStatus,
37    pub players: Option<Players>,
38    pub initial_fen: Option<String>,
39    pub winner: Option<PlayerColor>,
40    pub opening: Option<Opening>,
41    pub moves: Option<String>,
42    pub pgn: Option<String>,
43    pub days_per_turn: Option<u64>,
44    pub analysis: Option<Vec<GameMoveAnalysis>>,
45    pub tournament: Option<String>,
46    pub swiss: Option<String>,
47    pub clock: Option<Clock>,
48    pub clocks: Option<Vec<u64>>,
49    pub division: Option<Division>,
50}
51
52#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
53#[serde(rename_all = "camelCase")]
54pub enum GameStatus {
55    Created,
56    Started,
57    Aborted,
58    Mate,
59    Resign,
60    Stalemate,
61    Timeout,
62    Draw,
63    Outoftime,
64    Cheat,
65    NoStart,
66    UnknownFinish,
67    VariantEnd,
68}
69
70#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
71pub struct GameStatusJson {
72    pub id: u32,
73    pub name: GameStatus,
74}
75
76#[serde_with::skip_serializing_none]
77#[derive(Clone, Debug, Serialize, Deserialize)]
78pub struct Players {
79    pub white: Option<GameUser>,
80    pub black: Option<GameUser>,
81}
82
83#[serde_with::skip_serializing_none]
84#[derive(Clone, Debug, Serialize, Deserialize)]
85#[serde(rename_all = "camelCase")]
86pub struct GameUser {
87    pub user: Option<LightUser>,
88    pub rating: Option<u32>,
89    pub rating_diff: Option<i32>,
90    pub name: Option<String>,
91    pub provisional: Option<bool>,
92    pub ai_level: Option<u32>,
93    pub analysis: Option<Analysis>,
94    pub team: Option<String>,
95}
96
97#[derive(Clone, Debug, Serialize, Deserialize)]
98pub struct Analysis {
99    pub inaccuracy: u32,
100    pub mistake: u32,
101    pub blunder: u32,
102    pub acpl: u32,
103}
104
105#[derive(Clone, Debug, Serialize, Deserialize)]
106pub struct Opening {
107    pub eco: String,
108    pub name: String,
109    pub ply: u32,
110}
111
112#[serde_with::skip_serializing_none]
113#[derive(Clone, Debug, Serialize, Deserialize)]
114pub struct Division {
115    pub middle: Option<u32>,
116    pub end: Option<u32>,
117}
118
119#[serde_with::skip_serializing_none]
120#[derive(Clone, Debug, Serialize, Deserialize)]
121pub struct GameMoveAnalysis {
122    pub eval: Option<i32>,
123    pub mate: Option<u32>,
124    pub best: Option<String>,
125    pub variation: Option<String>,
126    // ion232: Incorrect spelling here is expected.
127    pub judgment: Option<Judgement>,
128}
129
130#[serde_with::skip_serializing_none]
131#[derive(Debug, Clone, Serialize, Deserialize)]
132pub struct Judgement {
133    pub name: JudgementName,
134    pub comment: Option<String>,
135}
136
137#[derive(Debug, Clone, Serialize, Deserialize)]
138pub enum JudgementName {
139    // ion232: These are expected to be uppercase.
140    Inaccuracy,
141    Mistake,
142    Blunder,
143}