from pydantic import BaseModel, ConfigDict
from datetime import datetime
from typing import Optional
from decimal import Decimal

class UserReference(BaseModel):
    id: int
    name: Optional[str] = None
    model_config = ConfigDict(from_attributes=True)

class ItemPublic(BaseModel):
    id: int
    list_id: int
    name: str
    quantity: Optional[str] = None
    is_complete: bool
    price: Optional[Decimal] = None
    category_id: Optional[int] = None
    added_by_id: int
    completed_by_id: Optional[int] = None
    added_by_user: Optional[UserReference] = None
    completed_by_user: Optional[UserReference] = None
    created_at: datetime
    updated_at: datetime
    version: int
    model_config = ConfigDict(from_attributes=True)

class ItemCreate(BaseModel):
    name: str
    quantity: Optional[str] = None
    category_id: Optional[int] = None

class ItemUpdate(BaseModel):
    name: Optional[str] = None
    quantity: Optional[str] = None
    is_complete: Optional[bool] = None
    price: Optional[Decimal] = None
    position: Optional[int] = None
    category_id: Optional[int] = None
    version: int