"""
Auto-generated residue definitions.
DO NOT EDIT - Generated by ciffy/src/codegen/generate.py from CCD.
"""

from ..utils import ResidueType, ResidueMeta
from ._generated_molecule import Molecule
from ._generated_atoms import (
    A,
    C,
    CCC,
    FHU,
    G,
    G7M,
    H2U,
    I,
    M2G,
    N,
    OMC,
    OMG,
    OMU,
    PPU,
    PSU,
    U,
    X1MG,
    X2MA,
    X2MG,
    X4SU,
    X5MC,
    X5MU,
    X6MZ,
    X7MG,
    DA,
    DC,
    DG,
    DT,
    ALA,
    ARG,
    ASN,
    ASP,
    CSO,
    CYS,
    GLN,
    GLU,
    GLY,
    HIS,
    HYP,
    ILE,
    LEU,
    LYS,
    MEQ,
    MET,
    MLY,
    MS6,
    MSE,
    OCS,
    PHE,
    PRO,
    PTR,
    SEP,
    SER,
    THR,
    TPO,
    TRP,
    TYR,
    UNK,
    VAL,
    X4D4,
    HOH,
    CS,
    K,
    MG,
    NA,
    ZN,
    ACT,
    GNG,
    GTP,
    X6O1,
)


class Residue(metaclass=ResidueMeta):
    """
    Consolidated residue definitions with nested atom access.

    Usage:
        Residue.A.value         # -> residue index
        Residue.A.C3p.value     # -> atom index
        Residue.A.molecule_type # -> Molecule.RNA
        Residue.A.bonds         # -> bond list

        list(Residue)           # -> iterate all residues
        Residue(0)              # -> lookup by index
        Residue["ALA"]          # -> lookup by name
    """

    A = ResidueType("A", 0, A, Molecule.RNA, "a")
    C = ResidueType("C", 1, C, Molecule.RNA, "c")
    CCC = ResidueType("CCC", 2, CCC, Molecule.RNA, "c")
    FHU = ResidueType("FHU", 3, FHU, Molecule.RNA, "u")
    G = ResidueType("G", 4, G, Molecule.RNA, "g")
    G7M = ResidueType("G7M", 5, G7M, Molecule.RNA, "g")
    H2U = ResidueType("H2U", 6, H2U, Molecule.RNA, "u")
    I = ResidueType("I", 7, I, Molecule.RNA, "i")
    M2G = ResidueType("M2G", 8, M2G, Molecule.RNA, "g")
    N = ResidueType("N", 9, N, Molecule.RNA, "n")
    OMC = ResidueType("OMC", 10, OMC, Molecule.RNA, "c")
    OMG = ResidueType("OMG", 11, OMG, Molecule.RNA, "g")
    OMU = ResidueType("OMU", 12, OMU, Molecule.RNA, "u")
    PPU = ResidueType("PPU", 13, PPU, Molecule.RNA, "a")
    PSU = ResidueType("PSU", 14, PSU, Molecule.RNA, "u")
    U = ResidueType("U", 15, U, Molecule.RNA, "u")
    X1MG = ResidueType("X1MG", 16, X1MG, Molecule.RNA, "g")
    X2MA = ResidueType("X2MA", 17, X2MA, Molecule.RNA, "a")
    X2MG = ResidueType("X2MG", 18, X2MG, Molecule.RNA, "g")
    X4SU = ResidueType("X4SU", 19, X4SU, Molecule.RNA, "u")
    X5MC = ResidueType("X5MC", 20, X5MC, Molecule.RNA, "c")
    X5MU = ResidueType("X5MU", 21, X5MU, Molecule.RNA, "u")
    X6MZ = ResidueType("X6MZ", 22, X6MZ, Molecule.RNA, "a")
    X7MG = ResidueType("X7MG", 23, X7MG, Molecule.RNA, "g")
    DA = ResidueType("DA", 24, DA, Molecule.DNA, "a")
    DC = ResidueType("DC", 25, DC, Molecule.DNA, "c")
    DG = ResidueType("DG", 26, DG, Molecule.DNA, "g")
    DT = ResidueType("DT", 27, DT, Molecule.DNA, "t")
    ALA = ResidueType("ALA", 28, ALA, Molecule.PROTEIN, "A")
    ARG = ResidueType("ARG", 29, ARG, Molecule.PROTEIN, "R")
    ASN = ResidueType("ASN", 30, ASN, Molecule.PROTEIN, "N")
    ASP = ResidueType("ASP", 31, ASP, Molecule.PROTEIN, "D")
    CSO = ResidueType("CSO", 32, CSO, Molecule.PROTEIN, "C")
    CYS = ResidueType("CYS", 33, CYS, Molecule.PROTEIN, "C")
    GLN = ResidueType("GLN", 34, GLN, Molecule.PROTEIN, "Q")
    GLU = ResidueType("GLU", 35, GLU, Molecule.PROTEIN, "E")
    GLY = ResidueType("GLY", 36, GLY, Molecule.PROTEIN, "G")
    HIS = ResidueType("HIS", 37, HIS, Molecule.PROTEIN, "H")
    HYP = ResidueType("HYP", 38, HYP, Molecule.PROTEIN, "P")
    ILE = ResidueType("ILE", 39, ILE, Molecule.PROTEIN, "I")
    LEU = ResidueType("LEU", 40, LEU, Molecule.PROTEIN, "L")
    LYS = ResidueType("LYS", 41, LYS, Molecule.PROTEIN, "K")
    MEQ = ResidueType("MEQ", 42, MEQ, Molecule.PROTEIN, "Q")
    MET = ResidueType("MET", 43, MET, Molecule.PROTEIN, "M")
    MLY = ResidueType("MLY", 44, MLY, Molecule.PROTEIN, "K")
    MS6 = ResidueType("MS6", 45, MS6, Molecule.PROTEIN, "~")
    MSE = ResidueType("MSE", 46, MSE, Molecule.PROTEIN, "M")
    OCS = ResidueType("OCS", 47, OCS, Molecule.PROTEIN, "C")
    PHE = ResidueType("PHE", 48, PHE, Molecule.PROTEIN, "F")
    PRO = ResidueType("PRO", 49, PRO, Molecule.PROTEIN, "P")
    PTR = ResidueType("PTR", 50, PTR, Molecule.PROTEIN, "Y")
    SEP = ResidueType("SEP", 51, SEP, Molecule.PROTEIN, "S")
    SER = ResidueType("SER", 52, SER, Molecule.PROTEIN, "S")
    THR = ResidueType("THR", 53, THR, Molecule.PROTEIN, "T")
    TPO = ResidueType("TPO", 54, TPO, Molecule.PROTEIN, "T")
    TRP = ResidueType("TRP", 55, TRP, Molecule.PROTEIN, "W")
    TYR = ResidueType("TYR", 56, TYR, Molecule.PROTEIN, "Y")
    UNK = ResidueType("UNK", 57, UNK, Molecule.PROTEIN, "X")
    VAL = ResidueType("VAL", 58, VAL, Molecule.PROTEIN, "V")
    X4D4 = ResidueType("X4D4", 59, X4D4, Molecule.PROTEIN, "~")
    HOH = ResidueType("HOH", 60, HOH, Molecule.WATER, "~")
    CS = ResidueType("CS", 61, CS, Molecule.ION, "~")
    K = ResidueType("K", 62, K, Molecule.ION, "~")
    MG = ResidueType("MG", 63, MG, Molecule.ION, "~")
    NA = ResidueType("NA", 64, NA, Molecule.ION, "~")
    ZN = ResidueType("ZN", 65, ZN, Molecule.ION, "~")
    ACT = ResidueType("ACT", 66, ACT, Molecule.LIGAND, "~")
    GNG = ResidueType("GNG", 67, GNG, Molecule.LIGAND, "~")
    GTP = ResidueType("GTP", 68, GTP, Molecule.LIGAND, "G")
    X6O1 = ResidueType("X6O1", 69, X6O1, Molecule.LIGAND, "~")

    _members: dict[str, ResidueType] = {}
    _by_index: dict[int, ResidueType] = {}


def _init_residue_class() -> None:
    """Populate lookup tables from class attributes."""
    for name in dir(Residue):
        if name.startswith("_"):
            continue
        attr = getattr(Residue, name)
        if isinstance(attr, ResidueType):
            Residue._members[name] = attr
            Residue._by_index[attr.value] = attr


_init_residue_class()


# CIF name -> Residue index (for C extension)
CIF_RESIDUE_NAMES: dict[str, int] = {
    "A": 0,
    "C": 1,
    "CCC": 2,
    "FHU": 3,
    "G": 4,
    "G7M": 5,
    "H2U": 6,
    "I": 7,
    "M2G": 8,
    "N": 9,
    "OMC": 10,
    "OMG": 11,
    "OMU": 12,
    "PPU": 13,
    "PSU": 14,
    "U": 15,
    "1MG": 16,
    "2MA": 17,
    "2MG": 18,
    "4SU": 19,
    "5MC": 20,
    "5MU": 21,
    "6MZ": 22,
    "7MG": 23,
    "DA": 24,
    "DC": 25,
    "DG": 26,
    "DT": 27,
    "ALA": 28,
    "ARG": 29,
    "ASN": 30,
    "ASP": 31,
    "CSO": 32,
    "CYS": 33,
    "GLN": 34,
    "GLU": 35,
    "GLY": 36,
    "HIS": 37,
    "HYP": 38,
    "ILE": 39,
    "LEU": 40,
    "LYS": 41,
    "MEQ": 42,
    "MET": 43,
    "MLY": 44,
    "MS6": 45,
    "MSE": 46,
    "OCS": 47,
    "PHE": 48,
    "PRO": 49,
    "PTR": 50,
    "SEP": 51,
    "SER": 52,
    "THR": 53,
    "TPO": 54,
    "TRP": 55,
    "TYR": 56,
    "UNK": 57,
    "VAL": 58,
    "4D4": 59,
    "HOH": 60,
    "CS": 61,
    "K": 62,
    "MG": 63,
    "NA": 64,
    "ZN": 65,
    "ACT": 66,
    "GNG": 67,
    "GTP": 68,
    "6O1": 69,
}

# Residue index -> CIF name (for C extension)
RESIDUE_CIF_NAMES: dict[int, str] = {
    0: "A",
    1: "C",
    2: "CCC",
    3: "FHU",
    4: "G",
    5: "G7M",
    6: "H2U",
    7: "I",
    8: "M2G",
    9: "N",
    10: "OMC",
    11: "OMG",
    12: "OMU",
    13: "PPU",
    14: "PSU",
    15: "U",
    16: "1MG",
    17: "2MA",
    18: "2MG",
    19: "4SU",
    20: "5MC",
    21: "5MU",
    22: "6MZ",
    23: "7MG",
    24: "DA",
    25: "DC",
    26: "DG",
    27: "DT",
    28: "ALA",
    29: "ARG",
    30: "ASN",
    31: "ASP",
    32: "CSO",
    33: "CYS",
    34: "GLN",
    35: "GLU",
    36: "GLY",
    37: "HIS",
    38: "HYP",
    39: "ILE",
    40: "LEU",
    41: "LYS",
    42: "MEQ",
    43: "MET",
    44: "MLY",
    45: "MS6",
    46: "MSE",
    47: "OCS",
    48: "PHE",
    49: "PRO",
    50: "PTR",
    51: "SEP",
    52: "SER",
    53: "THR",
    54: "TPO",
    55: "TRP",
    56: "TYR",
    57: "UNK",
    58: "VAL",
    59: "4D4",
    60: "HOH",
    61: "CS",
    62: "K",
    63: "MG",
    64: "NA",
    65: "ZN",
    66: "ACT",
    67: "GNG",
    68: "GTP",
    69: "6O1",
}
