use serde::{Deserialize, Serialize};
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum TextureModel {
#[default]
Steve,
Alex,
Cape,
}
impl TextureModel {
#[must_use]
pub const fn as_str(self) -> &'static str {
match self {
TextureModel::Steve => "steve",
TextureModel::Alex => "alex",
TextureModel::Cape => "cape",
}
}
}
#[derive(Clone, Copy, Debug, Default, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum SkinlibFilter {
#[default]
Skin,
Steve,
Alex,
Cape,
}
#[derive(Clone, Copy, Debug, Default, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum SkinlibSort {
#[default]
Time,
Likes,
}
#[non_exhaustive]
#[derive(Clone, Debug, Default, Serialize, Eq, PartialEq)]
pub struct SkinlibQuery {
pub filter: Option<SkinlibFilter>,
pub sort: Option<SkinlibSort>,
pub keyword: Option<String>,
pub uploader: Option<u64>,
pub page: Option<u32>,
}
impl SkinlibQuery {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn filter(mut self, filter: SkinlibFilter) -> Self {
self.filter = Some(filter);
self
}
#[must_use]
pub fn sort(mut self, sort: SkinlibSort) -> Self {
self.sort = Some(sort);
self
}
#[must_use]
pub fn keyword(mut self, keyword: impl Into<String>) -> Self {
self.keyword = Some(keyword.into());
self
}
#[must_use]
pub fn uploader(mut self, uid: u64) -> Self {
self.uploader = Some(uid);
self
}
#[must_use]
pub fn page(mut self, page: u32) -> Self {
self.page = Some(page);
self
}
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct SkinlibItem {
pub tid: u64,
pub name: String,
#[serde(rename = "type")]
pub texture_type: TextureModel,
pub uploader: u64,
pub public: bool,
#[serde(default)]
pub likes: u64,
#[serde(default)]
pub hash: Option<String>,
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct TextureDetail {
pub tid: u64,
pub name: String,
#[serde(rename = "type")]
pub texture_type: TextureModel,
pub hash: String,
pub size: u64,
pub uploader: u64,
pub public: bool,
#[serde(default)]
pub likes: u64,
#[serde(default)]
pub upload_at: Option<String>,
}
#[non_exhaustive]
#[derive(Clone, Debug, Eq, PartialEq)]
pub struct UploadTextureRequest {
pub name: String,
pub texture_type: TextureModel,
pub public: bool,
pub file_name: String,
pub png_bytes: Vec<u8>,
}
impl UploadTextureRequest {
#[must_use]
pub fn new(
name: impl Into<String>,
texture_type: TextureModel,
file_name: impl Into<String>,
png_bytes: Vec<u8>,
) -> Self {
Self {
name: name.into(),
texture_type,
public: true,
file_name: file_name.into(),
png_bytes,
}
}
#[must_use]
pub fn public(mut self, public: bool) -> Self {
self.public = public;
self
}
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct UploadedTexture {
pub tid: u64,
pub name: String,
#[serde(rename = "type")]
pub texture_type: TextureModel,
pub hash: String,
pub public: bool,
}
#[derive(Clone, Copy, Debug, Deserialize, Serialize, Eq, Hash, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum TextureSlot {
Skin,
Cape,
}
#[non_exhaustive]
#[derive(Clone, Debug, Default, Serialize, Eq, PartialEq)]
pub struct ClosetQuery {
#[serde(skip_serializing_if = "Option::is_none")]
pub category: Option<ClosetCategory>,
#[serde(rename = "q", skip_serializing_if = "Option::is_none")]
pub keyword: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
pub page: Option<u32>,
}
impl ClosetQuery {
#[must_use]
pub fn new() -> Self {
Self::default()
}
#[must_use]
pub fn category(mut self, category: ClosetCategory) -> Self {
self.category = Some(category);
self
}
#[must_use]
pub fn keyword(mut self, keyword: impl Into<String>) -> Self {
self.keyword = Some(keyword.into());
self
}
#[must_use]
pub fn page(mut self, page: u32) -> Self {
self.page = Some(page);
self
}
}
#[derive(Clone, Copy, Debug, Default, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ClosetCategory {
#[default]
Skin,
Cape,
}
#[derive(Clone, Debug, Deserialize, Serialize, Eq, PartialEq)]
pub struct ClosetItem {
pub tid: u64,
pub name: String,
#[serde(rename = "type")]
pub texture_type: TextureModel,
pub hash: String,
#[serde(default)]
pub pivot: Option<serde_json::Value>,
}