//! Type definition templates

use crate::utils::to_pascal_case;

/// Generate message type template
pub fn message_type(name: &str) -> String {
    format!(
        r#"//! {} Message Type
//!
//! Auto-generated message definition.

use serde::{{Deserialize, Serialize}};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct {} {{
    pub timestamp: f64,
    // TODO: Add message fields
}}

impl {} {{
    pub fn new() -> Self {{
        Self {{
            timestamp: std::time::SystemTime::now()
                .duration_since(std::time::UNIX_EPOCH)
                .unwrap()
                .as_secs_f64(),
        }}
    }}
}}

impl Default for {} {{
    fn default() -> Self {{
        Self::new()
    }}
}}
"#,
        name,
        to_pascal_case(name),
        to_pascal_case(name),
        to_pascal_case(name)
    )
}

/// Generate event type template
pub fn event_type(name: &str) -> String {
    format!(
        r#"//! {} Event Type
//!
//! Auto-generated event definition.

use serde::{{Deserialize, Serialize}};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct {} {{
    pub timestamp: f64,
    pub event_type: String,
    // TODO: Add event fields
}}

impl {} {{
    pub fn new(event_type: impl Into<String>) -> Self {{
        Self {{
            timestamp: std::time::SystemTime::now()
                .duration_since(std::time::UNIX_EPOCH)
                .unwrap()
                .as_secs_f64(),
            event_type: event_type.into(),
        }}
    }}
}}
"#,
        name,
        to_pascal_case(name),
        to_pascal_case(name)
    )
}

/// Generate state type template
pub fn state_type(name: &str) -> String {
    format!(
        r#"//! {} State Type
//!
//! Auto-generated state definition.

use serde::{{Deserialize, Serialize}};

#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct {} {{
    pub timestamp: f64,
    // TODO: Add state fields
}}

impl {} {{
    pub fn new() -> Self {{
        Self {{
            timestamp: std::time::SystemTime::now()
                .duration_since(std::time::UNIX_EPOCH)
                .unwrap()
                .as_secs_f64(),
        }}
    }}
}}

impl Default for {} {{
    fn default() -> Self {{
        Self::new()
    }}
}}
"#,
        name,
        to_pascal_case(name),
        to_pascal_case(name),
        to_pascal_case(name)
    )
}
