from pydantic import BaseModel, ConfigDict from typing import Optional, List from datetime import datetime from decimal import Decimal class ProductCreate(BaseModel): sku: str name: str description: Optional[str] = None category: Optional[str] = None unit: str = "件" item_type: str = "finished" cost_price: Decimal = Decimal("0") sale_price: Decimal = Decimal("0") min_stock: int = 0 max_stock: int = 1000 class ProductResponse(BaseModel): id: int sku: str name: str description: Optional[str] category: Optional[str] unit: str item_type: str cost_price: Decimal sale_price: Decimal min_stock: int max_stock: int material_cost: Decimal = Decimal("0") is_active: bool created_at: datetime model_config = ConfigDict(from_attributes=True) class ProductMaterialItemUpdate(BaseModel): material_id: int quantity: Decimal loss_rate: Decimal = Decimal("0") class ProductBOMUpdate(BaseModel): items: List[ProductMaterialItemUpdate] class ProductMaterialItemResponse(BaseModel): material_id: int material_sku: str material_name: str quantity: Decimal unit_cost: Decimal line_cost: Decimal class ProductBOMResponse(BaseModel): product_id: int product_name: str total_material_cost: Decimal items: List[ProductMaterialItemResponse]