use serde::{Deserialize, Serialize};
use super::{
DayHorseRule, DoorPressureRule, GrowthRule, HiddenStemRule, PunishmentRule, StrengthRule,
TombRule,
};
use crate::{Branch, Cycle, Door, Element, Horse, Star, Stem};
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
pub struct ChartExtensions {
#[serde(skip_serializing_if = "Option::is_none")]
pub hidden_stems: Option<HiddenStems>,
#[serde(skip_serializing_if = "Option::is_none")]
pub strength: Option<Strengths>,
#[serde(skip_serializing_if = "Option::is_none")]
pub growth_stages: Option<GrowthStages>,
#[serde(skip_serializing_if = "Option::is_none")]
pub punishments: Option<Punishments>,
#[serde(skip_serializing_if = "Option::is_none")]
pub tombs: Option<Tombs>,
#[serde(skip_serializing_if = "Option::is_none")]
pub day_horse: Option<DayHorse>,
#[serde(skip_serializing_if = "Option::is_none")]
pub door_pressure: Option<DoorPressures>,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum StemPlate {
Heaven,
Earth,
Hidden,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct StemPlacement {
pub palace: u8,
pub plate: StemPlate,
pub stem: Stem,
pub source_palace: Option<u8>,
pub is_center_hosted: bool,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct HiddenStem {
pub palace: u8,
pub stem: Stem,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct HiddenStems {
pub rule: HiddenStemRule,
pub effective_hour_stem: Stem,
pub start_palace: u8,
pub used_center_fallback: bool,
pub palaces: [HiddenStem; 9],
}
macro_rules! states {
($(#[$meta:meta])* $name:ident { $($(#[$variant_meta:meta])* $variant:ident => $label:literal),+ $(,)? }) => {
$(#[$meta])*
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum $name { $($(#[$variant_meta])* $variant),+ }
impl $name {
#[must_use]
pub const fn name(self) -> &'static str {
match self { $(Self::$variant => $label),+ }
}
}
};
}
states! {
StarStrengthState {
Wang => "旺",
Xiang => "相",
Xiu => "休",
Qiu => "囚",
Fei => "废",
}
}
states! {
ElementStrengthState {
Wang => "旺",
Xiang => "相",
Xiu => "休",
Qiu => "囚",
Si => "死",
}
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct StarStrength {
pub star: Star,
pub element: Element,
pub at_palace: StarStrengthState,
pub at_month: StarStrengthState,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DoorStrength {
pub door: Door,
pub element: Element,
pub at_palace: ElementStrengthState,
pub at_month: ElementStrengthState,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct StemStrength {
pub placement: StemPlacement,
pub element: Element,
pub at_palace: ElementStrengthState,
pub at_month: ElementStrengthState,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct PalaceStrength {
pub palace: u8,
pub element: Element,
pub stars: Vec<StarStrength>,
pub door: Option<DoorStrength>,
pub stems: Vec<StemStrength>,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Strengths {
pub rule: StrengthRule,
pub month_branch: Branch,
pub month_element: Element,
pub palaces: Vec<PalaceStrength>,
}
states! {
GrowthStage {
ChangSheng => "长生",
MuYu => "沐浴",
GuanDai => "冠带",
LinGuan => "临官",
DiWang => "帝旺",
Shuai => "衰",
Bing => "病",
Si => "死",
Mu => "墓",
Jue => "绝",
Tai => "胎",
Yang => "养",
}
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct BranchGrowth {
pub branch: Branch,
pub stage: GrowthStage,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct StemGrowth {
pub placement: StemPlacement,
pub branches: Vec<BranchGrowth>,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct GrowthStages {
pub rule: GrowthRule,
pub stems: Vec<StemGrowth>,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct StemPunishment {
pub placement: StemPlacement,
pub hidden_jia: Option<Cycle>,
pub punished_branch: Option<Branch>,
pub is_punished: bool,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Punishments {
pub rule: PunishmentRule,
pub stems: Vec<StemPunishment>,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct StemTomb {
pub placement: StemPlacement,
pub tomb_branch: Option<Branch>,
pub is_in_tomb: Option<bool>,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct Tombs {
pub rule: TombRule,
pub stems: Vec<StemTomb>,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DayHorse {
pub rule: DayHorseRule,
pub pillar: Cycle,
pub horse: Horse,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DoorPressure {
pub palace: u8,
pub door: Door,
pub door_element: Element,
pub palace_element: Element,
pub is_pressed: bool,
}
#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
pub struct DoorPressures {
pub rule: DoorPressureRule,
pub doors: Vec<DoorPressure>,
}