Skip to main content

systemprompt_models/validators/
validation_config_provider.rs

1//! Config provider wrapper for validation with all pre-loaded configs.
2
3use crate::{Config, ContentConfigRaw, ServicesConfig};
4use systemprompt_traits::ConfigProvider;
5
6#[derive(Debug, Clone, serde::Deserialize)]
7pub struct WebConfigRaw {
8    #[serde(default)]
9    pub site_name: Option<String>,
10    #[serde(default)]
11    pub base_url: Option<String>,
12    #[serde(default)]
13    pub theme: Option<String>,
14    #[serde(default)]
15    pub branding: Option<BrandingConfigRaw>,
16    #[serde(default)]
17    pub paths: Option<WebPathsConfigRaw>,
18}
19
20#[derive(Debug, Clone, serde::Deserialize)]
21pub struct WebPathsConfigRaw {
22    #[serde(default)]
23    pub templates: Option<String>,
24    #[serde(default)]
25    pub assets: Option<String>,
26}
27
28#[derive(Debug, Clone, serde::Deserialize)]
29pub struct BrandingConfigRaw {
30    #[serde(default)]
31    pub copyright: Option<String>,
32    #[serde(default)]
33    pub twitter_handle: Option<String>,
34    #[serde(default)]
35    pub display_sitename: Option<bool>,
36    #[serde(default)]
37    pub favicon: Option<String>,
38    #[serde(default)]
39    pub logo: Option<LogoConfigRaw>,
40}
41
42#[derive(Debug, Clone, serde::Deserialize)]
43pub struct LogoConfigRaw {
44    #[serde(default)]
45    pub primary: Option<LogoPrimaryRaw>,
46}
47
48#[derive(Debug, Clone, serde::Deserialize)]
49pub struct LogoPrimaryRaw {
50    #[serde(default)]
51    pub svg: Option<String>,
52}
53
54#[derive(Debug, Clone, serde::Deserialize)]
55pub struct WebMetadataRaw {
56    #[serde(default)]
57    pub title: Option<String>,
58    #[serde(default)]
59    pub description: Option<String>,
60}
61
62#[derive(Debug)]
63pub struct ValidationConfigProvider {
64    config: Config,
65    services_config: ServicesConfig,
66    content_config: Option<ContentConfigRaw>,
67    web_config: Option<WebConfigRaw>,
68    web_metadata: Option<WebMetadataRaw>,
69}
70
71impl ValidationConfigProvider {
72    pub const fn new(config: Config, services_config: ServicesConfig) -> Self {
73        Self {
74            config,
75            services_config,
76            content_config: None,
77            web_config: None,
78            web_metadata: None,
79        }
80    }
81
82    pub fn with_content_config(mut self, config: ContentConfigRaw) -> Self {
83        self.content_config = Some(config);
84        self
85    }
86
87    pub fn with_web_config(mut self, config: WebConfigRaw) -> Self {
88        self.web_config = Some(config);
89        self
90    }
91
92    pub fn with_web_metadata(mut self, metadata: WebMetadataRaw) -> Self {
93        self.web_metadata = Some(metadata);
94        self
95    }
96
97    pub const fn services_config(&self) -> &ServicesConfig {
98        &self.services_config
99    }
100
101    pub const fn config(&self) -> &Config {
102        &self.config
103    }
104
105    pub const fn content_config(&self) -> Option<&ContentConfigRaw> {
106        self.content_config.as_ref()
107    }
108
109    pub const fn web_config(&self) -> Option<&WebConfigRaw> {
110        self.web_config.as_ref()
111    }
112
113    pub const fn web_metadata(&self) -> Option<&WebMetadataRaw> {
114        self.web_metadata.as_ref()
115    }
116}
117
118impl ConfigProvider for ValidationConfigProvider {
119    fn get(&self, key: &str) -> Option<String> {
120        self.config.get(key)
121    }
122
123    fn database_url(&self) -> &str {
124        self.config.database_url()
125    }
126
127    fn system_path(&self) -> &str {
128        self.config.system_path()
129    }
130
131    fn api_port(&self) -> u16 {
132        self.config.api_port()
133    }
134
135    fn as_any(&self) -> &dyn std::any::Any {
136        self
137    }
138}