"""Surgical-procedure registry.

One planning engine — the safest corridor to a target while avoiding vessels,
eloquent cortex, and tracts, scored against predicted brain shift — generalises
across cranial procedures. This registry names each supported procedure, the
imaging modality, the Sulcora engine that plans it, and its status, so the app
and reports can enumerate what the toolkit does.

Corridor procedures (ICH, DBS, SEEG, biopsy, LITT, lesion access, EVD/shunt) run
today; glioma/GBM resection is volumetric (``sulcora.tumor``) and its resection
metrics are in; a learned segmentation backend and awake-mapping integration are
the remaining development items.
"""
from __future__ import annotations
from dataclasses import dataclass


@dataclass(frozen=True)
class Procedure:
    key: str
    name: str
    modality: str          # imaging typically used
    engine: str            # sulcora module/function that plans it
    kind: str              # "corridor" | "volumetric" | "multi-corridor"
    status: str            # "built" | "in_development"
    summary: str


PROCEDURES = [
    Procedure("ich", "Intracerebral haemorrhage (ICH) evacuation", "CT",
              "sulcora.hematoma.plan_hematoma", "corridor", "built",
              "Segment the clot, find its long axis, and maximise clot traversal while clearing vessels/eloquent cortex."),
    Procedure("dbs", "Deep brain stimulation (DBS)", "MRI (+CT)",
              "sulcora.session.recommend", "corridor", "built",
              "Named deep target (STN, GPi, ...) → safest entry with ranked alternatives, deformation-aware."),
    Procedure("seeg", "Stereo-EEG (SEEG) / epilepsy", "MRI (+CTA)",
              "sulcora.session.plan_multi", "multi-corridor", "built",
              "Multiple depth electrodes to multiple targets, conflict-aware, avoiding vessels and structures."),
    Procedure("biopsy", "Stereotactic biopsy", "MRI / CT",
              "sulcora.session.plan_to_lesion", "corridor", "built",
              "Lesion-centroid targeting for a diagnostic biopsy corridor."),
    Procedure("litt", "Laser interstitial thermal therapy (LITT)", "MRI",
              "sulcora.session.plan_to_lesion", "corridor", "built",
              "Lesion-centroid corridor for laser ablation (thermal modelling is a development item)."),
    Procedure("lesion", "Tumour / lesion access", "MRI / CT",
              "sulcora.session.plan_to_lesion", "corridor", "built",
              "Any segmented lesion (volume in cc) → safest access corridor."),
    Procedure("evd", "Ventricular catheter (EVD / shunt)", "CT",
              "sulcora.ventricle.plan_ventricular_catheter", "corridor", "built",
              "Segment the ventricles and plan a catheter to the frontal horn; reports cannulation and length."),
    Procedure("gbm", "Glioma / glioblastoma resection", "MRI (T1c + FLAIR)",
              "sulcora.tumor.resection_report", "volumetric", "in_development",
              "Two-compartment (enhancing + FLAIR) segmentation and extent-of-resection volumetrics vs the RANO resect targets; awake-mapping integration pending."),
]

PROCEDURE_BY_KEY = {p.key: p for p in PROCEDURES}


def list_procedures(status=None, kind=None):
    """Filtered list of procedures (by status and/or kind)."""
    out = PROCEDURES
    if status is not None:
        out = [p for p in out if p.status == status]
    if kind is not None:
        out = [p for p in out if p.kind == kind]
    return list(out)
