from datetime import datetime from typing import Optional from pydantic import BaseModel, Field class ProductBase(BaseModel): name: str = Field(..., min_length=1, max_length=100, example="Smartphone XYZ") description: Optional[str] = Field(None, example="Latest model with advanced features") price: float = Field(..., gt=0, example=799.99) sku: str = Field(..., min_length=3, max_length=50, example="SM-XYZ-2023") stock: int = Field(0, ge=0, example=25) category: Optional[str] = Field(None, example="Electronics") class ProductCreate(ProductBase): pass class ProductUpdate(BaseModel): name: Optional[str] = Field(None, min_length=1, max_length=100) description: Optional[str] = None price: Optional[float] = Field(None, gt=0) sku: Optional[str] = Field(None, min_length=3, max_length=50) stock: Optional[int] = Field(None, ge=0) category: Optional[str] = None class ProductInDB(ProductBase): id: int created_at: datetime updated_at: datetime class Config: from_attributes = True class Product(ProductInDB): pass