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

use serde::Serialize;

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

use super::OrdrFuture;

#[derive(Serialize)]
struct GetSkinCustomFields {
    id: u32,
}

/// Get [`SkinInfo`] of a custom skin.
#[must_use]
pub struct GetSkinCustom<'a> {
    ordr: &'a OrdrClient,
    fields: GetSkinCustomFields,
}

impl<'a> GetSkinCustom<'a> {
    pub(crate) const fn new(ordr: &'a OrdrClient, id: u32) -> Self {
        Self {
            ordr,
            fields: GetSkinCustomFields { id },
        }
    }
}

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

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

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

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