// sars_cov2.sy -- SARS-CoV-2 viral biology as native Scyla.
//
// The complete molecular mechanism of COVID-19 infection:
// spike protein binding, membrane fusion, RNA replication,
// immune evasion, and drug targets. Every protein cited.
//
// Sources:
//   Walls AC et al. Cell 181:281-292, 2020 (spike structure)
//   Hoffmann M et al. Cell 181:271-280, 2020 (ACE2 entry + TMPRSS2)
//   Lan J et al. Nature 581:215-220, 2020 (spike-ACE2 interface)
//   Zhou P et al. Nature 579:270-273, 2020 (SARS-CoV-2 identification)
//   Wrapp D et al. Science 367:1260-1263, 2020 (prefusion spike cryo-EM)
//   Gordon DE et al. Nature 583:459-468, 2020 (host-virus interactome)
//
// Marjorie McCubbins + Aether, April 2026
// Patent pending: 64/034,536

struct ViralProtein {
    name: String,
    gene: String,
    genbank: String,
    function_desc: String,
    drug_target: Bool,
    drug_name: String,
    citation: String,
}

struct InfectionStep {
    step_number: Int,
    phase: String,
    viral_component: String,
    host_component: String,
    host_accession: String,
    mechanism: String,
    drug_intervention: String,
    citation: String,
}

struct HostTarget {
    name: String,
    accession: String,
    gene: String,
    role_in_infection: String,
    therapeutic_strategy: String,
    citation: String,
}

fn vprot(n: String, g: String, gb: String, f: String, dt: Bool, dn: String, ci: String) -> ViralProtein {
    return ViralProtein { name: n, gene: g, genbank: gb, function_desc: f, drug_target: dt, drug_name: dn, citation: ci }
}

fn infstep(sn: Int, ph: String, vc: String, hc: String, ha: String, me: String, di: String, ci: String) -> InfectionStep {
    return InfectionStep { step_number: sn, phase: ph, viral_component: vc, host_component: hc, host_accession: ha, mechanism: me, drug_intervention: di, citation: ci }
}

fn htarget(n: String, a: String, g: String, r: String, ts: String, ci: String) -> HostTarget {
    return HostTarget { name: n, accession: a, gene: g, role_in_infection: r, therapeutic_strategy: ts, citation: ci }
}

// ═══════════════════════════════════════════════════════
// SARS-CoV-2 VIRAL PROTEINS
// ═══════════════════════════════════════════════════════

fn viral_protein(name: String) -> ViralProtein {
    if name == "spike" { return vprot("Spike glycoprotein (S)", "S", "P0DTC2", "Mediates receptor binding (RBD binds ACE2) and membrane fusion (S2 subunit). Homotrimer. Cleaved at S1/S2 and S2' sites. THE vaccine target. Heavily glycosylated (22 N-linked glycans per monomer).", true, "mRNA vaccines (BNT162b2, mRNA-1273) encode prefusion-stabilized spike. Monoclonal antibodies (sotrovimab, bebtelovimab).", "Wrapp D et al. Science 367:1260-1263, 2020") }

    if name == "RdRp" { return vprot("RNA-dependent RNA polymerase (nsp12)", "nsp12", "P0DTD1", "Replicates viral RNA genome. Forms complex with nsp7 and nsp8 cofactors. THE antiviral target.", true, "Remdesivir (adenosine analog, chain terminator). Molnupiravir (mutagenic NHC incorporated into RNA).", "Yin W et al. Science 368:1499-1504, 2020") }

    if name == "Mpro" { return vprot("Main protease (3CLpro, nsp5)", "nsp5", "P0DTD1", "Cleaves viral polyprotein at 11 sites. Essential for viral replication. Cysteine protease with His-Cys catalytic dyad.", true, "Nirmatrelvir (Paxlovid component). GC376.", "Jin Z et al. Nature 582:289-293, 2020") }

    if name == "PLpro" { return vprot("Papain-like protease (nsp3)", "nsp3", "P0DTD1", "Cleaves polyprotein at 3 sites. Also deubiquitinase and deISGylase — strips ubiquitin and ISG15 from host proteins to evade innate immunity.", true, "GRL-0617.", "Shin D et al. Nature 587:657-662, 2020") }

    if name == "nucleocapsid" { return vprot("Nucleocapsid protein (N)", "N", "P0DTC9", "Packages viral RNA into ribonucleoprotein complex. Also suppresses RNA silencing. Diagnostic target (antigen tests).", false, "Antigen rapid test target.", "Zeng W et al. Biochem Biophys Res Commun 527:618-623, 2020") }

    if name == "envelope" { return vprot("Envelope protein (E)", "E", "P0DTC4", "Viroporin (ion channel). Involved in virion assembly and release. Only 75 aa. Activates NLRP3 inflammasome in host.", false, "", "Mandala VS et al. Nat Struct Mol Biol 27:1202-1208, 2020") }

    if name == "membrane" { return vprot("Membrane protein (M)", "M", "P0DTC5", "Most abundant structural protein. Shapes virion envelope. Interacts with N for genome packaging. Suppresses type I interferon.", false, "", "Thomas S. Viruses 13:1908, 2021") }

    if name == "nsp13" { return vprot("Helicase (nsp13)", "nsp13", "P0DTD1", "Unwinds dsRNA and dsDNA with 5' to 3' polarity. NTPase. Essential for replication.", true, "Bismuth compounds (experimental).", "Chen J et al. J Virol 93:e00465-19, 2019") }

    return vprot("", "", "", "", false, "", "")
}

// ═══════════════════════════════════════════════════════
// INFECTION CYCLE — step by step
// ═══════════════════════════════════════════════════════

fn infection_step(step: Int) -> InfectionStep {
    if step == 1 { return infstep(1, "attachment", "Spike RBD", "ACE2 (angiotensin-converting enzyme 2)", "Q9BYF1", "Spike RBD binds ACE2 on host cell surface with high affinity (Kd ~15 nM). ACE2 normally converts angiotensin II to angiotensin 1-7 (vasodilator). Binding downregulates ACE2, shifting balance toward angiotensin II (vasoconstrictor, proinflammatory).", "Monoclonal antibodies block RBD-ACE2 interaction. Soluble ACE2 decoys.", "Lan J et al. Nature 581:215-220, 2020") }

    if step == 2 { return infstep(2, "priming", "Spike S2' site", "TMPRSS2 (transmembrane serine protease 2)", "O15393", "TMPRSS2 cleaves spike at S2' site, exposing the fusion peptide. Alternative: cathepsin L in endosomes (endosomal entry pathway).", "Camostat mesylate (TMPRSS2 inhibitor). Hydroxychloroquine was hypothesized to block endosomal pathway (did not work clinically).", "Hoffmann M et al. Cell 181:271-280, 2020") }

    if step == 3 { return infstep(3, "fusion", "Spike S2 fusion peptide", "Host cell plasma membrane", "", "Fusion peptide inserts into host membrane. S2 subunit refolds into six-helix bundle (6-HB), pulling viral and host membranes together. Viral RNA released into cytoplasm.", "Fusion inhibitor peptides (EK1C4). Targeting 6-HB formation.", "Xia S et al. Cell Mol Immunol 17:765-767, 2020") }

    if step == 4 { return infstep(4, "translation", "Viral genomic RNA (ORF1a/1ab)", "Host ribosome", "P62753", "Viral +ssRNA directly translated by host ribosomes. Produces pp1a and pp1ab polyproteins. Ribosomal frameshifting at slippery sequence produces pp1ab.", "", "V'kovski P et al. Nat Rev Microbiol 19:155-170, 2021") }

    if step == 5 { return infstep(5, "polyprotein processing", "Mpro (3CLpro) + PLpro", "Viral polyprotein", "", "Mpro cleaves pp1a/pp1ab at 11 sites. PLpro cleaves at 3 sites. Releases 16 nonstructural proteins (nsp1-nsp16) that form the replication-transcription complex.", "Nirmatrelvir (Paxlovid) inhibits Mpro. GRL-0617 inhibits PLpro.", "Jin Z et al. Nature 582:289-293, 2020") }

    if step == 6 { return infstep(6, "replication", "RdRp (nsp12) + nsp7 + nsp8", "Host cell cytoplasm (double-membrane vesicles)", "", "RdRp synthesizes negative-sense RNA intermediate, then new positive-sense genomic RNA. Replication occurs in double-membrane vesicles (DMVs) formed from ER membranes. nsp14 provides proofreading (3'-5' exonuclease).", "Remdesivir (chain terminator incorporated by RdRp). Molnupiravir (mutagenic analog).", "Yin W et al. Science 368:1499-1504, 2020") }

    if step == 7 { return infstep(7, "subgenomic transcription", "RdRp + discontinuous transcription", "N/A", "", "RdRp produces subgenomic mRNAs for structural proteins (S, E, M, N) and accessory proteins via discontinuous transcription (template switching at TRS sequences).", "", "Sola I et al. Annu Rev Virol 2:265-288, 2015") }

    if step == 8 { return infstep(8, "assembly", "N + genomic RNA + M + E", "ER-Golgi intermediate compartment (ERGIC)", "", "N protein packages genomic RNA into helical nucleocapsid. M protein drives budding into ERGIC. E protein (viroporin) facilitates assembly. Spike incorporated into virion membrane.", "", "V'kovski P et al. Nat Rev Microbiol 19:155-170, 2021") }

    if step == 9 { return infstep(9, "egress", "Mature virions", "Lysosomal exocytosis pathway", "", "Virions exit via lysosomal pathway (not classical secretory pathway). Arl8b-dependent. This deacidifies lysosomes, potentially impairing antigen presentation.", "", "Ghosh S et al. Cell 183:1520-1535, 2020") }

    return infstep(0, "", "", "", "", "", "", "")
}

// ═══════════════════════════════════════════════════════
// HOST TARGETS — what the virus exploits
// ═══════════════════════════════════════════════════════

fn host_target(name: String) -> HostTarget {
    if name == "ACE2" { return htarget("ACE2", "Q9BYF1", "ACE2", "Primary entry receptor. Expressed in lung alveolar type II cells, intestinal epithelium, heart, kidney, vascular endothelium.", "Soluble ACE2 decoys. Blocking antibodies.", "Zhou P et al. Nature 579:270-273, 2020") }
    if name == "TMPRSS2" { return htarget("TMPRSS2", "O15393", "TMPRSS2", "Serine protease that cleaves spike S2' site for membrane fusion. Expressed in lung epithelium. Androgen-regulated (may explain male severity bias).", "Camostat mesylate (serine protease inhibitor).", "Hoffmann M et al. Cell 181:271-280, 2020") }
    if name == "NRP1" { return htarget("Neuropilin-1", "O14786", "NRP1", "Co-receptor. Binds furin-cleaved spike (CendR motif). Enhances infection. Broadly expressed.", "EG00229 (NRP1 inhibitor, experimental).", "Daly JL et al. Science 370:861-865, 2020") }
    if name == "CD147" { return htarget("Basigin (CD147)", "P35613", "BSG", "Alternative receptor (disputed). Expressed on lymphocytes, may contribute to lymphocyte infection and lymphopenia.", "Meplazumab (anti-CD147 antibody, clinical trial).", "Wang K et al. bioRxiv 2020 (preprint, peer review mixed)") }
    if name == "FURIN" { return htarget("Furin", "P09958", "FURIN", "Cleaves spike at S1/S2 polybasic site (RRAR) during biosynthesis in Golgi. This pre-priming is unique to SARS-CoV-2 (not in SARS-CoV-1) and enhances transmissibility.", "Decanoyl-RVKR-CMK (furin inhibitor, experimental).", "Coutard B et al. Antiviral Res 176:104742, 2020") }
    return htarget("", "", "", "", "", "")
}

// ═══════════════════════════════════════════════════════
// VARIANTS OF CONCERN
// ═══════════════════════════════════════════════════════

fn variant_info(name: String) -> String {
    if name == "Alpha" { return "B.1.1.7 | First detected UK Sep 2020 | Key mutations: N501Y (increased ACE2 affinity), P681H (near furin site), del69-70. ~50% more transmissible. Cited: Davies NG et al. Science 372:eabg3055, 2021." }
    if name == "Beta" { return "B.1.351 | First detected South Africa Oct 2020 | Key: E484K (immune escape), K417N, N501Y. Reduced vaccine efficacy. Cited: Tegally H et al. Nature 592:438-443, 2021." }
    if name == "Delta" { return "B.1.617.2 | First detected India Dec 2020 | Key: L452R (immune escape), P681R (enhanced furin cleavage), T478K. ~60% more transmissible than Alpha. Cited: Mlcochova P et al. Nature 599:114-119, 2021." }
    if name == "Omicron" { return "B.1.1.529 | First detected South Africa Nov 2021 | 30+ spike mutations including 15 in RBD. Massive immune escape. BA.1, BA.2, BA.5, XBB sublineages. Reduced severity, extreme transmissibility. Cited: Viana R et al. Nature 603:679-686, 2022." }
    return ""
}

// ═══════════════════════════════════════════════════════
// QUICK ACCESS
// ═══════════════════════════════════════════════════════

fn infection_step_count() -> Int {
    return 9
}

fn viral_protein_count() -> Int {
    return 8
}

fn sars_cov2_genome_size() -> Int {
    // ~29,903 nucleotides, positive-sense single-stranded RNA
    return 29903
}

fn sars_cov2_citation() -> String {
    return "Wu F et al. Nature 579:265-269, 2020 (genome sequence). Zhou P et al. Nature 579:270-273, 2020 (identification)."
}
