Skip to main content

systemprompt_models/artifacts/dashboard/
hints.rs

1use schemars::JsonSchema;
2use serde::{Deserialize, Serialize};
3use serde_json::{json, Value as JsonValue};
4
5#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)]
6pub struct DashboardHints {
7    pub layout: LayoutMode,
8    pub refreshable: bool,
9    pub refresh_interval_seconds: Option<u32>,
10    pub drill_down_enabled: bool,
11}
12
13#[derive(Debug, Clone, Copy, Default, Serialize, Deserialize, JsonSchema)]
14#[serde(rename_all = "lowercase")]
15pub enum LayoutMode {
16    #[default]
17    Vertical,
18    Grid,
19    Tabs,
20}
21
22impl DashboardHints {
23    pub fn new() -> Self {
24        Self::default()
25    }
26
27    pub const fn with_refreshable(mut self, refreshable: bool) -> Self {
28        self.refreshable = refreshable;
29        self
30    }
31
32    pub const fn with_refresh_interval(mut self, seconds: u32) -> Self {
33        self.refresh_interval_seconds = Some(seconds);
34        self
35    }
36
37    pub const fn with_drill_down(mut self, enabled: bool) -> Self {
38        self.drill_down_enabled = enabled;
39        self
40    }
41
42    pub const fn with_layout(mut self, layout: LayoutMode) -> Self {
43        self.layout = layout;
44        self
45    }
46
47    pub fn generate_schema(&self) -> JsonValue {
48        let mut schema = json!({
49            "layout": self.layout,
50            "refreshable": self.refreshable,
51            "drill_down_enabled": self.drill_down_enabled
52        });
53
54        if let Some(interval) = self.refresh_interval_seconds {
55            schema["refresh_interval_seconds"] = json!(interval);
56        }
57
58        schema
59    }
60}