"""
Molecule type enumeration.

Based on PDB/mmCIF entity types from wwPDB:
- _entity.type: polymer, non-polymer, water, branched
- _entity_poly.type: polypeptide(L/D), polyribonucleotide, etc.

See: https://mmcif.wwpdb.org/dictionaries/mmcif_pdbx_v50.dic/Items/_entity_poly.type.html

AUTO-GENERATED by ciffy/src/codegen/generate.py - DO NOT EDIT MANUALLY.
"""

from enum import Enum


class Molecule(Enum):
    """
    Types of molecules that can appear in a structure.

    Used to classify chains by their molecular type, enabling
    filtering and type-specific operations.
    """

    PROTEIN = 0  # Standard L-amino acid chains
    RNA = 1  # Ribonucleic acid
    DNA = 2  # Deoxyribonucleic acid
    HYBRID = 3  # DNA/RNA hybrid
    PROTEIN_D = 4  # D-amino acid chains (rare)
    POLYSACCHARIDE = 5  # Carbohydrates
    PNA = 6  # Peptide nucleic acid (synthetic)
    CYCLIC_PEPTIDE = 7  # Cyclic peptides
    LIGAND = 8  # Small molecules, cofactors, drugs
    ION = 9  # Metal ions (Mg2+, Ca2+, Zn2+, etc.)
    WATER = 10  # Water molecules (HOH)
    OTHER = 11  # Unclassified polymer type
    UNKNOWN = 12  # Residue type not recognized


def molecule_type(value: int) -> Molecule:
    """
    Convert an integer value to the corresponding Molecule type.

    Args:
        value: Integer representing molecule type.

    Returns:
        The corresponding Molecule enum value.

    Raises:
        ValueError: If value doesn't correspond to a known molecule type.
    """
    try:
        return Molecule(value)
    except ValueError as e:
        raise ValueError(f"Unknown molecule type value: {value}") from e
