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
use crate::model::{Color, Days, VariantKey};
use serde::Serialize;

#[derive(Clone, Debug, Serialize)]
#[serde(rename_all = "camelCase")]
pub struct PostQuery {
    #[serde(flatten)]
    pub seek_type: SeekType,
    pub rated: bool,
    pub variant: VariantKey,
    pub color: Color,
    pub rating_range: String,
}

#[derive(Clone, Debug, Serialize)]
#[serde(untagged)]
pub enum SeekType {
    Correspondence { days: Days },
    RealTime { time: u32, increment: u32 },
}

impl Default for PostQuery {
    fn default() -> Self {
        Self {
            rated: false,
            seek_type: SeekType::RealTime {
                time: 5,
                increment: 3,
            },
            variant: VariantKey::Standard,
            color: Color::Random,
            rating_range: "".to_string(),
        }
    }
}

pub type PostRequest = crate::model::Request<PostQuery>;

impl PostRequest {
    pub fn new() -> Self {
        Self {
            method: http::Method::POST,
            path: "/api/board/seek".to_string(),
            ..Default::default()
        }
    }
}