use crate::client::Client;
use crate::error::ApiError;
use crate::utils::Race;
const ENDPOINT_URL: &str = "/v1/skin_details";
#[derive(Debug, Deserialize, PartialEq)]
pub struct Skin {
#[serde(rename = "skin_id")]
id: String,
name: String,
#[serde(rename = "type")]
skin_type: SkinType,
#[serde(default)]
flags: Vec<SkinFlags>,
#[serde(default)]
restrictions: Vec<Race>,
icon_file_id: String,
icon_file_signature: String,
#[serde(default)]
description: String,
}
#[derive(Debug, Deserialize, PartialEq)]
pub enum SkinType {
Armor,
Weapon,
Back,
}
#[derive(Debug, Deserialize, PartialEq)]
pub enum SkinFlags {
ShowInWardrobe,
NoCost,
HideIfLocked,
}
impl Skin {
pub fn get_id(client: &Client, id: String) -> Result<Skin, ApiError> {
let url = format!("{}?skin_id={}", ENDPOINT_URL, id);
client.request(&url)
}
pub fn id(&self) -> &str {
&self.id
}
pub fn name(&self) -> &str {
&self.name
}
pub fn skin_type(&self) -> &SkinType {
&self.skin_type
}
pub fn flags(&self) -> &Vec<SkinFlags> {
&self.flags
}
pub fn restrictions(&self) -> &Vec<Race> {
&self.restrictions
}
pub fn icon_file_id(&self) -> &str {
&self.icon_file_id
}
pub fn icon_file_signature(&self) -> &str {
&self.icon_file_signature
}
pub fn description(&self) -> &str {
&self.description
}
}
#[cfg(test)]
mod tests {
use crate::v1::skin_details::*;
use crate::client::Client;
const JSON_SKIN: &str = r#"
{
"skin_id": "1350",
"name": "Zodiac Light Vest",
"type": "Armor",
"flags": [
"ShowInWardrobe"
],
"restrictions": [],
"icon_file_id": "740312",
"icon_file_signature": "021048C317DFFFB6727E0955A2D6C7EFFBE9425B",
"armor": {
"type": "Coat",
"weight_class": "Light"
}
}"#;
#[test]
fn create_skin() {
match serde_json::from_str::<Skin>(JSON_SKIN) {
Ok(_) => assert!(true),
Err(e) => panic!(e.to_string()),
}
}
#[test]
fn get_skin() {
let client = Client::new();
let skin = serde_json::from_str::<Skin>(JSON_SKIN).unwrap();
assert_eq!(Skin::get_id(&client, "1350".to_string()).unwrap(), skin)
}
}