from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]


def require(path: Path, snippet: str) -> None:
    text = path.read_text(encoding="utf-8")
    if snippet not in text:
        raise SystemExit(f"{path.relative_to(ROOT)} missing {snippet!r}")


def main() -> None:
    header = ROOT / "Source" / "AgrarianGame" / "AgrarianSurvivalComponent.h"
    source = ROOT / "Source" / "AgrarianGame" / "AgrarianSurvivalComponent.cpp"
    hud = ROOT / "Source" / "AgrarianGame" / "AgrarianDebugHUD.cpp"
    roadmap = ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md"

    require(header, "DECLARE_DYNAMIC_MULTICAST_DELEGATE_TwoParams(FAgrarianDeathStateChangedSignature")
    require(header, "FAgrarianDeathStateChangedSignature OnDeathStateChanged;")
    require(header, "bool bLastBroadcastDeathState = false;")
    require(header, "FName LastBroadcastDeathReason = NAME_None;")
    require(source, "OnSurvivalChanged.Broadcast(Survival);")
    require(source, "bLastBroadcastDeathState != Survival.bIsDead")
    require(source, "LastBroadcastDeathReason != Survival.LastDeathReason")
    require(source, "OnDeathStateChanged.Broadcast(Survival.bIsDead, Survival.LastDeathReason);")
    require(hud, "Death:   %s")
    require(roadmap, "[x] Add replicated death feedback.")

    print("PASS: replicated death feedback is present.")


if __name__ == "__main__":
    main()
