use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use std::path::PathBuf;
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct VxConfig {
pub defaults: DefaultConfig,
pub tools: HashMap<String, ToolConfig>,
pub registries: HashMap<String, RegistryConfig>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct DefaultConfig {
pub auto_install: bool,
pub cache_duration: String,
pub fallback_to_builtin: bool,
pub install_dir: Option<String>,
pub use_system_path: bool,
}
impl Default for DefaultConfig {
fn default() -> Self {
Self {
auto_install: true,
cache_duration: "7d".to_string(),
fallback_to_builtin: true,
install_dir: None,
use_system_path: false,
}
}
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ToolConfig {
pub version: Option<String>,
pub install_method: Option<String>,
pub registry: Option<String>,
pub custom_sources: Option<Vec<String>>,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct RegistryConfig {
pub url: String,
pub token: Option<String>,
pub trusted: bool,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum ProjectType {
Python, Rust, Node, Go, Mixed, Unknown, }
#[derive(Debug, Clone)]
pub struct ProjectInfo {
pub project_type: ProjectType,
pub config_file: PathBuf,
pub tool_versions: HashMap<String, String>,
}
#[derive(Debug, Clone)]
pub struct ConfigStatus {
pub layers: Vec<LayerInfo>,
pub available_tools: Vec<String>,
pub fallback_enabled: bool,
pub project_info: Option<ProjectInfo>,
}
#[derive(Debug, Clone)]
pub struct LayerInfo {
pub name: String,
pub available: bool,
pub priority: i32,
}
impl ConfigStatus {
pub fn summary(&self) -> String {
let active_layers: Vec<&str> = self
.layers
.iter()
.filter(|l| l.available)
.map(|l| l.name.as_str())
.collect();
format!(
"Configuration layers: {} | Tools: {} | Fallback: {}",
active_layers.join(", "),
self.available_tools.len(),
if self.fallback_enabled {
"enabled"
} else {
"disabled"
}
)
}
pub fn is_healthy(&self) -> bool {
self.layers.iter().any(|l| l.available) && !self.available_tools.is_empty()
}
}
#[derive(Debug, Serialize, Deserialize, Default, Clone)]
pub struct ProjectConfig {
pub tools: HashMap<String, String>,
pub settings: ProjectSettings,
}
#[derive(Debug, Serialize, Deserialize, Clone)]
pub struct ProjectSettings {
pub auto_install: bool,
pub cache_duration: String,
}
impl Default for ProjectSettings {
fn default() -> Self {
Self {
auto_install: true,
cache_duration: "7d".to_string(),
}
}
}