use serde::Deserialize;
use crate::types::utils::{bool_from_str, u32_from_str};
#[derive(Deserialize, Debug)]
struct RegisteredRaw {
#[serde(rename = "unixtime", deserialize_with = "u32_from_str")]
unixtime: u32,
}
#[derive(Deserialize, Debug)]
pub(crate) struct UserInfoResponse {
user: UserInfoRaw,
}
#[derive(Deserialize, Debug)]
struct UserInfoRaw {
name: String,
realname: String,
url: String,
country: String,
#[serde(deserialize_with = "u32_from_str")]
age: u32,
gender: String,
#[serde(deserialize_with = "bool_from_str")]
subscriber: bool,
#[serde(deserialize_with = "u32_from_str")]
playcount: u32,
#[serde(deserialize_with = "u32_from_str")]
playlists: u32,
registered: RegisteredRaw,
}
#[derive(Debug, Clone)]
#[non_exhaustive]
pub struct UserInfo {
pub name: String,
pub real_name: String,
pub url: String,
pub country: String,
pub age: u32,
pub gender: String,
pub subscriber: bool,
pub play_count: u32,
pub playlist_count: u32,
pub registered: u32,
}
impl From<UserInfoRaw> for UserInfo {
fn from(r: UserInfoRaw) -> Self {
Self {
name: r.name,
real_name: r.realname,
url: r.url,
country: r.country,
age: r.age,
gender: r.gender,
subscriber: r.subscriber,
play_count: r.playcount,
playlist_count: r.playlists,
registered: r.registered.unixtime,
}
}
}
impl From<UserInfoResponse> for UserInfo {
fn from(r: UserInfoResponse) -> Self {
Self::from(r.user)
}
}