use std::collections::BTreeMap;
use serde::{Deserialize, Serialize};
#[cfg(feature = "typescript")]
use tsify::Tsify;
use crate::fit::id_map;
#[cfg_attr(feature = "typescript", derive(Tsify))]
#[derive(Serialize, Deserialize, Debug, Clone, Default, PartialEq)]
pub struct Projection {
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub buffs: Vec<ProjectedBuff>,
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub effects: Vec<ProjectedEffect>,
}
#[cfg_attr(feature = "typescript", derive(Tsify))]
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq)]
pub struct ProjectedBuff {
pub id: i32,
pub value: f64,
}
#[cfg_attr(feature = "typescript", derive(Tsify))]
#[derive(Serialize, Deserialize, Debug, Clone, PartialEq)]
pub struct ProjectedEffect {
pub type_id: i32,
pub effect_id: i32,
#[serde(default, deserialize_with = "id_map")]
#[cfg_attr(
feature = "typescript",
tsify(type = "Map<number, number> | Record<number, number>")
)]
pub attributes: BTreeMap<i32, f64>,
}
impl Projection {
pub fn is_empty(&self) -> bool {
self.buffs.is_empty() && self.effects.is_empty()
}
pub fn extend(&mut self, other: Projection) {
self.buffs.extend(other.buffs);
self.effects.extend(other.effects);
}
}