1pub mod accept;
2pub mod add_time;
3pub mod admin_challenge;
4pub mod ai;
5pub mod cancel;
6pub mod create;
7pub mod decline;
8pub mod list;
9pub mod open;
10pub mod show;
11pub mod start_clocks;
12
13use crate::model::{Color, Days, GameCompat, Speed, Title, Variant, VariantKey};
14use serde::{Deserialize, Serialize};
15use serde_with::skip_serializing_none;
16use std::collections::HashMap;
17
18pub type AdminChallengeTokenResults = HashMap<String, String>;
19
20#[derive(Clone, Debug, Serialize)]
21pub struct OpenChallenge {
22 #[serde(flatten)]
23 pub base: ChallengeBase,
24 pub name: String,
25 pub rules: String,
26 pub users: String,
27}
28
29#[derive(Clone, Debug, Serialize)]
30#[serde(rename_all = "camelCase")]
31pub struct CreateChallenge {
32 #[serde(flatten)]
33 pub base: ChallengeBase,
34 pub rated: bool,
35 pub keep_alive_stream: bool,
36 pub accept_by_token: Option<String>,
37 pub message: Option<String>,
38 pub rules: String,
39}
40
41#[derive(Clone, Debug, PartialEq, Eq, Serialize)]
42#[serde(rename_all = "camelCase")]
43pub enum Rules {
44 NoAbort,
45 NoRematch,
46 NoGiveTime,
47 NoClaimWin,
48}
49
50#[derive(Clone, Debug, Serialize)]
51pub struct AIChallenge {
52 #[serde(flatten)]
53 pub base: ChallengeBase,
54 pub level: u32,
55 pub color: Color,
56}
57
58#[skip_serializing_none]
59#[derive(Clone, Debug, Serialize)]
60pub struct ChallengeBase {
61 #[serde(rename = "clock.limit")]
62 pub clock_limit: Option<u32>,
63 #[serde(rename = "clock.increment")]
64 pub clock_increment: Option<u32>,
65 pub days: Option<Days>,
66 pub variant: VariantKey,
67 pub fen: Option<String>,
68}
69
70#[derive(Clone, Debug, Deserialize, Serialize)]
71#[serde(rename_all = "camelCase")]
72pub struct ChallengeOpenJson {
73 pub id: String,
74 pub url: String,
75 pub status: Status,
76 pub challenger: Option<ChallengeUser>,
77 pub dest_user: Option<ChallengeUser>,
78 pub variant: Variant,
79 pub rated: bool,
80 pub speed: Speed,
81 pub time_control: TimeControl,
82 pub color: Color,
83 pub final_color: Option<Color>,
84 pub perf: Perf,
85 #[serde(skip_serializing_if = "Option::is_none")]
86 pub initial_fen: Option<String>,
87 pub url_white: String,
88 pub url_black: String,
89 pub open: OpenChallengeUsers,
90}
91
92#[derive(Clone, Debug, Deserialize, Serialize, Default)]
93#[serde(rename_all = "camelCase")]
94pub struct OpenChallengeUsers {
95 #[serde(skip_serializing_if = "Option::is_none")]
96 pub user_ids: Option<Vec<String>>,
97}
98
99#[derive(Clone, Debug, Deserialize, Serialize)]
100#[serde(rename_all = "camelCase")]
101pub struct ChallengeDeclinedJson {
102 #[serde(flatten)]
103 pub base: ChallengeJson,
104 pub decline_reason: String,
105 pub decline_reason_key: DeclineReasonKey,
106}
107
108#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
109#[serde(rename_all = "lowercase")]
110pub enum DeclineReasonKey {
111 Generic,
112 Later,
113 #[serde(rename = "toofast")]
114 TooFast,
115 #[serde(rename = "tooslow")]
116 TooSlow,
117 #[serde(rename = "timecontrol")]
118 TimeControl,
119 Rated,
120 Casual,
121 Standard,
122 Variant,
123 #[serde(rename = "nobot")]
124 NoBot,
125 #[serde(rename = "onlybot")]
126 OnlyBot,
127}
128
129#[skip_serializing_none]
130#[derive(Clone, Debug, Deserialize, Serialize)]
131#[serde(rename_all = "camelCase")]
132pub struct ChallengeJson {
133 #[serde(flatten)]
134 pub base: ChallengeJsonBase,
135 pub initial_fen: Option<String>,
136 pub decline_reason: Option<String>,
137}
138
139#[skip_serializing_none]
140#[derive(Clone, Debug, Deserialize, Serialize)]
141#[serde(rename_all = "camelCase")]
142pub struct ChallengeJsonBase {
143 pub id: String,
144 pub url: String,
145 pub color: Color,
146 pub direction: Option<Direction>,
147 pub time_control: TimeControl,
148 pub variant: Variant,
149
150 pub challenger: Option<ChallengeUser>,
153 pub dest_user: Option<ChallengeUser>,
154 pub perf: Perf,
155 pub rated: bool,
156 pub speed: Speed,
157 pub status: Status,
158 pub final_color: Option<Color>,
159}
160
161#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
162#[serde(rename_all = "camelCase")]
163pub enum Direction {
164 In,
165 Out,
166}
167
168#[derive(Clone, Debug, Deserialize, Serialize)]
169pub struct Perf {
170 pub icon: String,
171 pub name: String,
172}
173
174#[derive(Clone, Debug, Deserialize, PartialEq, Eq, Serialize)]
175#[serde(rename_all = "camelCase")]
176pub enum Status {
177 Created,
178 Offline,
179 Canceled,
180 Declined,
181 Accepted,
182}
183
184#[derive(Clone, Debug, Deserialize, Serialize)]
185#[serde(rename_all = "camelCase")]
186pub struct ChallengeEvent {
187 #[serde(rename = "type")]
188 pub event_type: String, pub challenge: ChallengeJson,
190 pub compat: Option<GameCompat>,
191}
192
193#[derive(Clone, Debug, Deserialize, Serialize)]
194#[serde(rename_all = "camelCase")]
195pub struct ChallengeCanceledEvent {
196 #[serde(rename = "type")]
197 pub event_type: String, pub challenge: ChallengeJson,
199}
200
201#[derive(Clone, Debug, Deserialize, Serialize)]
202#[serde(rename_all = "camelCase")]
203pub struct ChallengeDeclinedEvent {
204 #[serde(rename = "type")]
205 pub event_type: String, pub challenge: ChallengeDeclinedJson,
207}
208
209#[derive(Clone, Debug, Deserialize, Serialize)]
210#[serde(tag = "type")]
211#[serde(rename_all = "camelCase")]
212#[serde(rename_all_fields = "camelCase")]
213pub enum TimeControl {
214 Clock {
215 increment: u32,
216 limit: u32,
217 show: String,
218 },
219 Correspondence {
220 days_per_turn: u32,
221 },
222 Unlimited,
223}
224
225#[derive(Clone, Debug, Deserialize, Serialize)]
226pub struct ChallengeUser {
227 pub id: String,
228 pub name: String,
229 pub rating: u32,
230 pub title: Option<Title>,
231 #[serde(skip_serializing_if = "Option::is_none")]
232 pub flair: Option<String>,
233 #[serde(skip_serializing_if = "Option::is_none")]
234 pub patron: Option<bool>,
235 #[serde(skip_serializing_if = "Option::is_none")]
236 pub provisional: Option<bool>,
237 #[serde(skip_serializing_if = "Option::is_none")]
238 pub online: Option<bool>,
239 #[serde(skip_serializing_if = "Option::is_none")]
240 pub lag: Option<u32>,
241}