// mitochondria.sy -- Mitochondrial electron transport chain, oxidative
// phosphorylation, proton pumps, and ATP synthesis as native Scyla.
//
// The powerhouse of the cell: NADH and FADH2 from glycolysis and TCA
// cycle are oxidized through four complexes, pumping protons across the
// inner mitochondrial membrane. ATP synthase harnesses the proton gradient
// to produce ATP. ~30-32 ATP per glucose, cited.
//
// Sources:
//   Mitchell P. Nature 191:144-148, 1961 (chemiosmotic hypothesis, Nobel 1978)
//   Lehninger Principles of Biochemistry, 8th ed, 2021.
//   Hatefi Y. Annu Rev Biochem 54:1015-1069, 1985 (ETC complexes)
//   Abrahams JP et al. Nature 370:621-628, 1994 (ATP synthase structure, Nobel 1997)
//
// Marjorie McCubbins + Aether, April 2026
// Patent pending: 64/034,536

struct ETCComplex {
    complex_number: String,
    name: String,
    subunit_count: Int,
    key_subunit_accession: String,
    key_subunit_gene: String,
    electron_donor: String,
    electron_acceptor: String,
    protons_pumped: Int,
    inhibitor: String,
    disease_link: String,
    citation: String,
}

fn etc(cn: String, n: String, sc: Int, ka: String, kg: String, ed: String, ea: String, pp: Int, inh: String, dl: String, ci: String) -> ETCComplex {
    return ETCComplex { complex_number: cn, name: n, subunit_count: sc, key_subunit_accession: ka, key_subunit_gene: kg, electron_donor: ed, electron_acceptor: ea, protons_pumped: pp, inhibitor: inh, disease_link: dl, citation: ci }
}

// ═══════════════════════════════════════════════════════
// ELECTRON TRANSPORT CHAIN — the proton pumps
// ═══════════════════════════════════════════════════════

fn lookup_etc_complex(name: String) -> ETCComplex {
    if name == "I" { return etc("I", "NADH:ubiquinone oxidoreductase (NADH dehydrogenase)", 45, "P03886", "MT-ND1", "NADH", "Ubiquinone (CoQ10)", 4, "Rotenone, piericidin A, metformin (mild)", "Leigh syndrome, LHON (Leber hereditary optic neuropathy), Parkinson disease (Complex I deficiency)", "Hatefi Y. Annu Rev Biochem 54:1015-1069, 1985") }

    if name == "II" { return etc("II", "Succinate dehydrogenase (succinate:ubiquinone oxidoreductase)", 4, "P31040", "SDHA", "FADH2 (from succinate in TCA)", "Ubiquinone (CoQ10)", 0, "Malonate (competitive), carboxin", "Paraganglioma, pheochromocytoma (SDHB/C/D germline mutations)", "Lehninger 8th ed, Ch 19") }

    if name == "III" { return etc("III", "Cytochrome bc1 complex (ubiquinol:cytochrome c oxidoreductase)", 11, "P22695", "UQCRC1", "Ubiquinol (CoQH2)", "Cytochrome c", 4, "Antimycin A (Qi site), myxothiazol (Qo site)", "Exercise intolerance, cardiomyopathy", "Lehninger 8th ed, Ch 19") }

    if name == "IV" { return etc("IV", "Cytochrome c oxidase", 13, "P00395", "MT-CO1", "Cytochrome c (reduced)", "O2 (molecular oxygen → H2O)", 2, "Cyanide (CN-), carbon monoxide (CO), hydrogen sulfide (H2S)", "Cyanide poisoning (binds Fe3+ in heme a3). CO poisoning. Leigh syndrome.", "Lehninger 8th ed, Ch 19") }

    if name == "V" { return etc("V", "ATP synthase (F1Fo-ATPase)", 16, "P25705", "ATP5F1A", "Proton gradient (delta-mu H+)", "ADP + Pi → ATP", 0, "Oligomycin (blocks Fo proton channel)", "Mitochondrial disease. Oligomycin used experimentally to study oxidative phosphorylation.", "Abrahams JP et al. Nature 370:621-628, 1994 (Nobel Prize 1997)") }

    return etc("", "Unknown", 0, "", "", "", "", 0, "", "", "")
}

// ═══════════════════════════════════════════════════════
// ATP SYNTHASE — the molecular motor
// ═══════════════════════════════════════════════════════

fn atp_synthase_mechanism() -> String {
    return "F1 (matrix side): alpha3-beta3 hexamer rotary catalytic head. Gamma subunit rotates 120 degrees per ATP synthesized. 3 ATP per full rotation (360 degrees). Fo (membrane): c-ring (8-15 subunits depending on species). Proton flow through Fo drives c-ring rotation, which spins gamma in F1. Each proton drives ~1/3 of a 120-degree step. ~3.3 H+ per ATP in humans (c10 ring = 10 H+ per 3 ATP). Cited: Boyer PD. Annu Rev Biochem 66:717-749, 1997 (binding change mechanism, Nobel 1997)."
}

fn atp_per_glucose() -> String {
    return "Glycolysis: 2 ATP (net) + 2 NADH. Pyruvate dehydrogenase: 2 NADH. TCA cycle: 2 GTP + 6 NADH + 2 FADH2. ETC: each NADH -> ~2.5 ATP (Complex I->III->IV = 10 H+ pumped, ~3.3 H+/ATP). Each FADH2 -> ~1.5 ATP (Complex II->III->IV = 6 H+ pumped). Total: 10 NADH x 2.5 = 25 ATP + 2 FADH2 x 1.5 = 3 ATP + 2 ATP (glycolysis) + 2 GTP (TCA) = ~30-32 ATP per glucose. Cited: Lehninger 8th ed, Ch 19."
}

// ═══════════════════════════════════════════════════════
// TCA CYCLE (Citric Acid Cycle / Krebs Cycle)
// ═══════════════════════════════════════════════════════

fn tca_enzyme(step: Int) -> String {
    if step == 1 { return "Citrate synthase (O75390, CS): Acetyl-CoA + Oxaloacetate -> Citrate + CoA. Committed step. Inhibited by ATP, NADH, citrate." }
    if step == 2 { return "Aconitase (Q99798, ACO2): Citrate -> Isocitrate. Iron-sulfur cluster enzyme. Inactivated by ROS (oxidative stress sensor)." }
    if step == 3 { return "Isocitrate dehydrogenase (P48735, IDH2): Isocitrate -> alpha-Ketoglutarate + CO2 + NADH. KEY regulatory step. Activated by ADP. Inhibited by ATP, NADH. IDH1/2 mutations in glioma and AML produce 2-HG oncometabolite." }
    if step == 4 { return "alpha-Ketoglutarate dehydrogenase (Q02218, OGDH): alpha-KG -> Succinyl-CoA + CO2 + NADH. Rate-limiting. Inhibited by NADH, succinyl-CoA. Thiamine (B1) dependent." }
    if step == 5 { return "Succinyl-CoA synthetase (P53597, SUCLG1): Succinyl-CoA -> Succinate + GTP + CoA. Substrate-level phosphorylation (GTP)." }
    if step == 6 { return "Succinate dehydrogenase (P31040, SDHA): Succinate -> Fumarate + FADH2. Also Complex II of ETC. Links TCA to oxidative phosphorylation. Tumor suppressor." }
    if step == 7 { return "Fumarase (P07954, FH): Fumarate -> Malate. Also a tumor suppressor (fumarase-deficient renal cell carcinoma)." }
    if step == 8 { return "Malate dehydrogenase (P40926, MDH2): Malate -> Oxaloacetate + NADH. Regenerates oxaloacetate to accept next acetyl-CoA. Thermodynamically unfavorable (driven by citrate synthase pulling product)." }
    return ""
}

fn tca_per_acetyl_coa() -> String {
    // Per Acetyl-CoA entering the cycle:
    return "3 NADH + 1 FADH2 + 1 GTP + 2 CO2 released"
}

fn tca_step_count() -> Int {
    return 8
}

fn etc_complex_count() -> Int {
    return 5
}

// ═══════════════════════════════════════════════════════
// UNCOUPLING AND THERMOGENESIS
// ═══════════════════════════════════════════════════════

fn uncoupling_protein(name: String) -> String {
    if name == "UCP1" { return "P25874 | UCP1 | Brown adipose tissue. Dissipates proton gradient as heat instead of ATP. Non-shivering thermogenesis. Activated by fatty acids. Newborns and hibernating animals. Recently found in adult humans (supraclavicular brown fat). Cited: Cannon B, Nedergaard J. Physiol Rev 84:277-359, 2004." }
    if name == "UCP2" { return "P55851 | UCP2 | Widely expressed. Reduces ROS production by mild uncoupling. Regulates insulin secretion in beta cells. Linked to type 2 diabetes risk." }
    if name == "UCP3" { return "P55916 | UCP3 | Skeletal muscle. Fatty acid oxidation. Reduces ROS during high-fat diet." }
    return ""
}
