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