from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
PERSISTENCE_H = ROOT / "Source" / "AgrarianGame" / "AgrarianPersistenceSubsystem.h"
PERSISTENCE_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianPersistenceSubsystem.cpp"
CONTROLLER_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianGamePlayerController.cpp"
AUTOMATION_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianEditorAutomationLibrary.cpp"
PERSISTENCE_DOC = ROOT / "Docs" / "PersistenceDesignDocument.md"
ROADMAP = ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md"


EXPECTED = {
    PERSISTENCE_H: [
        "bool LoadCurrentWorld(int32& RestoredPlayerCount, int32& RestoredWorldActorCount, bool bClearExistingActors = true) const;",
        "bool RestoreWorldState(const UAgrarianSaveGame* SaveGame) const;",
    ],
    PERSISTENCE_CPP: [
        "SaveGame->WorldHours = GameState->WorldHours;",
        "SaveGame->WeatherInputs = GameState->ActiveWeatherInputs;",
        "GameState->WorldHours = SaveGame->WorldHours;",
        "GameState->ApplyMappedWeatherInputs(SaveGame->WeatherInputs);",
        "bool UAgrarianPersistenceSubsystem::LoadCurrentWorld",
        "RestoreWorldState(SaveGame)",
        "RestorePlayers(SaveGame)",
        "RestoreWorldActors(SaveGame, bClearExistingActors)",
    ],
    CONTROLLER_CPP: [
        "Persistence->LoadCurrentWorld(RestoredPlayerCount, RestoredActorCount)",
    ],
    AUTOMATION_CPP: [
        "SavedWeatherInputs.Provider = TEXT(\"automation-weather\");",
        "SavedWeatherInputs.ProviderTimestamp = TEXT(\"2026-05-16T08:00:00Z\");",
        "GameState->ApplyMappedWeatherInputs(SavedWeatherInputs);",
        "Persistence->LoadCurrentWorld(RestoredPlayerCount, RestoredActorCount, true)",
        "weather state did not survive save/load",
    ],
    PERSISTENCE_DOC: [
        "LoadCurrentWorld",
        "weather/time state",
        "players, and structures",
    ],
    ROADMAP: [
        "[x] Add weather save/load support.",
    ],
}


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("Weather save/load support verification failed: " + "; ".join(missing))
    print("Agrarian weather save/load support verification complete.")


if __name__ == "__main__":
    main()
