1use serde::{Deserialize, Serialize};
4use std::collections::HashMap;
5use std::path::PathBuf;
6
7#[derive(Debug, Serialize, Deserialize, Default, Clone)]
9pub struct VxConfig {
10 pub defaults: DefaultConfig,
12 pub tools: HashMap<String, ToolConfig>,
14 pub registries: HashMap<String, RegistryConfig>,
16}
17
18#[derive(Debug, Serialize, Deserialize, Clone)]
20pub struct DefaultConfig {
21 pub auto_install: bool,
23 pub cache_duration: String,
25 pub fallback_to_builtin: bool,
27 pub install_dir: Option<String>,
29 pub use_system_path: bool,
31}
32
33impl Default for DefaultConfig {
34 fn default() -> Self {
35 Self {
36 auto_install: true,
37 cache_duration: "7d".to_string(),
38 fallback_to_builtin: true,
39 install_dir: None,
40 use_system_path: false,
41 }
42 }
43}
44
45#[derive(Debug, Serialize, Deserialize, Clone)]
47pub struct ToolConfig {
48 pub version: Option<String>,
50 pub install_method: Option<String>,
52 pub registry: Option<String>,
54 pub custom_sources: Option<Vec<String>>,
56}
57
58#[derive(Debug, Serialize, Deserialize, Clone)]
60pub struct RegistryConfig {
61 pub url: String,
63 pub token: Option<String>,
65 pub trusted: bool,
67}
68
69#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
71pub enum ProjectType {
72 Python, Rust, Node, Go, Mixed, Unknown, }
79
80#[derive(Debug, Clone)]
82pub struct ProjectInfo {
83 pub project_type: ProjectType,
85 pub config_file: PathBuf,
87 pub tool_versions: HashMap<String, String>,
89}
90
91#[derive(Debug, Clone)]
93pub struct ConfigStatus {
94 pub layers: Vec<LayerInfo>,
96 pub available_tools: Vec<String>,
98 pub fallback_enabled: bool,
100 pub project_info: Option<ProjectInfo>,
102}
103
104#[derive(Debug, Clone)]
106pub struct LayerInfo {
107 pub name: String,
109 pub available: bool,
111 pub priority: i32,
113}
114
115impl ConfigStatus {
116 pub fn summary(&self) -> String {
118 let active_layers: Vec<&str> = self
119 .layers
120 .iter()
121 .filter(|l| l.available)
122 .map(|l| l.name.as_str())
123 .collect();
124
125 format!(
126 "Configuration layers: {} | Tools: {} | Fallback: {}",
127 active_layers.join(", "),
128 self.available_tools.len(),
129 if self.fallback_enabled {
130 "enabled"
131 } else {
132 "disabled"
133 }
134 )
135 }
136
137 pub fn is_healthy(&self) -> bool {
139 self.layers.iter().any(|l| l.available) && !self.available_tools.is_empty()
141 }
142}
143
144#[derive(Debug, Serialize, Deserialize, Default, Clone)]
146pub struct ProjectConfig {
147 pub tools: HashMap<String, String>,
149 pub settings: ProjectSettings,
151}
152
153#[derive(Debug, Serialize, Deserialize, Clone)]
155pub struct ProjectSettings {
156 pub auto_install: bool,
158 pub cache_duration: String,
160}
161
162impl Default for ProjectSettings {
163 fn default() -> Self {
164 Self {
165 auto_install: true,
166 cache_duration: "7d".to_string(),
167 }
168 }
169}