#!/usr/bin/env python3
"""Verify the MVP craft-fire QA gate is covered."""

from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
ROADMAP = ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md"
QA_DOC = ROOT / "Docs" / "QA" / "MvpQaGates.md"
RECIPE_VERIFY = ROOT / "Scripts" / "verify_recipe_definitions.py"
PLAYER_SETUP = ROOT / "Scripts" / "setup_agrarian_player_blueprints.py"
BLUEPRINT_SETUP = ROOT / "Scripts" / "setup_playable_blueprints.py"
CAMPFIRE_H = ROOT / "Source" / "AgrarianGame" / "AgrarianCampfire.h"
CAMPFIRE_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianCampfire.cpp"
PERSISTENCE_VERIFY = ROOT / "Scripts" / "verify_fire_persistence.py"
RISK_VERIFY = ROOT / "Scripts" / "verify_fire_risk_qa_coverage.py"

REQUIRED = {
    QA_DOC: [
        "## Craft Fire",
        "DA_Recipe_Campfire",
        "BP_Campfire",
        "AAgrarianCampfire",
        "Light fire",
        "Maintain fire",
    ],
    RECIPE_VERIFY: [
        "DA_Recipe_Campfire",
        '"recipe_id": "campfire"',
        '"result": ("campfire", 1)',
    ],
    PLAYER_SETUP: [
        "/Game/Agrarian/DataAssets/Recipes/DA_Recipe_Campfire",
    ],
    BLUEPRINT_SETUP: [
        "BP_Campfire",
        "unreal.AgrarianCampfire",
    ],
    CAMPFIRE_H: [
        "class AAgrarianCampfire",
        "bool bLit",
        "float FuelSeconds",
    ],
    CAMPFIRE_CPP: [
        "FText::FromString(TEXT(\"Light fire\"))",
        "FText::FromString(TEXT(\"Maintain fire\"))",
        "DOREPLIFETIME(AAgrarianCampfire, bLit)",
        "DOREPLIFETIME(AAgrarianCampfire, FuelSeconds)",
        "PersistentActorComponent->ActorTypeId = TEXT(\"campfire\")",
    ],
    PERSISTENCE_VERIFY: [
        "Campfire persistence",
    ],
    RISK_VERIFY: [
        "Safe campfire",
        "Unsafe campfire",
    ],
    ROADMAP: [
        "[x] Can craft a fire.",
    ],
}


def main() -> None:
    missing: list[str] = []
    for path, snippets in REQUIRED.items():
        text = path.read_text(encoding="utf-8")
        for snippet in snippets:
            if snippet not in text:
                missing.append(f"{path.relative_to(ROOT)} missing {snippet!r}")
    if missing:
        raise SystemExit("FAILED: " + "; ".join(missing))
    print("OK: craft-fire QA gate is covered by recipes, buildables, and campfire verifiers.")


if __name__ == "__main__":
    main()
