from pathlib import Path


ROOT = Path(__file__).resolve().parents[1]
FILES = {
    "AgrarianSaveGame.h": ROOT / "Source" / "AgrarianGame" / "AgrarianSaveGame.h",
    "AgrarianInventoryComponent.h": ROOT / "Source" / "AgrarianGame" / "AgrarianInventoryComponent.h",
    "AgrarianInventoryComponent.cpp": ROOT / "Source" / "AgrarianGame" / "AgrarianInventoryComponent.cpp",
    "AgrarianPersistenceSubsystem.cpp": ROOT / "Source" / "AgrarianGame" / "AgrarianPersistenceSubsystem.cpp",
    "InventoryDataModel.md": ROOT / "Docs" / "InventoryDataModel.md",
    "TechnicalDesignDocument.md": ROOT / "Docs" / "TechnicalDesignDocument.md",
    "PersistenceDesignDocument.md": ROOT / "Docs" / "PersistenceDesignDocument.md",
    "AGRARIAN_DEVELOPMENT_ROADMAP.md": ROOT / "AGRARIAN_DEVELOPMENT_ROADMAP.md",
}

EXPECTED = {
    "AgrarianSaveGame.h": [
        "TArray<FAgrarianItemStack> Inventory",
    ],
    "AgrarianInventoryComponent.h": [
        "RestoreSavedItems",
        "const TArray<FAgrarianItemStack>& SavedItems",
    ],
    "AgrarianInventoryComponent.cpp": [
        "UAgrarianInventoryComponent::RestoreSavedItems",
        "Items = SavedItems",
        "BroadcastInventoryChanged()",
    ],
    "AgrarianPersistenceSubsystem.cpp": [
        "SavedPlayer.Inventory = InventoryComponent->Items",
        "InventoryComponent->RestoreSavedItems(SavedPlayer->Inventory)",
    ],
    "InventoryDataModel.md": [
        "`UAgrarianInventoryComponent::RestoreSavedItems`",
        "`OnInventoryChanged`",
        "Recompute derived values such as total weight",
    ],
    "TechnicalDesignDocument.md": [
        "Inventory persistence saves",
        "`FAgrarianSavedPlayer::Inventory`",
        "`UAgrarianInventoryComponent::RestoreSavedItems`",
        "`OnInventoryChanged`",
    ],
    "PersistenceDesignDocument.md": [
        "`FAgrarianSavedPlayer::Inventory`",
        "`UAgrarianInventoryComponent::Items`",
        "`UAgrarianInventoryComponent::RestoreSavedItems`",
        "broadcasts inventory changes",
    ],
    "AGRARIAN_DEVELOPMENT_ROADMAP.md": [
        "[x] Add persistence for inventory.",
        "[x] Save player inventory.",
        "`FAgrarianSavedPlayer::Inventory`",
        "`RestoreSavedItems`",
        "listeners are notified after load",
        "carry weight refresh after load",
    ],
}


def main():
    missing = []
    for label, path in FILES.items():
        text = path.read_text(encoding="utf-8")
        for snippet in EXPECTED[label]:
            if snippet not in text:
                missing.append(f"{label}: {snippet}")

    if missing:
        raise RuntimeError("Inventory persistence verification failed: " + "; ".join(missing))

    print("Agrarian inventory persistence verification complete.")


if __name__ == "__main__":
    main()
