#!/usr/bin/env python3
"""Verify the MVP craft-shelter 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"
SMOKE = ROOT / "Scripts" / "verify_playable_loop_smoke.py"
BUILD_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianBuildingPlacementComponent.cpp"
SHELTER_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianShelterActor.cpp"
SHELTER_H = ROOT / "Source" / "AgrarianGame" / "AgrarianShelterActor.h"
BLUEPRINT_SETUP = ROOT / "Scripts" / "setup_playable_blueprints.py"
PERSISTENCE_VERIFY = ROOT / "Scripts" / "verify_shelter_weather_protection.py"

REQUIRED = {
    QA_DOC: [
        "## Craft Shelter",
        "Primitive frame, wall panel, roof panel, and shelter recipes",
        "BP_PrimitiveShelter",
        "verify_playable_loop_smoke.py",
    ],
    SMOKE: [
        "DA_Recipe_PrimitiveShelter",
        "DA_Recipe_PrimitiveFrame",
        "DA_Recipe_PrimitiveWallPanel",
        "DA_Recipe_PrimitiveRoofPanel",
        "run_natural_shelter_loop_smoke_test",
    ],
    BUILD_CPP: [
        "ServerPlaceBuildable_Implementation",
        "PlacementCost",
        "SpawnActor",
    ],
    SHELTER_H: [
        "class AAgrarianShelterActor",
    ],
    SHELTER_CPP: [
        "PersistentActorComponent->ActorTypeId = TEXT(\"primitive_shelter\")",
        "ProtectionVolume->SetBoxExtent",
    ],
    BLUEPRINT_SETUP: [
        "BP_PrimitiveShelter",
        "unreal.AgrarianShelterActor",
    ],
    PERSISTENCE_VERIFY: [
        "shelter",
        "weather protection",
    ],
    ROADMAP: [
        "[x] Can craft a shelter.",
    ],
}


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-shelter QA gate is covered by recipes, placement, and smoke-test hooks.")


if __name__ == "__main__":
    main()
