1use serde::{Deserialize, Serialize};
2
3use super::{
4 DayHorseRule, DoorPressureRule, GrowthRule, HiddenStemRule, PunishmentRule, StrengthRule,
5 TombRule,
6};
7use crate::{Branch, Cycle, Door, Element, Horse, Star, Stem};
8
9#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
11#[derive(Debug, Clone, Default, PartialEq, Eq, Serialize, Deserialize)]
12pub struct ChartExtensions {
13 #[serde(skip_serializing_if = "Option::is_none")]
15 pub hidden_stems: Option<HiddenStems>,
16 #[serde(skip_serializing_if = "Option::is_none")]
18 pub strength: Option<Strengths>,
19 #[serde(skip_serializing_if = "Option::is_none")]
21 pub growth_stages: Option<GrowthStages>,
22 #[serde(skip_serializing_if = "Option::is_none")]
24 pub punishments: Option<Punishments>,
25 #[serde(skip_serializing_if = "Option::is_none")]
27 pub tombs: Option<Tombs>,
28 #[serde(skip_serializing_if = "Option::is_none")]
30 pub day_horse: Option<DayHorse>,
31 #[serde(skip_serializing_if = "Option::is_none")]
33 pub door_pressure: Option<DoorPressures>,
34}
35
36#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
38#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
39#[serde(rename_all = "snake_case")]
40pub enum StemPlate {
41 Heaven,
43 Earth,
45 Hidden,
47}
48
49#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
51#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
52pub struct StemPlacement {
53 pub palace: u8,
55 pub plate: StemPlate,
57 pub stem: Stem,
59 pub source_palace: Option<u8>,
61 pub is_center_hosted: bool,
63}
64
65#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
67#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
68pub struct HiddenStem {
69 pub palace: u8,
71 pub stem: Stem,
73}
74
75#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
77#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
78pub struct HiddenStems {
79 pub rule: HiddenStemRule,
81 pub effective_hour_stem: Stem,
83 pub start_palace: u8,
85 pub used_center_fallback: bool,
87 pub palaces: [HiddenStem; 9],
89}
90
91macro_rules! states {
92 ($(#[$meta:meta])* $name:ident { $($(#[$variant_meta:meta])* $variant:ident => $label:literal),+ $(,)? }) => {
93 $(#[$meta])*
94 #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
95 #[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
96 #[serde(rename_all = "snake_case")]
97 pub enum $name { $($(#[$variant_meta])* $variant),+ }
98
99 impl $name {
100 #[must_use]
102 pub const fn name(self) -> &'static str {
103 match self { $(Self::$variant => $label),+ }
104 }
105 }
106 };
107}
108
109states! {
110 StarStrengthState {
112 Wang => "旺",
114 Xiang => "相",
116 Xiu => "休",
118 Qiu => "囚",
120 Fei => "废",
122 }
123}
124
125states! {
126 ElementStrengthState {
128 Wang => "旺",
130 Xiang => "相",
132 Xiu => "休",
134 Qiu => "囚",
136 Si => "死",
138 }
139}
140
141#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
143#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
144pub struct StarStrength {
145 pub star: Star,
147 pub element: Element,
149 pub at_palace: StarStrengthState,
151 pub at_month: StarStrengthState,
153}
154
155#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
157#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
158pub struct DoorStrength {
159 pub door: Door,
161 pub element: Element,
163 pub at_palace: ElementStrengthState,
165 pub at_month: ElementStrengthState,
167}
168
169#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
171#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
172pub struct StemStrength {
173 pub placement: StemPlacement,
175 pub element: Element,
177 pub at_palace: ElementStrengthState,
179 pub at_month: ElementStrengthState,
181}
182
183#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
185#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
186pub struct PalaceStrength {
187 pub palace: u8,
189 pub element: Element,
191 pub stars: Vec<StarStrength>,
193 pub door: Option<DoorStrength>,
195 pub stems: Vec<StemStrength>,
197}
198
199#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
201#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
202pub struct Strengths {
203 pub rule: StrengthRule,
205 pub month_branch: Branch,
207 pub month_element: Element,
210 pub palaces: Vec<PalaceStrength>,
212}
213
214states! {
215 GrowthStage {
217 ChangSheng => "长生",
219 MuYu => "沐浴",
221 GuanDai => "冠带",
223 LinGuan => "临官",
225 DiWang => "帝旺",
227 Shuai => "衰",
229 Bing => "病",
231 Si => "死",
233 Mu => "墓",
235 Jue => "绝",
237 Tai => "胎",
239 Yang => "养",
241 }
242}
243
244#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
246#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
247pub struct BranchGrowth {
248 pub branch: Branch,
250 pub stage: GrowthStage,
252}
253
254#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
256#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
257pub struct StemGrowth {
258 pub placement: StemPlacement,
260 pub branches: Vec<BranchGrowth>,
262}
263
264#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
266#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
267pub struct GrowthStages {
268 pub rule: GrowthRule,
270 pub stems: Vec<StemGrowth>,
272}
273
274#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
276#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
277pub struct StemPunishment {
278 pub placement: StemPlacement,
280 pub hidden_jia: Option<Cycle>,
282 pub punished_branch: Option<Branch>,
284 pub is_punished: bool,
286}
287
288#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
290#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
291pub struct Punishments {
292 pub rule: PunishmentRule,
294 pub stems: Vec<StemPunishment>,
296}
297
298#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
300#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
301pub struct StemTomb {
302 pub placement: StemPlacement,
304 pub tomb_branch: Option<Branch>,
307 pub is_in_tomb: Option<bool>,
309}
310
311#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
313#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
314pub struct Tombs {
315 pub rule: TombRule,
317 pub stems: Vec<StemTomb>,
319}
320
321#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
323#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
324pub struct DayHorse {
325 pub rule: DayHorseRule,
327 pub pillar: Cycle,
329 pub horse: Horse,
331}
332
333#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
335#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
336pub struct DoorPressure {
337 pub palace: u8,
339 pub door: Door,
341 pub door_element: Element,
343 pub palace_element: Element,
345 pub is_pressed: bool,
347}
348
349#[cfg_attr(feature = "schema", derive(schemars::JsonSchema))]
351#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize)]
352pub struct DoorPressures {
353 pub rule: DoorPressureRule,
355 pub doors: Vec<DoorPressure>,
357}