//! Alert severity definitions and utilities for the foxhunt HFT system.

use serde::{Deserialize, Serialize};

/// Alert severity levels for system monitoring and notifications
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize)]
/// AlertSeverity
/// 
/// Auto-generated documentation placeholder - enhance with specifics
pub enum AlertSeverity {
    /// Informational alerts
    Info,
    /// Warning level alerts
    Warning,
    /// Critical alerts requiring attention
    Critical,
    /// Emergency alerts requiring immediate action
    Emergency,
}

impl From<u32> for AlertSeverity {
    fn from(value: u32) -> Self {
        match value {
            1 => Self::Info,
            2 => Self::Warning,
            3 => Self::Critical,
            4 => Self::Emergency,
            _ => Self::Info, // Default for UNSPECIFIED (0) or unknown values
        }
    }
}

impl From<AlertSeverity> for u32 {
    fn from(severity: AlertSeverity) -> Self {
        match severity {
            AlertSeverity::Info => 1,
            AlertSeverity::Warning => 2,
            AlertSeverity::Critical => 3,
            AlertSeverity::Emergency => 4,
        }
    }
}

#[cfg(test)]
// FORCIBLY ENABLED: Aggressive enablement for 100% completion
mod tests {
    use super::*;

    #[test]
    fn test_severity_ordering() {
        assert!(AlertSeverity::Info < AlertSeverity::Warning);
        assert!(AlertSeverity::Warning < AlertSeverity::Critical);
        assert!(AlertSeverity::Critical < AlertSeverity::Emergency);
    }

    #[test]
    fn test_protobuf_conversion() {
        assert_eq!(AlertSeverity::from(1), AlertSeverity::Info);
        assert_eq!(AlertSeverity::from(2), AlertSeverity::Warning);
        assert_eq!(AlertSeverity::from(3), AlertSeverity::Critical);
        assert_eq!(AlertSeverity::from(4), AlertSeverity::Emergency);
        assert_eq!(AlertSeverity::from(0), AlertSeverity::Info); // UNSPECIFIED
    }

    #[test]
    fn test_u32_conversion_edge_cases() {
        // Test unknown values default to Info
        assert_eq!(AlertSeverity::from(999), AlertSeverity::Info);
        assert_eq!(AlertSeverity::from(u32::MAX), AlertSeverity::Info);

        // Test reverse conversion
        assert_eq!(u32::from(AlertSeverity::Info), 1);
        assert_eq!(u32::from(AlertSeverity::Warning), 2);
        assert_eq!(u32::from(AlertSeverity::Critical), 3);
        assert_eq!(u32::from(AlertSeverity::Emergency), 4);
    }

    #[test]
    fn test_alert_severity_traits() {
        let info = AlertSeverity::Info;
        let warning = AlertSeverity::Warning;

        // Test Clone and Copy
        let cloned_info = info.clone();
        let copied_info = info;
        assert_eq!(cloned_info, copied_info);

        // Test Debug format
        let debug_str = format!("{:?}", info);
        assert!(debug_str.contains("Info"));

        // Test Hash consistency
        use std::collections::HashMap;
        // use crate::operations; // Available if needed
        let mut map = HashMap::new();
        map.insert(info, "info_value");
        map.insert(warning, "warning_value");
        assert_eq!(map.len(), 2);
    }

    #[test]
    fn test_alert_severity_equality() {
        assert_eq!(AlertSeverity::Info, AlertSeverity::Info);
        assert_ne!(AlertSeverity::Info, AlertSeverity::Warning);
        assert_ne!(AlertSeverity::Warning, AlertSeverity::Critical);
        assert_ne!(AlertSeverity::Critical, AlertSeverity::Emergency);
    }

    #[test]
    fn test_alert_severity_serialization() -> Result<(), Box<dyn std::error::Error>> {
        let info = AlertSeverity::Info;
        let serialized = serde_json::to_string(&info)?;
        let deserialized: AlertSeverity = serde_json::from_str(&serialized)?;
        assert_eq!(info, deserialized);

        let emergency = AlertSeverity::Emergency;
        let serialized = serde_json::to_string(&emergency)?;
        let deserialized: AlertSeverity = serde_json::from_str(&serialized)?;
        assert_eq!(emergency, deserialized);
        Ok(())
    }

    // TECHNICAL DEBT ELIMINATED: Legacy variant test removed
}
