Mountain/ApplicationState/DTO/
MergedConfigurationStateDTO.rs

1//! # MergedConfigurationStateDTO
2//!
3//! Defines the Data Transfer Object for the application's final, merged
4//! configuration state.
5
6#![allow(non_snake_case, non_camel_case_types)]
7
8use serde::{Deserialize, Serialize};
9use serde_json::Value;
10
11/// Represents the final, effective configuration after merging settings from
12/// all sources (default, user, workspace, folder). This merged view is what
13/// is queried by application features.
14#[derive(Serialize, Deserialize, Clone, Debug, Default)]
15#[serde(rename_all = "PascalCase")]
16pub struct MergedConfigurationStateDTO {
17	pub Data:Value,
18}
19
20impl MergedConfigurationStateDTO {
21	/// Creates a new `MergedConfigurationStateDTO` from a `serde_json::Value`.
22	pub fn Create(Data:Value) -> Self { Self { Data } }
23
24	/// Gets a specific value from the configuration using a dot-separated path.
25	/// If the section is `None`, it returns the entire configuration object.
26	pub fn GetValue(&self, Section:Option<&str>) -> Value {
27		if let Some(Path) = Section {
28			Path.split('.')
29				.try_fold(&self.Data, |Node, Key| Node.get(Key))
30				.unwrap_or(&Value::Null)
31				.clone()
32		} else {
33			self.Data.clone()
34		}
35	}
36}