use serde::Deserialize;
use orrery_core::{color::Color, semantic::LayoutEngine};
#[derive(Debug, Clone, Default, Deserialize)]
pub struct AppConfig {
#[serde(default)]
layout: LayoutConfig,
#[serde(default)]
style: StyleConfig,
}
impl AppConfig {
pub fn new(layout: LayoutConfig, style: StyleConfig) -> Self {
Self { layout, style }
}
pub fn layout(&self) -> &LayoutConfig {
&self.layout
}
pub fn style(&self) -> &StyleConfig {
&self.style
}
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct LayoutConfig {
#[serde(default)]
component: LayoutEngine,
#[serde(default)]
sequence: LayoutEngine,
}
impl LayoutConfig {
pub fn new(component: LayoutEngine, sequence: LayoutEngine) -> Self {
Self {
component,
sequence,
}
}
pub fn component(&self) -> LayoutEngine {
self.component
}
pub fn sequence(&self) -> LayoutEngine {
self.sequence
}
}
#[derive(Debug, Default, Clone, Deserialize)]
pub struct StyleConfig {
#[serde(default)]
background_color: Option<String>,
}
impl StyleConfig {
pub fn background_color(&self) -> Result<Option<Color>, String> {
self.background_color
.as_ref()
.map(|color| Color::new(color))
.transpose()
.map_err(|err| format!("Invalid background color in config: {err}"))
}
}