mcapi 0.2.0

Unified async Rust client for the Minecraft ecosystem (Mojang, Modrinth, CurseForge, Yggdrasil, Blessing Skin, Loaders, Java Runtimes, and SLP)
Documentation
use serde::{Deserialize, Serialize};

/// Skin or cape model kind in Blessing Skin.
#[derive(Clone, Copy, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum TextureModel {
    #[default]
    Steve,
    Alex,
    Cape,
}

impl TextureModel {
    /// Returns the wire value (`"steve"`, `"alex"`, or `"cape"`).
    pub const fn as_str(self) -> &'static str {
        match self {
            TextureModel::Steve => "steve",
            TextureModel::Alex => "alex",
            TextureModel::Cape => "cape",
        }
    }
}

/// Filter kind for `GET /api/skinlib`.
#[derive(Clone, Copy, Debug, Default, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum SkinlibFilter {
    #[default]
    Skin,
    Steve,
    Alex,
    Cape,
}

impl SkinlibFilter {
    /// Returns the query string value.
    pub const fn as_str(self) -> &'static str {
        match self {
            SkinlibFilter::Skin => "skin",
            SkinlibFilter::Steve => "steve",
            SkinlibFilter::Alex => "alex",
            SkinlibFilter::Cape => "cape",
        }
    }
}

/// Sort mode for `GET /api/skinlib`.
#[derive(Clone, Copy, Debug, Default, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum SkinlibSort {
    #[default]
    Time,
    Likes,
}

impl SkinlibSort {
    /// Returns the query string value.
    pub const fn as_str(self) -> &'static str {
        match self {
            SkinlibSort::Time => "time",
            SkinlibSort::Likes => "likes",
        }
    }
}

/// Fluent query builder for `GET /api/skinlib`.
#[derive(Clone, Debug, Default, Serialize)]
pub struct SkinlibListQuery {
    pub filter: Option<SkinlibFilter>,
    pub sort: Option<SkinlibSort>,
    pub keyword: Option<String>,
    pub uploader: Option<u64>,
    pub page: Option<u32>,
}

impl SkinlibListQuery {
    /// Creates an empty skin library query.
    pub fn new() -> Self {
        Self::default()
    }

    /// Filters by texture type/model.
    pub fn filter(mut self, filter: SkinlibFilter) -> Self {
        self.filter = Some(filter);
        self
    }

    /// Sets the sort field (`time` or `likes`).
    pub fn sort(mut self, sort: SkinlibSort) -> Self {
        self.sort = Some(sort);
        self
    }

    /// Searches by texture title keyword.
    pub fn keyword(mut self, keyword: impl Into<String>) -> Self {
        self.keyword = Some(keyword.into());
        self
    }

    /// Filters by uploader UID.
    pub fn uploader(mut self, uid: u64) -> Self {
        self.uploader = Some(uid);
        self
    }

    /// Sets the 1-based page number.
    pub fn page(mut self, page: u32) -> Self {
        self.page = Some(page);
        self
    }
}

/// Summary texture entry in `GET /api/skinlib`.
#[derive(Clone, Debug, Deserialize, Serialize)]
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>,
}

/// Detailed texture entry returned by `GET /skinlib/info/{tid}`.
#[derive(Clone, Debug, Deserialize, Serialize)]
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>,
}

/// Multipart upload request for `POST /api/skinlib`.
#[derive(Clone, Debug)]
pub struct UploadTextureRequest {
    pub name: String,
    pub texture_type: TextureModel,
    pub public: bool,
    pub file_name: String,
    pub png_bytes: Vec<u8>,
}

/// Uploaded texture summary returned inside `POST /api/skinlib`.
#[derive(Clone, Debug, Deserialize, Serialize)]
pub struct UploadedTexture {
    pub tid: u64,
    pub name: String,
    #[serde(rename = "type")]
    pub texture_type: TextureModel,
    pub hash: String,
    pub public: bool,
}

/// Closet category filter (`"skin"` or `"cape"`).
#[derive(Clone, Copy, Debug, Default, Serialize, Eq, PartialEq)]
#[serde(rename_all = "lowercase")]
pub enum ClosetCategory {
    #[default]
    Skin,
    Cape,
}

impl ClosetCategory {
    /// Returns the query value.
    pub const fn as_str(self) -> &'static str {
        match self {
            ClosetCategory::Skin => "skin",
            ClosetCategory::Cape => "cape",
        }
    }
}

/// Texture entry stored in a user's closet (`GET /api/closet`).
#[derive(Clone, Debug, Deserialize, Serialize)]
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>,
}