"""Models used to serialize API requests and responses.""" from typing import Annotated, Any, List from annotated_types import Len from pydantic import BaseModel, RootModel from pdp.constants.constants import CacheEntryType class CacheItem(RootModel): # type: ignore[type-arg] """Representation of a cache item. Generic model we can use to serialize any cache item, even if the shape of the item is malformed. This is helpful for our cache_list endpoint. """ root: Any class ListCacheRequest(BaseModel): """Request object for listing cached items.""" keys: Annotated[List[str], Len(min_length=1)] class CacheResult(BaseModel): """Representation of a cache result.""" key: str value: Any class ListCacheResponse(BaseModel): """Response object for listing cached items.""" items: List[CacheResult] class BustCacheRequest(BaseModel): """Request object for busting cached items.""" keys: Annotated[List[str], Len(min_length=1)] class BustCacheResult(BaseModel): """Representation of a cache bust result.""" key: str value: Any deleted: bool class BustCacheResponse(BaseModel): """Response object for busting cached items.""" items: List[BustCacheResult] class BludgeonCacheRequest(BaseModel): """Request object for deleting cache entries by type.""" cache_entry_type: CacheEntryType delete: bool = False class BludgeonCacheResponse(BaseModel): """Response object for deleting cache entries by type.""" total_rows_before_delete: int total_rows_affected: int performed_delete: bool