use jiff::Timestamp;
use serde::{Deserialize, Serialize};
use url::Url;
#[non_exhaustive]
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum UserRole {
Admin,
Moderator,
Pyro,
Developer,
#[serde(other)]
Unknown,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct PayoutData {
#[serde(default)]
pub balance: Option<f64>,
#[serde(default)]
pub payout_wallet: Option<String>,
#[serde(default)]
pub payout_wallet_type: Option<String>,
#[serde(default)]
pub payout_address: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct User {
pub id: String,
pub username: String,
#[serde(default)]
pub name: Option<String>,
#[serde(default)]
pub email: Option<String>,
#[serde(default)]
pub bio: Option<String>,
#[serde(default)]
pub payout_data: Option<PayoutData>,
#[serde(default)]
pub avatar_url: Option<Url>,
pub created: Timestamp,
pub role: UserRole,
#[serde(default)]
pub badges: u32,
#[serde(default)]
pub auth_providers: Option<Vec<String>>,
#[serde(default)]
pub email_verified: Option<bool>,
#[serde(default)]
pub has_password: Option<bool>,
#[serde(default)]
pub has_totp: Option<bool>,
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
#[non_exhaustive]
#[derive(Clone, Debug, Default, Serialize, Eq, PartialEq)]
pub struct ModifyUserRequest {
#[serde(skip_serializing_if = "Option::is_none")]
pub username: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub name: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub email: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub bio: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub payout_data: Option<serde_json::Value>,
}
#[cfg(feature = "modrinth-write")]
#[cfg_attr(docsrs, doc(cfg(feature = "modrinth-write")))]
impl ModifyUserRequest {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn username(mut self, username: impl Into<String>) -> Self {
self.username = Some(username.into());
self
}
#[must_use]
pub fn name(mut self, name: impl Into<String>) -> Self {
self.name = Some(name.into());
self
}
#[must_use]
pub fn email(mut self, email: impl Into<String>) -> Self {
self.email = Some(email.into());
self
}
#[must_use]
pub fn bio(mut self, bio: impl Into<String>) -> Self {
self.bio = Some(bio.into());
self
}
#[must_use]
pub fn payout_data(mut self, payout_data: serde_json::Value) -> Self {
self.payout_data = Some(payout_data);
self
}
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct PayoutEntry {
pub created: Timestamp,
pub amount: f64,
pub status: String,
}
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
pub struct PayoutHistory {
pub all_time: String,
pub last_month: String,
#[serde(default)]
pub payouts: Vec<PayoutEntry>,
}