use crate::core::model::ganzhi::{EarthlyBranch, HeavenlyStem};
use crate::core::model::{
bureau::FiveElementBureau,
chart::{Chart, PalaceName},
profile::{ChartAlgorithmKind, ChartPlane},
};
use serde::{Deserialize, Serialize};
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct ChartDiagnosticSnapshot {
pub algorithm: ChartAlgorithmKind,
pub chart_plane: ChartPlane,
pub palace_count: usize,
pub life_palace_branch: Option<EarthlyBranch>,
pub body_palace_branch: Option<EarthlyBranch>,
pub five_element_bureau: Option<FiveElementBureau>,
pub palaces: Vec<PalaceDiagnosticSnapshot>,
}
impl ChartDiagnosticSnapshot {
pub(crate) fn from_chart(chart: &Chart) -> Self {
let palaces = chart
.palaces()
.iter()
.map(|palace| PalaceDiagnosticSnapshot {
name: palace.name(),
branch: palace.branch(),
stem: palace.stem(),
star_count: palace.stars().len(),
decorative_star_count: palace.decorative_stars().len(),
})
.collect();
Self {
algorithm: chart.algorithm_kind(),
chart_plane: chart.chart_plane(),
palace_count: chart.palaces().len(),
life_palace_branch: chart.life_palace().map(|palace| palace.branch()),
body_palace_branch: chart.body_palace_branch(),
five_element_bureau: chart.five_element_bureau(),
palaces,
}
}
}
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
pub struct PalaceDiagnosticSnapshot {
pub name: PalaceName,
pub branch: EarthlyBranch,
pub stem: HeavenlyStem,
pub star_count: usize,
pub decorative_star_count: usize,
}