//! Header serialization/deserialization tests

#[cfg(test)]
mod header_tests {
    use std::io::Cursor;
    use taco_format::{AtomMetadata, CompressionSettings, Header, SimulationMetadata};

    #[test]
    fn test_header_serialization_roundtrip() {
        // Create a header
        let sim_metadata = SimulationMetadata {
            name: Some("Test Simulation".to_string()),
            temperature: Some(300.0),
            pressure: Some(1.0),
            ensemble: Some("NPT".to_string()),
            ..Default::default()
        };

        let atom_metadata = AtomMetadata {
            names: Some(vec!["C".to_string(), "O".to_string(), "H".to_string()]),
            elements: Some(vec!["C".to_string(), "O".to_string(), "H".to_string()]),
            masses: Some(vec![12.01, 16.0, 1.008]),
            ..Default::default()
        };

        let compression_settings = CompressionSettings::default();

        let header = Header::new(3, 0.002, sim_metadata, atom_metadata, compression_settings);

        // Serialize
        let mut buffer = Cursor::new(Vec::new());
        header
            .write(&mut buffer, None)
            .expect("Failed to write header");

        // Deserialize
        buffer.set_position(0);
        let (header2, _) = Header::read(&mut buffer).expect("Failed to read header");

        // Compare
        assert_eq!(header.version, header2.version);
        assert_eq!(header.num_atoms, header2.num_atoms);
        assert_eq!(header.time_step, header2.time_step);
        assert_eq!(
            header.simulation_metadata.name,
            header2.simulation_metadata.name
        );
        assert_eq!(
            header.simulation_metadata.temperature,
            header2.simulation_metadata.temperature
        );
        assert_eq!(header.atom_metadata.names, header2.atom_metadata.names);
        assert_eq!(header.atom_metadata.masses, header2.atom_metadata.masses);
    }
}
