"""Core organs 摘要 — 小路 · 小莫 · P15。"""

from __future__ import annotations

from typing import TYPE_CHECKING

from niannian.cognitive.plane_registry import PlaneRegistry
from niannian.personas import DMN, THALAMUS

if TYPE_CHECKING:
    from niannian.client import NianNian


def organs_api_dict(nn: NianNian) -> dict:
    reg = PlaneRegistry(nn._config, home=nn._home)
    planes = {p["id"]: p for p in reg.list_planes() if isinstance(p, dict) and p.get("id")}
    p15 = planes.get("P15")
    threads = nn._subject_store.load_open_threads()
    return {
        "modules": [
            {
                "id": "thalamus",
                "persona": THALAMUS,
                "plane": "P1",
                "label": (planes.get("P1") or {}).get("label") or "感知",
            },
            {
                "id": "dmn",
                "persona": DMN,
                "plane": "P14",
                "label": (planes.get("P14") or {}).get("label") or "生活",
                "open_threads_count": len(threads),
            },
        ],
        "p15_registered": p15 is not None and p15.get("enabled", True),
        "p15": p15,
    }
