mcsr_ranked_api/user/
mod.rs1use std::fmt::Debug;
2
3use serde::Deserialize;
4use serde_repr::Deserialize_repr;
5use uuid::Uuid;
6
7use crate::types::{Elo, Rank};
8
9pub mod identifier;
10pub mod info;
11pub mod requests;
12#[cfg(test)]
13mod tests;
14
15#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Deserialize_repr)]
16#[repr(u8)]
17pub enum SupporterTier {
18 None = 0,
19 Stone = 1,
20 Iron = 2,
21 Diamond = 3,
22}
23
24#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
26#[serde(rename_all = "camelCase")]
27pub struct UserProfile {
28 uuid: Uuid,
29 nickname: Box<str>,
30 #[serde(rename = "roleType")]
31 supporter_tier: SupporterTier,
32 #[serde(rename = "eloRate")]
33 elo: Option<Elo>,
34 #[serde(rename = "eloRank")]
35 rank: Option<Rank>,
36 country: Option<Box<str>>,
37}
38
39#[cfg(test)]
40impl UserProfile {
41 pub(crate) fn new<U>(
42 uuid: U,
43 name: &str,
44 supporter_tier: SupporterTier,
45 elo: Option<Elo>,
46 rank: Option<Rank>,
47 country: Option<&str>,
48 ) -> Self
49 where
50 U: TryInto<Uuid>,
51 U::Error: Debug,
52 {
53 Self {
54 uuid: uuid.try_into().expect("Expected a valid uuid"),
55 nickname: name.into(),
56 supporter_tier,
57 elo,
58 rank,
59 country: country.map(Into::into),
60 }
61 }
62}
63
64impl UserProfile {
65 pub fn uuid(&self) -> Uuid {
67 self.uuid
68 }
69 pub fn nickname(&self) -> &str {
71 &self.nickname
72 }
73 pub fn supporter_tier(&self) -> SupporterTier {
75 self.supporter_tier
76 }
77 pub fn elo(&self) -> Option<Elo> {
79 self.elo
80 }
81 pub fn rank(&self) -> Option<Rank> {
83 self.rank
84 }
85}