Common/Configuration/
ConfigurationProvider.rs

1// File: Common/Source/Configuration/ConfigurationProvider.rs
2// Role: Defines the abstract service trait for configuration management.
3// Responsibilities:
4//   - Provide a contract for retrieving merged configuration values.
5//   - Provide a contract for updating configuration values at specific targets
6//     (e.g., User, Workspace).
7
8use async_trait::async_trait;
9use serde_json::Value;
10
11use super::DTO::{ConfigurationOverridesDTO::ConfigurationOverridesDTO, ConfigurationTarget::ConfigurationTarget};
12use crate::{Environment::Environment::Environment, Error::CommonError::CommonError};
13
14/// An abstract service contract for an environment component that can provide
15/// the final, merged configuration values and handle requests to update those
16/// values in their persistent storage (e.g., `settings.json` files).
17#[async_trait]
18pub trait ConfigurationProvider: Environment + Send + Sync {
19	/// Retrieves a configuration value for a given section or key, applying
20	/// specified overrides.
21	///
22	/// This method should return the final, effective value after merging all
23	/// configuration sources (e.g., default, user, workspace) in the correct
24	/// order of precedence.
25	///
26	/// # Parameters
27	///
28	/// * `Section`: An optional, dot-separated key to a specific configuration
29	///   section. If `None`, the entire configuration object should be
30	///   returned.
31	/// * `Overrides`: A DTO specifying scope overrides (e.g., for a specific
32	///   resource or language).
33	///
34	/// # Returns
35	///
36	/// A `Result` containing the requested configuration as a
37	/// `serde_json::Value`.
38	async fn GetConfigurationValue(
39		&self,
40
41		Section:Option<String>,
42
43		Overrides:ConfigurationOverridesDTO,
44	) -> Result<Value, CommonError>;
45
46	/// Updates a configuration value at a specific key and target scope.
47	///
48	/// # Parameters
49	///
50	/// * `Key`: The dot-separated configuration key to update.
51	/// * `ValueToSet`: The new `serde_json::Value` to set for the key.
52	/// * `Target`: The `ConfigurationTarget` enum specifying which scope to
53	///   write to (e.g., User, WorkSpace).
54	/// * `Overrides`: A DTO for scope overrides.
55	/// * `ScopeToLanguage`: An optional flag related to language-specific
56	///   settings.
57	async fn UpdateConfigurationValue(
58		&self,
59
60		Key:String,
61
62		ValueToSet:Value,
63
64		Target:ConfigurationTarget,
65
66		Overrides:ConfigurationOverridesDTO,
67
68		ScopeToLanguage:Option<bool>,
69	) -> Result<(), CommonError>;
70}