from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
FILES = {
    "AgrarianTypes.h": ROOT / "Source" / "AgrarianGame" / "AgrarianTypes.h",
    "AgrarianSurvivalComponent.h": ROOT / "Source" / "AgrarianGame" / "AgrarianSurvivalComponent.h",
    "AgrarianSurvivalComponent.cpp": ROOT / "Source" / "AgrarianGame" / "AgrarianSurvivalComponent.cpp",
    "AgrarianGameCharacter.cpp": ROOT / "Source" / "AgrarianGame" / "AgrarianGameCharacter.cpp",
    "AgrarianDebugHUD.cpp": ROOT / "Source" / "AgrarianGame" / "AgrarianDebugHUD.cpp",
    "AgrarianGamePlayerController.cpp": ROOT / "Source" / "AgrarianGame" / "AgrarianGamePlayerController.cpp",
}

EXPECTED = {
    "AgrarianTypes.h": [
        "float Exhaustion = 0.0f;",
    ],
    "AgrarianSurvivalComponent.h": [
        "float ExhaustionGainPerLowStaminaSecond = 0.35f;",
        "float ExhaustionRecoveryPerSecond = 0.08f;",
        "float LowStaminaExhaustionThreshold = 20.0f;",
        "void AddExhaustion(float Amount);",
        "void ReduceExhaustion(float Amount);",
    ],
    "AgrarianSurvivalComponent.cpp": [
        "Survival.Exhaustion += ExhaustionGainPerLowStaminaSecond * DeltaTime;",
        "Survival.Exhaustion -= ExhaustionRecoveryPerSecond * DeltaTime;",
        "Survival.Exhaustion += PositiveAmount * 0.05f;",
        "void UAgrarianSurvivalComponent::AddExhaustion",
        "void UAgrarianSurvivalComponent::ReduceExhaustion",
        "Survival.Exhaustion = FMath::Clamp(Survival.Exhaustion, 0.0f, 100.0f);",
    ],
    "AgrarianGameCharacter.cpp": [
        "SurvivalComponent->Survival.Exhaustion < 85.0f",
        "const float ExhaustionMultiplier = FMath::GetMappedRangeValueClamped",
        "HungerMultiplier * ThirstMultiplier * InjuryMultiplier * ExhaustionMultiplier",
    ],
    "AgrarianDebugHUD.cpp": [
        "Exhaust:",
        "Survival.Exhaustion",
    ],
    "AgrarianGamePlayerController.cpp": [
        "Exhaustion %.1f",
        "Survival.Exhaustion",
        "SurvivalComponent->ReduceExhaustion(100.0f);",
    ],
}


def main():
    missing = []
    for label, path in FILES.items():
        text = path.read_text(encoding="utf-8")
        for snippet in EXPECTED[label]:
            if snippet not in text:
                missing.append(f"{label}: {snippet}")

    if missing:
        raise RuntimeError("Exhaustion stat verification failed: " + "; ".join(missing))

    print("Agrarian exhaustion stat verification complete.")


if __name__ == "__main__":
    main()
