from pathlib import Path


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

EXPECTED = {
    ROOT / "Source" / "AgrarianGame" / "AgrarianPersistenceSubsystem.h": [
        "bool bBackupBeforeSave = true;",
        "bool BackupExistingSave() const;",
    ],
    ROOT / "Source" / "AgrarianGame" / "AgrarianPersistenceSubsystem.cpp": [
        "if (SaveGame && bBackupBeforeSave)",
        "BackupExistingSave();",
        "FPaths::ProjectSavedDir()",
        "TEXT(\"SaveGames\")",
        "TEXT(\"Backups\")",
        "FDateTime::UtcNow().ToString",
        "IFileManager::Get().Copy",
    ],
    ROOT / "Docs" / "PersistenceDesignDocument.md": [
        "`UAgrarianPersistenceSubsystem::bBackupBeforeSave`",
        "`Saved/SaveGames/Backups`",
        "UTC timestamp",
    ],
    ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md": [
        "[x] Add backup-before-save option.",
        "`bBackupBeforeSave`",
        "`Saved/SaveGames/Backups`",
    ],
}


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("Backup-before-save verification failed: " + "; ".join(missing))

    print("PASS: backup-before-save is wired before slot overwrite.")


if __name__ == "__main__":
    main()
