| 1234567891011121314151617181920212223242526272829303132 | from datetime import datetimefrom typing import Optionalfrom typing import Typefrom typing import TypeVarfrom clean_python.base.domain.exceptions import BadRequestfrom clean_python.base.domain.value_object import ValueObjectfrom clean_python.base.infrastructure.now import nowT = TypeVar("T", bound="RootEntity")class RootEntity(ValueObject):    id: Optional[int] = None    created_at: datetime    updated_at: datetime    @classmethod    def create(cls: Type[T], **values) -> T:        values.setdefault("created_at", now())        values.setdefault("updated_at", values["created_at"])        return super(RootEntity, cls).create(**values)    def update(self: T, **values) -> T:        if "id" in values and self.id is not None and values["id"] != self.id:            raise BadRequest("Cannot change the id of an entity")        values.setdefault("updated_at", now())        return super().update(**values)    def __hash__(self):        assert self.id is not None        return hash(self.__class__) + hash(self.id)
 |