use std::fmt::Debug;
use serde::Deserialize;
use serde_repr::Deserialize_repr;
use uuid::Uuid;
use crate::types::{Elo, Rank};
pub mod identifier;
pub mod info;
pub mod requests;
#[cfg(test)]
mod tests;
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Deserialize_repr)]
#[repr(u8)]
pub enum SupporterTier {
None = 0,
Stone = 1,
Iron = 2,
Diamond = 3,
}
#[derive(Debug, Clone, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "camelCase")]
pub struct UserProfile {
uuid: Uuid,
nickname: Box<str>,
#[serde(rename = "roleType")]
supporter_tier: SupporterTier,
#[serde(rename = "eloRate")]
elo: Option<Elo>,
#[serde(rename = "eloRank")]
rank: Option<Rank>,
country: Option<Box<str>>,
}
#[cfg(test)]
impl UserProfile {
pub(crate) fn new<U>(
uuid: U,
name: &str,
supporter_tier: SupporterTier,
elo: Option<Elo>,
rank: Option<Rank>,
country: Option<&str>,
) -> Self
where
U: TryInto<Uuid>,
U::Error: Debug,
{
Self {
uuid: uuid.try_into().expect("Expected a valid uuid"),
nickname: name.into(),
supporter_tier,
elo,
rank,
country: country.map(Into::into),
}
}
}
impl UserProfile {
pub fn uuid(&self) -> Uuid {
self.uuid
}
pub fn nickname(&self) -> &str {
&self.nickname
}
pub fn supporter_tier(&self) -> SupporterTier {
self.supporter_tier
}
pub fn elo(&self) -> Option<Elo> {
self.elo
}
pub fn rank(&self) -> Option<Rank> {
self.rank
}
}