from pathlib import Path


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

EXPECTED = {
    ROOT / "Source" / "AgrarianGame" / "AgrarianGameGameMode.h": [
        "virtual void BeginPlay() override;",
        "float ServerAutoSaveIntervalSeconds = 300.0f;",
        "void RunServerAutoSave();",
        "FTimerHandle ServerAutoSaveTimerHandle;",
    ],
    ROOT / "Source" / "AgrarianGame" / "AgrarianGameGameMode.cpp": [
        "GetWorldTimerManager().SetTimer",
        "&AAgrarianGameGameMode::RunServerAutoSave",
        "ServerAutoSaveIntervalSeconds > 0.0f",
        "Persistence->SaveCurrentWorld()",
    ],
    ROOT / "Docs" / "PersistenceDesignDocument.md": [
        "`ServerAutoSaveIntervalSeconds`",
        "`UAgrarianPersistenceSubsystem::SaveCurrentWorld`",
        "disables the MVP autosave timer",
    ],
    ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md": [
        "[x] Add server-side save interval.",
        "`AAgrarianGameGameMode`",
        "`SaveCurrentWorld`",
    ],
}


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

    if missing:
        raise RuntimeError("Server save interval verification failed: " + "; ".join(missing))

    print("PASS: authoritative server autosave interval is wired to world persistence.")


if __name__ == "__main__":
    main()
