"""Digifeeds Pydantic Models"""
from pydantic import BaseModel, Field, ConfigDict
from datetime import datetime
from enum import Enum
[docs]
class ItemStatus(BaseModel):
name: str = Field(alias="status_name")
description: str = Field(alias="status_description")
created_at: datetime
model_config = ConfigDict(populate_by_name=True, from_attributes=True)
[docs]
class ItemBase(BaseModel):
model_config = ConfigDict(populate_by_name=True, from_attributes=True)
barcode: str = Field(alias="item_barcode")
[docs]
class Item(ItemBase):
created_at: datetime
statuses: list[ItemStatus] = []
model_config = ConfigDict(
json_schema_extra={
"examples": [
{
"barcode": "39015040218748",
"created_at": "2024-09-25T17:12:39",
"statuses": [
{
"name": "in_zephir",
"description": "Item is in zephir",
"created_at": "2024-09-25T17:13:28",
}
],
}
]
}
)
[docs]
class PageOfItems(BaseModel):
items: list[Item]
limit: int = 10
offset: int = 0
total: int = 1
[docs]
class ItemFilters(str, Enum):
in_zephir = "in_zephir"
not_in_zephir = "not_in_zephir"
pending_deletion = "pending_deletion"
not_pending_deletion = "not_pending_deletion"
not_found_in_alma = "not_found_in_alma"
[docs]
class ItemCreate(ItemBase):
pass
[docs]
class StatusBase(BaseModel):
name: str
[docs]
class Status(StatusBase):
description: str
[docs]
class Response(BaseModel):
detail: str
[docs]
class Response400(Response):
model_config = ConfigDict(
json_schema_extra={
"examples": [
{
"detail": "Item already exists",
}
]
}
)
[docs]
class Response404(Response):
model_config = ConfigDict(
json_schema_extra={
"examples": [
{
"detail": "Item not found",
}
]
}
)