//! Bulk entity: many identical small molecules (water, solvent).

use super::atom::Atom;
use super::id::EntityId;
use super::traits::Entity;
use super::MoleculeType;

/// A group of identical small molecules (water, solvent).
#[derive(Debug, Clone)]
pub struct BulkEntity {
    /// Unique entity identifier.
    pub id: EntityId,
    /// Molecule type (Water or Solvent).
    pub mol_type: MoleculeType,
    /// Atom data for all molecules in this group.
    pub atoms: Vec<Atom>,
    /// 3-character residue code (e.g. b"HOH").
    pub residue_name: [u8; 3],
    /// Number of individual molecules in this group.
    pub molecule_count: usize,
}

impl BulkEntity {
    /// Construct from a list of atoms. `molecule_count` is supplied by
    /// the caller (typically the number of residues in the source).
    #[must_use]
    pub fn new(
        id: EntityId,
        mol_type: MoleculeType,
        atoms: Vec<Atom>,
        residue_name: [u8; 3],
        molecule_count: usize,
    ) -> Self {
        Self {
            id,
            mol_type,
            atoms,
            residue_name,
            molecule_count,
        }
    }
}

impl Entity for BulkEntity {
    fn id(&self) -> EntityId {
        self.id
    }
    fn molecule_type(&self) -> MoleculeType {
        self.mol_type
    }
    fn atoms(&self) -> &[Atom] {
        &self.atoms
    }
}
