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:
    types = ROOT / "Source" / "AgrarianGame" / "AgrarianTypes.h"
    survival_h = ROOT / "Source" / "AgrarianGame" / "AgrarianSurvivalComponent.h"
    survival_cpp = ROOT / "Source" / "AgrarianGame" / "AgrarianSurvivalComponent.cpp"
    hud = ROOT / "Source" / "AgrarianGame" / "AgrarianDebugHUD.cpp"
    controller = ROOT / "Source" / "AgrarianGame" / "AgrarianGamePlayerController.cpp"
    roadmap = ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md"

    require(types, "bool bIsDead = false;")
    require(types, "FName LastDeathReason = NAME_None;")
    require(survival_h, "bool IsDead() const;")
    require(survival_h, "void MarkDead(FName Reason);")
    require(survival_h, "void Revive(float HealthAmount = 100.0f);")
    require(survival_h, "void UpdateDeathState();")
    require(survival_cpp, "return !Survival.bIsDead && Survival.Health > 0.0f;")
    require(survival_cpp, "bool UAgrarianSurvivalComponent::IsDead() const")
    require(survival_cpp, "void UAgrarianSurvivalComponent::MarkDead")
    require(survival_cpp, "void UAgrarianSurvivalComponent::Revive")
    require(survival_cpp, "void UAgrarianSurvivalComponent::UpdateDeathState")
    require(survival_cpp, "Survival.LastDeathReason = FName(TEXT(\"health_depleted\"));")
    require(controller, "Survival.bIsDead ? TEXT(\"DEAD\") : TEXT(\"ALIVE\")")
    require(controller, "SurvivalComponent->Revive(100.0f);")
    require(hud, "State     DEAD")
    require(hud, "State:   %s")
    require(roadmap, "[x] Add death state.")

    print("PASS: death state is present.")


if __name__ == "__main__":
    main()
