//! Component catalog types
//!
//! Data types for component catalog system.

use serde::{Deserialize, Serialize};

/// Type of component
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
#[serde(rename_all = "lowercase")]
pub enum ComponentType {
    Driver,
    Package,
    Behavior,
    Stack,
}

impl std::fmt::Display for ComponentType {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ComponentType::Driver => write!(f, "driver"),
            ComponentType::Package => write!(f, "package"),
            ComponentType::Behavior => write!(f, "behavior"),
            ComponentType::Stack => write!(f, "stack"),
        }
    }
}

/// A component that can be added to a project
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Component {
    pub id: String,
    pub name: String,
    pub description: String,
    pub component_type: ComponentType,
    pub version: String,
    pub category: String,
    pub tags: Vec<String>,

    /// Cargo dependencies to add
    pub cargo_dependencies: Vec<CargoDependency>,

    /// Files to generate
    pub files: Vec<FileTemplate>,

    /// Configuration to add to mecha10.json
    pub mecha10_config: Mecha10Config,
}

/// A Cargo dependency specification
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CargoDependency {
    pub name: String,
    pub version: Option<String>,
    pub path: Option<String>,
    pub features: Vec<String>,
    pub optional: bool,
}

/// File template to generate
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FileTemplate {
    pub path: String,
    pub content: String,
}

/// Configuration to add to mecha10.json
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct Mecha10Config {
    /// Driver configuration (if applicable)
    pub driver: Option<DriverConfig>,

    /// Custom node configuration (if applicable)
    pub custom_node: Option<CustomNodeConfig>,

    /// Behavior configuration (if applicable)
    pub behavior: Option<String>,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DriverConfig {
    pub name: String,
    pub path: String,
    pub description: String,
    pub run_target: String,
    pub enabled: bool,
}

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CustomNodeConfig {
    pub name: String,
    pub path: String,
    pub config: Option<String>,
    pub description: String,
    pub run_target: String,
    pub enabled: bool,
}
