from pathlib import Path


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

EXPECTED = {
    ROOT / "Source" / "AgrarianGame" / "AgrarianGameGameMode.h": [
        "bool bLoadWorldOnServerStart = true;",
        "void RegisterPersistentActorClasses(UAgrarianPersistenceSubsystem* Persistence) const;",
        "void LoadWorldOnServerStart();",
    ],
    ROOT / "Source" / "AgrarianGame" / "AgrarianGameGameMode.cpp": [
        "LoadWorldOnServerStart();",
        "Persistence->RegisterWorldActorClass(TEXT(\"primitive_shelter\"), AAgrarianShelterActor::StaticClass());",
        "Persistence->RegisterWorldActorClass(TEXT(\"campfire\"), AAgrarianCampfire::StaticClass());",
        "Persistence->DoesSaveExist()",
        "Persistence->LoadCurrentWorld(RestoredPlayerCount, RestoredActorCount, bClearExistingActors);",
        "constexpr bool bClearExistingActors = false;",
    ],
    ROOT / "Docs" / "PersistenceDesignDocument.md": [
        "`bLoadWorldOnServerStart`",
        "`DoesSaveExist`",
        "`LoadCurrentWorld` without clearing existing map",
    ],
    ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md": [
        "[x] Add load-on-server-start.",
        "`bLoadWorldOnServerStart`",
        "authoritative `BeginPlay`",
    ],
}


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("Load-on-server-start verification failed: " + "; ".join(missing))

    print("PASS: authoritative server startup load is wired to current world persistence.")


if __name__ == "__main__":
    main()
