"""Pydantic schemas - 商品管理""" from pydantic import BaseModel, Field from typing import Optional from datetime import datetime class ProductUnitBase(BaseModel): """商品单位基础字段""" name: str = Field(..., max_length=50) code: str = Field(..., max_length=20) class ProductUnitCreate(ProductUnitBase): """创建商品单位请求""" pass class ProductUnitResponse(ProductUnitBase): """商品单位响应""" id: int is_active: bool created_at: datetime class Config: from_attributes = True class ProductCategoryBase(BaseModel): """商品分类基础字段""" name: str = Field(..., max_length=100) parent_id: Optional[int] = None sort_order: int = 0 class ProductCategoryCreate(ProductCategoryBase): """创建商品分类请求""" pass class ProductCategoryResponse(ProductCategoryBase): """商品分类响应""" id: int is_active: bool created_at: datetime class Config: from_attributes = True class ProductBase(BaseModel): """商品基础字段""" name: str = Field(..., max_length=200) category_id: Optional[int] = None unit_id: Optional[int] = None description: Optional[str] = None image_url: Optional[str] = None class ProductCreate(ProductBase): """创建商品请求""" pass class ProductUpdate(BaseModel): """更新商品请求""" name: Optional[str] = None category_id: Optional[int] = None unit_id: Optional[int] = None description: Optional[str] = None image_url: Optional[str] = None is_active: Optional[bool] = None class ProductResponse(ProductBase): """商品响应""" id: int is_active: bool created_at: datetime unit: Optional[ProductUnitResponse] = None class Config: from_attributes = True