// glycolysis.sy -- Glycolysis, gluconeogenesis, and the insulin signaling
// pathway as native Scyla.
//
// The complete 10-step glycolytic pathway, ATP yield, key regulatory
// enzymes, and how insulin triggers glucose uptake via GLUT4.
//
// Sources:
//   Lehninger Principles of Biochemistry, 8th ed, 2021.
//   Saltiel AR, Kahn CR. Nature 414:799-806, 2001 (insulin signaling)
//   Huang S, Czech MP. Cell Metab 5:237-252, 2007 (GLUT4 translocation)
//
// Marjorie McCubbins + Aether, April 2026
// Patent pending: 64/034,536

struct GlycolysisStep {
    step_number: Int,
    enzyme_name: String,
    enzyme_accession: String,
    enzyme_gene: String,
    substrate: String,
    product: String,
    atp_change: Int,
    reversible: Bool,
    regulatory: Bool,
    regulation_note: String,
    citation: String,
}

struct InsulinPathwayStep {
    step_number: Int,
    component: String,
    accession: String,
    gene: String,
    action: String,
    citation: String,
}

fn gstep(sn: Int, en: String, ea: String, eg: String, su: String, pr: String, at: Int, re: Bool, rg: Bool, rn: String, ci: String) -> GlycolysisStep {
    return GlycolysisStep { step_number: sn, enzyme_name: en, enzyme_accession: ea, enzyme_gene: eg, substrate: su, product: pr, atp_change: at, reversible: re, regulatory: rg, regulation_note: rn, citation: ci }
}

fn istep(sn: Int, co: String, ac: String, ge: String, act: String, ci: String) -> InsulinPathwayStep {
    return InsulinPathwayStep { step_number: sn, component: co, accession: ac, gene: ge, action: act, citation: ci }
}

// ═══════════════════════════════════════════════════════
// THE 10 STEPS OF GLYCOLYSIS
// ═══════════════════════════════════════════════════════
// Net: Glucose + 2 NAD+ + 2 ADP + 2 Pi → 2 Pyruvate + 2 NADH + 2 ATP + 2 H2O

fn glycolysis_step(step: Int) -> GlycolysisStep {
    if step == 1 { return gstep(1, "Hexokinase", "P19367", "HK1", "Glucose", "Glucose-6-phosphate", -1, false, true, "Inhibited by G6P (product inhibition). Traps glucose in cell.", "Lehninger 8th ed, Ch 14") }
    if step == 2 { return gstep(2, "Phosphoglucose isomerase", "P06744", "GPI", "Glucose-6-phosphate", "Fructose-6-phosphate", 0, true, false, "", "Lehninger 8th ed") }
    if step == 3 { return gstep(3, "Phosphofructokinase-1", "P17858", "PFKM", "Fructose-6-phosphate", "Fructose-1,6-bisphosphate", -1, false, true, "THE committed step. Activated by AMP, fructose-2,6-bisP. Inhibited by ATP, citrate. Most important regulatory point.", "Lehninger 8th ed, Ch 14") }
    if step == 4 { return gstep(4, "Aldolase A", "P04075", "ALDOA", "Fructose-1,6-bisphosphate", "DHAP + Glyceraldehyde-3-P", 0, true, false, "", "Lehninger 8th ed") }
    if step == 5 { return gstep(5, "Triose phosphate isomerase", "P60174", "TPI1", "DHAP", "Glyceraldehyde-3-phosphate", 0, true, false, "Catalytically perfect enzyme (diffusion-limited).", "Lehninger 8th ed") }
    if step == 6 { return gstep(6, "Glyceraldehyde-3-P dehydrogenase", "P04406", "GAPDH", "Glyceraldehyde-3-P + NAD+ + Pi", "1,3-Bisphosphoglycerate + NADH", 0, true, false, "Oxidation step. NADH produced. Also moonlights in apoptosis and membrane trafficking.", "Lehninger 8th ed") }
    if step == 7 { return gstep(7, "Phosphoglycerate kinase", "P00558", "PGK1", "1,3-Bisphosphoglycerate + ADP", "3-Phosphoglycerate + ATP", 1, true, false, "First substrate-level phosphorylation. 2 ATP produced (x2 trioses).", "Lehninger 8th ed") }
    if step == 8 { return gstep(8, "Phosphoglycerate mutase", "P18669", "PGAM1", "3-Phosphoglycerate", "2-Phosphoglycerate", 0, true, false, "", "Lehninger 8th ed") }
    if step == 9 { return gstep(9, "Enolase", "P06733", "ENO1", "2-Phosphoglycerate", "Phosphoenolpyruvate (PEP) + H2O", 0, true, false, "Dehydration creates high-energy phosphate bond on PEP.", "Lehninger 8th ed") }
    if step == 10 { return gstep(10, "Pyruvate kinase", "P14618", "PKM", "PEP + ADP", "Pyruvate + ATP", 1, false, true, "Second substrate-level phosphorylation. 2 ATP produced (x2). Activated by fructose-1,6-bisP (feedforward). Inhibited by ATP, alanine.", "Lehninger 8th ed, Ch 14") }
    return gstep(0, "", "", "", "", "", 0, false, false, "", "")
}

fn glycolysis_net_atp() -> Int {
    // 2 ATP consumed (steps 1+3), 4 ATP produced (steps 7+10 x2) = net 2 ATP
    return 2
}

fn glycolysis_net_nadh() -> Int {
    return 2
}

// ═══════════════════════════════════════════════════════
// INSULIN SIGNALING — how insulin gets glucose into cells
// ═══════════════════════════════════════════════════════

fn insulin_pathway_step(step: Int) -> InsulinPathwayStep {
    if step == 1 { return istep(1, "Insulin", "P01308", "INS", "Secreted by pancreatic beta cells when blood glucose rises above ~5.6 mM. Circulates as monomer. Half-life ~5 min.", "Saltiel AR, Kahn CR. Nature 414:799-806, 2001") }
    if step == 2 { return istep(2, "Insulin receptor (IR)", "P06213", "INSR", "Insulin binds alpha subunit of IR (receptor tyrosine kinase). Induces conformational change. Beta subunit autophosphorylates on tyrosine residues.", "Saltiel 2001") }
    if step == 3 { return istep(3, "IRS-1 (Insulin receptor substrate 1)", "P35568", "IRS1", "IR phosphorylates IRS-1 on multiple tyrosines. IRS-1 becomes a docking platform for SH2-domain proteins including PI3K.", "Saltiel 2001") }
    if step == 4 { return istep(4, "PI3K (Phosphoinositide 3-kinase)", "P42336", "PIK3CA", "Recruited to phospho-IRS-1 via SH2 domain. Phosphorylates PIP2 to PIP3 in the membrane. PIP3 is the key second messenger.", "Saltiel 2001") }
    if step == 5 { return istep(5, "AKT (Protein kinase B)", "P31749", "AKT1", "PIP3 recruits AKT to membrane via PH domain. PDK1 phosphorylates AKT Thr308. mTORC2 phosphorylates Ser473. Fully active AKT.", "Saltiel 2001") }
    if step == 6 { return istep(6, "AS160 (TBC1D4)", "O60343", "TBC1D4", "AKT phosphorylates AS160, inactivating its GAP activity. RAB proteins remain GTP-bound (active). Vesicle trafficking enabled.", "Huang S, Czech MP. Cell Metab 5:237-252, 2007") }
    if step == 7 { return istep(7, "GLUT4 (Glucose transporter type 4)", "P14672", "SLC2A4", "GLUT4 storage vesicles (GSVs) translocate to plasma membrane. GLUT4 inserts into membrane. Glucose floods into the cell down its concentration gradient. No ATP required for transport.", "Huang 2007") }
    if step == 8 { return istep(8, "Hexokinase (glucose trapping)", "P19367", "HK1", "Once inside, hexokinase immediately phosphorylates glucose to glucose-6-phosphate, trapping it in the cell and maintaining the inward concentration gradient. Enters glycolysis.", "Lehninger 8th ed") }
    return istep(0, "", "", "", "", "")
}

fn insulin_pathway_step_count() -> Int {
    return 8
}

fn glycolysis_step_count() -> Int {
    return 10
}

// ═══════════════════════════════════════════════════════
// PYRUVATE FATE — what happens after glycolysis
// ═══════════════════════════════════════════════════════

fn pyruvate_fate(condition: String) -> String {
    if condition == "aerobic" { return "Pyruvate enters mitochondria via MPC (P53007). Pyruvate dehydrogenase (PDH, P08559) converts to Acetyl-CoA + CO2 + NADH. Acetyl-CoA enters TCA cycle. Full oxidation yields ~30-32 ATP per glucose." }
    if condition == "anaerobic" { return "Lactate dehydrogenase (LDH, P00338) converts pyruvate to lactate, regenerating NAD+ for glycolysis to continue. Net 2 ATP per glucose. Lactate exported to liver (Cori cycle)." }
    if condition == "fermentation" { return "Yeast: pyruvate decarboxylase converts to acetaldehyde + CO2. Alcohol dehydrogenase converts to ethanol, regenerating NAD+. Net 2 ATP per glucose." }
    if condition == "cancer" { return "Warburg effect: cancer cells preferentially use glycolysis even in presence of oxygen (aerobic glycolysis). High glucose uptake, high lactate production. PET imaging exploits this (FDG uptake). Warburg O. Science 123:309-314, 1956." }
    return ""
}

// ═══════════════════════════════════════════════════════
// GLUCOSE TRANSPORTERS
// ═══════════════════════════════════════════════════════

fn glucose_transporter(name: String) -> String {
    if name == "GLUT1" { return "P11166 | SLC2A1 | Basal glucose uptake in all cells. RBCs, brain endothelium. Km ~1 mM (always saturated). Constitutive." }
    if name == "GLUT2" { return "P11168 | SLC2A2 | Liver, pancreatic beta cells, intestine. Km ~17 mM (glucose sensor). Low affinity allows proportional uptake." }
    if name == "GLUT3" { return "P11169 | SLC2A3 | Neurons. Km ~1.4 mM. High affinity ensures brain gets glucose even at low blood levels." }
    if name == "GLUT4" { return "P14672 | SLC2A4 | Muscle, adipose. INSULIN-RESPONSIVE. Sequestered in GSVs. Translocates to membrane on insulin signal. THE regulated transporter." }
    if name == "GLUT5" { return "P22732 | SLC2A5 | Intestine. Fructose transporter. Km ~6 mM for fructose." }
    return ""
}
