#!/usr/bin/env python3
"""Verify active grass, forest, and structure fire state persists."""

from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
FIRE_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianCampfire.cpp"
TDD = ROOT / "Docs" / "TechnicalDesignDocument.md"
ROADMAP = ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md"

PERSISTED_KEYS = [
    "grass_ignition_risk_score",
    "forest_ignition_risk_score",
    "structure_ignition_risk_score",
    "grass_or_brush_ignited",
    "forest_fuel_ignited",
    "structure_ignited",
    "grass_fire_intensity",
    "forest_fire_intensity",
    "structure_fire_intensity",
    "active_fire_spread_radius",
    "fire_suppression_pressure",
]


def require(condition: bool, message: str) -> None:
    if not condition:
        raise SystemExit(f"FAILED: {message}")


def main() -> None:
    fire_cpp = FIRE_CPP.read_text(encoding="utf-8")
    tdd = TDD.read_text(encoding="utf-8")
    roadmap = ROADMAP.read_text(encoding="utf-8")

    for key in PERSISTED_KEYS:
        require(
            f'NumberState.Add(TEXT("{key}")' in fire_cpp,
            f"campfire capture missing persisted key {key}",
        )
        require(
            f'NumberState.Find(TEXT("{key}")' in fire_cpp,
            f"campfire apply missing persisted key {key}",
        )

    for token in [
        "Active grass, forest, and structure fire state persists",
        "ignition flags",
        "fire intensities",
        "spread radius",
        "suppression pressure",
    ]:
        require(token in tdd, f"technical design document missing {token!r}")

    require(
        "[x] Persist active grass, forest, and structure fires across save/load" in roadmap,
        "roadmap item is not checked off",
    )

    print("OK: active fire state persists across save/load.")


if __name__ == "__main__":
    main()
