#!/usr/bin/env python3
"""Verify the MVP resource gathering 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"
RESOURCE_H = ROOT / "Source" / "AgrarianGame" / "AgrarianResourceNode.h"
RESOURCE_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianResourceNode.cpp"
SMOKE = ROOT / "Scripts" / "verify_playable_loop_smoke.py"
PERSISTENCE = ROOT / "Scripts" / "verify_resource_node_persistence.py"

REQUIRED = {
    QA_DOC: [
        "## Resource Gathering",
        "Gather by hand",
        "RemainingHarvests",
        "character inventory path",
        "verify_playable_loop_smoke.py",
    ],
    RESOURCE_H: [
        "RemainingHarvests",
        "QuantityPerHarvest",
        "YieldItemDefinition",
        "OnRep_RemainingHarvests",
    ],
    RESOURCE_CPP: [
        "FText::FromString(TEXT(\"Gather\"))",
        "FText::FromString(TEXT(\"Gather by hand\"))",
        "if (!HasAuthority() || !Interactor || RemainingHarvests <= 0)",
        "RemainingHarvests--;",
        "Interactor->GetInventoryComponent()",
        "Inventory->AddItem(Granted)",
        "DOREPLIFETIME(AAgrarianResourceNode, RemainingHarvests);",
    ],
    SMOKE: [
        "WOOD_NODE_LABEL",
        "FIBER_NODE_LABEL",
        "run_natural_shelter_loop_smoke_test",
    ],
    PERSISTENCE: [
        "FAgrarianSavedResourceNode",
        "RemainingHarvests",
    ],
    ROADMAP: [
        "[x] Can gather resources.",
    ],
}


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: resource gathering QA gate is covered by gameplay and smoke-test hooks.")


if __name__ == "__main__":
    main()
