from pathlib import Path


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

FILES = {
    "AgrarianResourceNode.h": ROOT / "Source" / "AgrarianGame" / "AgrarianResourceNode.h",
    "AgrarianResourceNode.cpp": ROOT / "Source" / "AgrarianGame" / "AgrarianResourceNode.cpp",
    "setup_playable_blueprints.py": ROOT / "Scripts" / "setup_playable_blueprints.py",
    "verify_playable_blueprints.py": ROOT / "Scripts" / "verify_playable_blueprints.py",
    "TechnicalDesignDocument.md": ROOT / "Docs" / "TechnicalDesignDocument.md",
    "Roadmap": ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md",
}

REQUIRED_SNIPPETS = {
    "AgrarianResourceNode.h": [
        "bool bRespawnsForMvp = false;",
        "float RespawnDelaySeconds = 900.0f;",
        "int32 MaxHarvests = 5;",
        "void ScheduleRespawnIfNeeded();",
        "void RespawnNode();",
        "FTimerHandle RespawnTimerHandle;",
    ],
    "AgrarianResourceNode.cpp": [
        "ScheduleRespawnIfNeeded();",
        "!bRespawnsForMvp || RemainingHarvests > 0",
        "World->GetTimerManager().SetTimer",
        "FMath::Max(1.0f, RespawnDelaySeconds)",
        "RemainingHarvests = FMath::Max(1, MaxHarvests);",
        "UpdateDepletedState();",
    ],
    "setup_playable_blueprints.py": [
        '"respawns_for_mvp": True',
        '"respawns_for_mvp": False',
        '"respawn_delay_seconds": 600.0',
        '"respawn_delay_seconds": 900.0',
        '"respawn_delay_seconds": 1200.0',
        '"max_harvests": 16',
    ],
    "verify_playable_blueprints.py": [
        '"respawns_for_mvp": True',
        '"respawns_for_mvp": False',
        '"respawn_delay_seconds": 1800.0',
        '"max_harvests": 12',
    ],
    "TechnicalDesignDocument.md": [
        "renewable MVP resource nodes respawn",
        "Stone remains nonrespawning",
    ],
    "Roadmap": [
        "[x] Add respawn rules for MVP.",
        "renewable surface resources respawn",
    ],
}


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

    if missing:
        raise SystemExit("Resource respawn rule verification failed:\n" + "\n".join(missing))

    print(
        "PASS: MVP resource respawn rules are configured for renewable nodes, "
        "exclude nonrenewable stone, and are covered by Blueprint verification."
    )


if __name__ == "__main__":
    main()
