use crate::model::prelude::*;
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct NewsItems {
pub news: Vec<News>,
}
impl AsRef<NewsItems> for NewsItems {
fn as_ref(&self) -> &Self {
self
}
}
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct News {
#[serde(rename = "_id")]
pub id: String,
pub stream: NewsStreamModel,
pub r#type: String,
pub data: NewsData,
#[serde(rename = "ts")]
pub created_at: Timestamp,
}
impl News {
impl_for_news_created_at!();
}
impl AsRef<News> for News {
fn as_ref(&self) -> &Self {
self
}
}
#[derive(Clone, Debug, Deserialize)]
#[serde(untagged)]
#[non_exhaustive]
pub enum NewsData {
LeaderboardNews(LeaderboardNews),
PersonalBestNews(PersonalBestNews),
BadgeNews(BadgeNews),
RankUpNews(RankUpNews),
SupporterNews(SupporterNews),
SupporterGiftNews(SupporterGiftNews),
Unknown(serde_json::Value),
}
impl NewsData {
pub fn is_leaderboard_news(&self) -> bool {
matches!(self, Self::LeaderboardNews(_))
}
pub fn is_personal_best_news(&self) -> bool {
matches!(self, Self::PersonalBestNews(_))
}
pub fn is_badge_news(&self) -> bool {
matches!(self, Self::BadgeNews(_))
}
pub fn is_rank_up_news(&self) -> bool {
matches!(self, Self::RankUpNews(_))
}
pub fn is_supporter_news(&self) -> bool {
matches!(self, Self::SupporterNews(_))
}
pub fn is_supporter_gift_news(&self) -> bool {
matches!(self, Self::SupporterGiftNews(_))
}
pub fn is_unknown(&self) -> bool {
matches!(self, Self::Unknown(_))
}
}
impl AsRef<NewsData> for NewsData {
fn as_ref(&self) -> &Self {
self
}
}
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct LeaderboardNews {
pub username: String,
pub gametype: Gamemode,
pub rank: u32,
pub result: f64,
#[serde(rename = "replayid")]
pub replay_id: ReplayId,
}
impl LeaderboardNews {
impl_get_user!(username);
impl_for_username!();
impl_for_replay_id!();
}
impl AsRef<LeaderboardNews> for LeaderboardNews {
fn as_ref(&self) -> &Self {
self
}
}
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct PersonalBestNews {
pub username: String,
pub gametype: Gamemode,
pub result: f64,
#[serde(rename = "replayid")]
pub replay_id: ReplayId,
}
impl PersonalBestNews {
impl_get_user!(username);
impl_for_username!();
impl_for_replay_id!();
}
impl AsRef<PersonalBestNews> for PersonalBestNews {
fn as_ref(&self) -> &Self {
self
}
}
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct BadgeNews {
pub username: String,
#[serde(rename = "type")]
pub id: BadgeId,
pub label: String,
}
impl BadgeNews {
impl_get_user!(username);
impl_for_username!();
impl_for_id_badge_id!();
}
impl AsRef<BadgeNews> for BadgeNews {
fn as_ref(&self) -> &Self {
self
}
}
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct RankUpNews {
pub username: String,
pub rank: Rank,
}
impl RankUpNews {
impl_get_user!(username);
impl_for_username!();
}
impl AsRef<RankUpNews> for RankUpNews {
fn as_ref(&self) -> &Self {
self
}
}
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct SupporterNews {
pub username: String,
}
impl SupporterNews {
impl_get_user!(username);
impl_for_username!();
}
impl AsRef<SupporterNews> for SupporterNews {
fn as_ref(&self) -> &Self {
self
}
}
#[derive(Clone, Debug, Deserialize)]
#[non_exhaustive]
pub struct SupporterGiftNews {
pub username: String,
}
impl SupporterGiftNews {
impl_get_user!(username);
impl_for_username!();
}