tempo_cli/models/
config.rs

1use serde::{Deserialize, Serialize};
2use std::collections::HashMap;
3
4#[derive(Debug, Clone, Serialize, Deserialize)]
5pub struct Config {
6    pub idle_timeout_minutes: u32,
7    pub auto_pause_enabled: bool,
8    pub default_context: String,
9    pub max_session_hours: u32,
10    pub backup_enabled: bool,
11    pub log_level: String,
12    #[serde(default, skip_serializing_if = "HashMap::is_empty")]
13    pub custom_settings: HashMap<String, String>,
14}
15
16impl Default for Config {
17    fn default() -> Self {
18        Self {
19            idle_timeout_minutes: 30,
20            auto_pause_enabled: true,
21            default_context: "terminal".to_string(),
22            max_session_hours: 48,
23            backup_enabled: true,
24            log_level: "info".to_string(),
25            custom_settings: HashMap::new(),
26        }
27    }
28}
29
30impl Config {
31    pub fn validate(&self) -> anyhow::Result<()> {
32        if self.idle_timeout_minutes == 0 {
33            return Err(anyhow::anyhow!("Idle timeout must be greater than 0"));
34        }
35
36        if self.max_session_hours == 0 {
37            return Err(anyhow::anyhow!("Max session hours must be greater than 0"));
38        }
39
40        let valid_contexts = ["terminal", "ide", "linked", "manual"];
41        if !valid_contexts.contains(&self.default_context.as_str()) {
42            return Err(anyhow::anyhow!(
43                "Default context must be one of: {}",
44                valid_contexts.join(", ")
45            ));
46        }
47
48        let valid_levels = ["error", "warn", "info", "debug", "trace"];
49        if !valid_levels.contains(&self.log_level.as_str()) {
50            return Err(anyhow::anyhow!(
51                "Log level must be one of: {}",
52                valid_levels.join(", ")
53            ));
54        }
55
56        Ok(())
57    }
58
59    pub fn set_custom(&mut self, key: String, value: String) {
60        self.custom_settings.insert(key, value);
61    }
62
63    pub fn get_custom(&self, key: &str) -> Option<&String> {
64        self.custom_settings.get(key)
65    }
66}