from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
TYPES_H = ROOT / "Source" / "AgrarianGame" / "AgrarianTypes.h"
GAME_STATE_H = ROOT / "Source" / "AgrarianGame" / "AgrarianGameState.h"
GAME_STATE_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianGameState.cpp"
SAVE_GAME_H = ROOT / "Source" / "AgrarianGame" / "AgrarianSaveGame.h"
PERSISTENCE_H = ROOT / "Source" / "AgrarianGame" / "AgrarianPersistenceSubsystem.h"
PERSISTENCE_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianPersistenceSubsystem.cpp"
PROVIDER_CPP = ROOT / "Source" / "AgrarianGame" / "AgrarianWeatherProviderSubsystem.cpp"
TDD = ROOT / "Docs" / "TechnicalDesignDocument.md"
PERSISTENCE_DOC = ROOT / "Docs" / "PersistenceDesignDocument.md"
ROADMAP = ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md"


EXPECTED = {
    TYPES_H: [
        "FName TileId = NAME_None;",
        "float Latitude = 0.0f;",
        "float Longitude = 0.0f;",
        "struct FAgrarianWeatherDebugSnapshot",
        "FString ProviderTimestamp;",
        "EAgrarianWeatherType AppliedWeather",
    ],
    PROVIDER_CPP: [
        "MappedInputs.TileId = Snapshot.TileId;",
        "MappedInputs.Latitude = Snapshot.Latitude;",
        "MappedInputs.Longitude = Snapshot.Longitude;",
    ],
    GAME_STATE_H: [
        "FAgrarianWeatherDebugSnapshot ActiveWeatherDebug",
        "FAgrarianWeatherDebugSnapshot GetWeatherDebugSnapshot() const;",
    ],
    GAME_STATE_CPP: [
        "DOREPLIFETIME(AAgrarianGameState, ActiveWeatherDebug);",
        "ActiveWeatherDebug.Provider = ActiveWeatherInputs.Provider;",
        "ActiveWeatherDebug.ProviderTimestamp = ActiveWeatherInputs.ProviderTimestamp;",
        "ActiveWeatherDebug.AppliedWeather = ActiveWeatherInputs.MappedWeather;",
        "FAgrarianWeatherDebugSnapshot AAgrarianGameState::GetWeatherDebugSnapshot() const",
    ],
    SAVE_GAME_H: [
        "FAgrarianMappedWeatherInputs WeatherInputs;",
        "FAgrarianWeatherDebugSnapshot WeatherDebug;",
    ],
    PERSISTENCE_H: [
        "bool CaptureWorldState(UAgrarianSaveGame* SaveGame) const;",
        "bool RestoreWorldState(const UAgrarianSaveGame* SaveGame) const;",
    ],
    PERSISTENCE_CPP: [
        "SaveGame->WeatherInputs = GameState->ActiveWeatherInputs;",
        "SaveGame->WeatherDebug = GameState->GetWeatherDebugSnapshot();",
        "GameState->ApplyMappedWeatherInputs(SaveGame->WeatherInputs);",
        "CaptureWorldState(SaveGame);",
    ],
    TDD: [
        "`FAgrarianWeatherDebugSnapshot`",
        "weather source",
        "provider timestamp",
        "tile center coordinate",
    ],
    PERSISTENCE_DOC: [
        "`FAgrarianWeatherDebugSnapshot`",
        "weather source",
        "provider timestamp",
        "tile center coordinate",
    ],
    ROADMAP: [
        "[x] Store weather source, provider timestamp, tile coordinate, and applied in-game weather state for debugging and persistence.",
    ],
}


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 debug persistence verification failed: " + "; ".join(missing))
    print("Agrarian weather debug persistence verification complete.")


if __name__ == "__main__":
    main()
