//! FIX protocol message handling

use serde::{Deserialize, Serialize};
use std::collections::HashMap;

/// FIX message structure
#[derive(Debug, Clone, Serialize, Deserialize)]
/// FixMessage
///
/// Auto-generated documentation placeholder - enhance with specifics
pub struct FixMessage {
    /// Msg Type
    pub msg_type: String,
    /// Fields
    pub fields: HashMap<String, String>,
}

impl FixMessage {
    /// Create new FIX message
    pub fn new(msg_type: String) -> Self {
        Self {
            msg_type,
            fields: HashMap::new(),
        }
    }

    /// Add field to message
    pub fn add_field(&mut self, tag: String, value: String) {
        self.fields.insert(tag, value);
    }

    /// Get field value
    pub fn get_field(&self, tag: &str) -> Option<&String> {
        self.fields.get(tag)
    }
}

/// Convert FIX message to string representation
impl ToString for FixMessage {
    fn to_string(&self) -> String {
        let mut result = format!("35={}\u{0001}", self.msg_type);
        for (tag, value) in &self.fields {
            use std::fmt::Write;
            _ = write!(result, "{}={}\u{0001}", tag, value);
        }
        result
    }
}
