// dna_replication.sy -- DNA helicase unzipping, replication fork, and repair.
//
// The molecular machinery that unzips the double helix, copies it,
// and proofreads the result. Every enzyme cited to its UniProt accession.
//
// Sources:
//   Alberts B et al. Molecular Biology of the Cell, 7th ed, 2022.
//   Kornberg A, Baker TA. DNA Replication, 2nd ed, 1992.
//   Lehninger Principles of Biochemistry, 8th ed, 2021.
//
// Marjorie McCubbins + Aether, April 2026
// Patent pending: 64/034,536

struct ReplicationProtein {
    accession: String,
    gene: String,
    name: String,
    role: String,
    location: String,
    citation: String,
}

fn rprot(a: String, g: String, n: String, r: String, l: String, ci: String) -> ReplicationProtein {
    return ReplicationProtein { accession: a, gene: g, name: n, role: r, location: l, citation: ci }
}

fn replication_enzyme(name: String) -> ReplicationProtein {
    // Unzipping — helicases
    if name == "MCM_helicase" { return rprot("P33991", "MCM2", "MCM2-7 helicase complex", "Unwinds dsDNA at replication fork. Hexameric ring encircles leading strand template. ATP-dependent. THE replicative helicase.", "replication fork (ahead)", "Moyer SE et al. Proc Natl Acad Sci 103:10236-10241, 2006") }
    if name == "CDC45" { return rprot("O75419", "CDC45", "CDC45", "CMG complex member. Activates MCM helicase with GINS. Required for fork firing.", "replication fork", "Ilves I et al. Mol Cell 37:247-258, 2010") }

    // Stabilizing ssDNA
    if name == "RPA" { return rprot("P27694", "RPA1", "Replication Protein A (70kDa subunit)", "Coats single-stranded DNA after helicase unwinds it. Prevents reannealing and secondary structure. Recruits checkpoint and repair factors.", "ssDNA at fork", "Wold MS. Annu Rev Biochem 66:61-92, 1997") }

    // Primase
    if name == "primase" { return rprot("P49642", "PRIM1", "DNA primase small subunit", "Synthesizes short RNA primers (~10 nt) on the lagging strand template. Required because DNA polymerase cannot initiate de novo.", "lagging strand", "Lehninger 8th ed, Ch 25") }

    // DNA polymerases
    if name == "pol_epsilon" { return rprot("Q07864", "POLE", "DNA polymerase epsilon (catalytic)", "Leading strand synthesis. High fidelity, 3'-5' exonuclease proofreading. Processive with PCNA clamp.", "leading strand", "Pursell ZF et al. Science 317:127-130, 2007") }
    if name == "pol_delta" { return rprot("P28340", "POLD1", "DNA polymerase delta (catalytic)", "Lagging strand synthesis (Okazaki fragments). Also gap-filling in repair. Uses PCNA clamp.", "lagging strand", "Nick McElhinny SA et al. Mol Cell 30:137-144, 2008") }
    if name == "pol_alpha" { return rprot("P09884", "POLA1", "DNA polymerase alpha (catalytic)", "Initiates synthesis by extending RNA primer with ~20 nt DNA. Then hands off to pol delta/epsilon. Low fidelity, no proofreading.", "primer extension", "Lehninger 8th ed, Ch 25") }

    // Clamp and loader
    if name == "PCNA" { return rprot("P12004", "PCNA", "Proliferating cell nuclear antigen", "Sliding clamp. Ring encircles DNA, tethers pol delta/epsilon for processive synthesis. Also recruits mismatch repair, cell cycle regulators.", "replication fork", "Moldovan GL et al. Cell 129:665-679, 2007") }
    if name == "RFC" { return rprot("P35251", "RFC1", "Replication factor C (large subunit)", "Clamp loader. ATP-dependent loading of PCNA onto primed DNA. Opens the PCNA ring.", "primer-template junction", "Lehninger 8th ed, Ch 25") }

    // Okazaki fragment processing
    if name == "FEN1" { return rprot("P39748", "FEN1", "Flap endonuclease 1", "Removes RNA primers from Okazaki fragments by cleaving the 5' flap after pol delta strand displacement.", "lagging strand", "Balakrishnan L, Bambara RA. Annu Rev Biochem 82:119-138, 2013") }
    if name == "ligase1" { return rprot("P18858", "LIG1", "DNA ligase I", "Seals nicks between Okazaki fragments after FEN1 removes primers and pol delta fills gaps. Joins 3'-OH to 5'-phosphate.", "lagging strand", "Lehninger 8th ed, Ch 25") }

    // Topoisomerases (relieve supercoiling ahead of fork)
    if name == "TOP1" { return rprot("P11387", "TOP1", "Topoisomerase I", "Relieves positive supercoiling ahead of the replication fork by cutting one strand and allowing rotation.", "ahead of fork", "Wang JC. Nat Rev Mol Cell Biol 3:430-440, 2002") }
    if name == "TOP2A" { return rprot("P11388", "TOP2A", "Topoisomerase IIa", "Decatenates intertwined daughter chromosomes after replication. Cuts both strands, passes duplex through, reseals.", "behind fork / post-replication", "Nitiss JL. Nat Rev Cancer 9:338-350, 2009") }

    // Telomerase
    if name == "telomerase" { return rprot("O14746", "TERT", "Telomerase reverse transcriptase", "Extends telomeric repeats (TTAGGG)n at chromosome ends. Solves the end-replication problem. Active in stem cells and ~90% of cancers. Uses RNA template (TERC).", "chromosome ends", "Greider CW, Blackburn EH. Cell 51:887-898, 1987 (Nobel Prize 2009)") }

    return rprot("", "", "Unknown", "", "", "")
}

fn replication_step(step: Int) -> String {
    if step == 1 { return "Origin recognition: ORC (Origin Recognition Complex) binds replication origins in G1." }
    if step == 2 { return "Licensing: MCM2-7 helicase loaded onto origins by CDT1 and CDC6. Pre-RC formed. Licensed origins can fire once per cell cycle." }
    if step == 3 { return "Firing: CDK2 and DDK phosphorylate MCM, recruit CDC45+GINS to form CMG complex. Helicase activated. Bidirectional fork established." }
    if step == 4 { return "Unwinding: MCM helicase unzips dsDNA. RPA coats exposed ssDNA. Topoisomerase I relieves positive supercoiling ahead." }
    if step == 5 { return "Priming: Primase (PRIM1) synthesizes RNA primers on lagging strand template. Pol alpha extends primers with ~20 nt DNA." }
    if step == 6 { return "Leading strand: Pol epsilon synthesizes continuously 5' to 3' with PCNA clamp. High fidelity proofreading." }
    if step == 7 { return "Lagging strand: Pol delta synthesizes Okazaki fragments (~200 nt each) with PCNA clamp. Discontinuous synthesis." }
    if step == 8 { return "Primer removal: FEN1 cleaves RNA primer flaps. Pol delta fills gaps." }
    if step == 9 { return "Ligation: DNA ligase I seals nicks between Okazaki fragments." }
    if step == 10 { return "Termination: Converging forks meet. TOP2A decatenates daughter chromosomes. MCM unloaded." }
    return ""
}

fn replication_step_count() -> Int {
    return 10
}
