from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
FILES = {
    "AgrarianSurvivalComponent.h": ROOT / "Source" / "AgrarianGame" / "AgrarianSurvivalComponent.h",
    "AgrarianSurvivalComponent.cpp": ROOT / "Source" / "AgrarianGame" / "AgrarianSurvivalComponent.cpp",
    "AgrarianGamePlayerController.h": ROOT / "Source" / "AgrarianGame" / "AgrarianGamePlayerController.h",
    "AgrarianGamePlayerController.cpp": ROOT / "Source" / "AgrarianGame" / "AgrarianGamePlayerController.cpp",
    "TechnicalDesignDocument.md": ROOT / "Docs" / "TechnicalDesignDocument.md",
    "InventoryDataModel.md": ROOT / "Docs" / "InventoryDataModel.md",
    "AGRARIAN_DEVELOPMENT_ROADMAP.md": ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md",
}

EXPECTED = {
    "AgrarianSurvivalComponent.h": [
        "void ReduceInjury(float Amount);",
    ],
    "AgrarianSurvivalComponent.cpp": [
        "void UAgrarianSurvivalComponent::ReduceInjury",
        "Survival.InjurySeverity -= FMath::Max(0.0f, Amount);",
        "BroadcastSurvivalChanged();",
    ],
    "AgrarianGamePlayerController.h": [
        "void AgrarianUseItem(FName ItemId, int32 Quantity);",
        "void ServerAgrarianUseItem(FName ItemId, int32 Quantity);",
    ],
    "AgrarianGamePlayerController.cpp": [
        "ApplyAgrarianItemUseEffect",
        "ItemId == TEXT(\"food\")",
        "SurvivalComponent->AddFood(15.0f * Quantity);",
        "ItemId == TEXT(\"meat\")",
        "SurvivalComponent->AddSickness(3.0f * Quantity);",
        "ItemId == TEXT(\"bandage\")",
        "SurvivalComponent->ReduceInjury(18.0f * Quantity);",
        "SurvivalComponent->ReduceBleeding(28.0f * Quantity);",
        "SurvivalComponent->ReduceSprain(10.0f * Quantity);",
        "void AAgrarianGamePlayerController::AgrarianUseItem(FName ItemId, int32 Quantity)",
        "Usage: AgrarianUseItem <ItemId> <Quantity>",
        "void AAgrarianGamePlayerController::ServerAgrarianUseItem_Implementation",
        "InventoryComponent->ExtractItem(ItemId, Quantity, UsedStack)",
        "InventoryComponent->AddItem(UsedStack);",
        "cannot be used yet; item restored",
    ],
    "TechnicalDesignDocument.md": [
        "`AgrarianUseItem ItemId Quantity`",
        "`food` restores hunger",
        "`meat` restores more hunger",
        "adds sickness risk",
        "MVP treatment",
        "reduces injury, bleeding, and sprain severity",
        "restores the stack if the item is not usable yet",
    ],
    "InventoryDataModel.md": [
        "Item use:",
        "server validates the item type and applies item-specific effects.",
    ],
    "AGRARIAN_DEVELOPMENT_ROADMAP.md": [
        "[x] Add item use.",
    ],
}


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("Item use verification failed: " + "; ".join(missing))

    print("Agrarian item use verification complete.")


if __name__ == "__main__":
    main()
