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
use crate::model::challenges::ChallengeJson;
use crate::model::{Color, Compat, Speed, Variant};
use serde::{Deserialize, Serialize};
use serde_with::skip_serializing_none;

#[derive(Default, Clone, Debug, Serialize)]
pub struct GetQuery;

pub type GetRequest = crate::model::Request<GetQuery>;

impl GetRequest {
    pub fn new() -> Self {
        Self {
            path: "/api/stream/event".to_string(),
            ..Default::default()
        }
    }
}

// Response structs.

#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(tag = "type")]
#[serde(rename_all = "camelCase")]
pub enum Event {
    Challenge { challenge: ChallengeJson },
    ChallengeCanceled { challenge: ChallengeJson },
    ChallengeDeclined { challenge: ChallengeJson },
    GameStart { game: GameEventInfo },
    GameFinish { game: GameEventInfo },
}

#[skip_serializing_none]
#[derive(Clone, Debug, Deserialize, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct GameEventInfo {
    pub full_id: String,
    pub game_id: String,
    pub fen: String,
    pub color: Color,
    pub last_move: String,
    pub source: Source,
    pub variant: Variant,
    pub speed: Speed,
    pub perf: String,
    pub rated: bool,
    pub has_moved: bool,
    pub opponent: Opponent,
    pub is_my_turn: bool,
    pub seconds_left: Option<u64>,
    pub compat: Option<Compat>,
}

#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
#[serde(rename_all = "camelCase")]
pub enum Source {
    Lobby,
    Friend,
    Ai,
    Api,
    Tournament,
    Position,
    Import,
    Importlive,
    Simul,
    Relay,
    Pool,
    Swiss,
}

#[skip_serializing_none]
#[derive(Clone, Debug, Serialize, Deserialize)]
pub struct Opponent {
    pub id: Option<String>,
    pub username: String,
    pub rating: Option<u32>,
    pub ai: Option<u32>,
}

#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct ChallengeCanceledJson {
    pub id: String,
}