use std::fmt;
use std::ops::Deref;
use super::item::Item;
use super::label::Label;
use super::league::League;
use super::price::Price;
pub struct Stash {
pub id: String,
pub league: League,
pub label: Label,
pub type_: StashType,
pub account: String,
pub last_character: Option<String>,
pub items: Vec<StashedItem>,
}
impl fmt::Debug for Stash {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("Stash")
.field("id", &self.id)
.field("league", &self.league)
.field("label", &self.label)
.field("type", &self.type_)
.field("account", &self.account)
.field("last_character", &self.last_character)
.field("items", &self.items)
.finish()
}
}
#[derive(Debug, Deserialize)]
pub enum StashType {
#[serde(rename = "NormalStash")]
Normal,
#[serde(rename = "PremiumStash")]
Premium,
#[serde(rename = "QuadStash")]
Quad,
#[serde(rename = "EssenceStash")]
Essence,
#[serde(rename = "CurrencyStash")]
Currency,
#[serde(rename = "DivinationCardStash")]
Divination,
#[serde(rename = "MapStash")] Map,
#[serde(rename = "FragmentStash")] Fragment,
}
#[derive(Debug)]
pub struct StashedItem {
pub(super) item: Item,
pub(super) label: Option<Label>,
pub(super) x: u64,
pub(super) y: u64,
pub(super) width: u64,
pub(super) height: u64,
}
impl Deref for StashedItem {
type Target = Item;
fn deref(&self) -> &Self::Target {
&self.item
}
}
impl StashedItem {
#[inline]
pub fn item(&self) -> &Item { &self.item }
#[inline]
pub fn label(&self) -> Option<&Label> {
self.label.as_ref()
}
pub fn note(&self) -> Option<&str> {
self.label().and_then(|l| l.note())
}
pub fn exact_price(&self) -> Option<&Price> {
self.label().and_then(|l| l.exact_price())
}
pub fn negotiable_price(&self) -> Option<&Price> {
self.label().and_then(|l| l.negotiable_price())
}
#[inline]
pub fn position(&self) -> (u64, u64) {
(self.x, self.y)
}
#[inline]
pub fn x(&self) -> u64 { self.x }
#[inline]
pub fn y(&self) -> u64 { self.y }
#[inline]
pub fn size(&self) -> (u64, u64) {
(self.width, self.height)
}
#[inline]
pub fn width(&self) -> u64 { self.width }
#[inline]
pub fn height(&self) -> u64 { self.height }
}