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
use std::future::IntoFuture;

use serde::Serialize;

use crate::{model::SkinList, request::Request, routing::Route, ClientError, OrdrClient};

use super::OrdrFuture;

#[derive(Serialize)]
struct GetSkinListFields<'a> {
    #[serde(rename = "pageSize")]
    page_size: Option<u32>,
    page: Option<u32>,
    search: Option<&'a str>,
}

/// Get a [`SkinList`].
#[must_use]
pub struct GetSkinList<'a> {
    ordr: &'a OrdrClient,
    fields: GetSkinListFields<'a>,
}

impl<'a> GetSkinList<'a> {
    pub(crate) const fn new(ordr: &'a OrdrClient) -> Self {
        Self {
            ordr,
            fields: GetSkinListFields {
                page_size: None,
                page: None,
                search: None,
            },
        }
    }

    /// The number of skins the API will return you in the page. If not specified, 100 is the default.
    pub fn page_size(&mut self, page_size: u32) -> &mut Self {
        self.fields.page_size = Some(page_size);
        self.fields.page.get_or_insert(1);

        self
    }

    /// The page.
    pub fn page(&mut self, page: u32) -> &mut Self {
        self.fields.page = Some(page);

        self
    }

    /// Get the skins that matches the most your string.
    pub fn search(&mut self, search: &'a str) -> &mut Self {
        self.fields.search = Some(search);

        self
    }
}

impl IntoFuture for &mut GetSkinList<'_> {
    type Output = Result<SkinList, ClientError>;
    type IntoFuture = OrdrFuture<SkinList>;

    fn into_future(self) -> Self::IntoFuture {
        match Request::builder(Route::SkinList).query(&self.fields) {
            Ok(builder) => self.ordr.request(builder.build()),
            Err(err) => OrdrFuture::error(err),
        }
    }
}

impl IntoFuture for GetSkinList<'_> {
    type Output = Result<SkinList, ClientError>;
    type IntoFuture = OrdrFuture<SkinList>;

    fn into_future(mut self) -> Self::IntoFuture {
        (&mut self).into_future()
    }
}