from pathlib import Path


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

EXPECTED = {
    ROOT / "Source" / "AgrarianGame" / "AgrarianSaveGame.h": [
        "struct FAgrarianSavedPlayerIdentity",
        "FString StablePlayerId;",
        "FString PlayerName;",
        "FString NetworkId;",
        "bool bUsedNetworkId = false;",
        "FAgrarianSavedPlayerIdentity Identity;",
    ],
    ROOT / "Source" / "AgrarianGame" / "AgrarianPersistenceSubsystem.cpp": [
        "SavedPlayer.Identity.StablePlayerId = SavedPlayer.PlayerId;",
        "SavedPlayer.Identity.LastKnownPawnName = Character->GetName();",
        "SavedPlayer.Identity.PlayerName = PlayerState->GetPlayerName();",
        "SavedPlayer.Identity.NetworkId = UniqueId->ToString();",
        "SavedPlayer.Identity.bUsedNetworkId = true;",
        "return UniqueId->ToString();",
    ],
    ROOT / "Docs" / "PersistenceDesignDocument.md": [
        "`FAgrarianSavedPlayerIdentity`",
        "prefers the replicated `APlayerState` unique network ID",
        "store passwords, tokens, emails, or platform credentials",
    ],
    ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md": [
        "[x] Save player identity.",
        "`FAgrarianSavedPlayerIdentity`",
        "without storing credentials",
    ],
}


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("Player identity persistence verification failed: " + "; ".join(missing))

    print("PASS: player identity persistence captures safe stable identity metadata.")


if __name__ == "__main__":
    main()
