from dataclasses import dataclass from typing import Optional @dataclass(frozen=True) class CartItemDTO: product_id: int name: str quantity: int price: int @property def total(self): return self.price * self.quantity @dataclass class CartDTO: items: list[CartItemDTO] total: int order_id: Optional[int] = None