25 lines
598 B
Python
25 lines
598 B
Python
from abc import ABC
|
|
from dataclasses import replace
|
|
from typing import Self
|
|
|
|
from domain.marketplace.domain_event import DomainEvent
|
|
|
|
|
|
class Entity(ABC):
|
|
_changes: tuple[DomainEvent, ...] = ()
|
|
|
|
def apply_event(self, event: DomainEvent) -> Self:
|
|
return replace(self, _changes=(*self._changes, event))
|
|
|
|
def get_changes(self) -> tuple[DomainEvent, ...]:
|
|
return self._changes
|
|
|
|
def _ensure_valid_state(self):
|
|
pass
|
|
|
|
def when(self, event: DomainEvent) -> Self:
|
|
return self
|
|
|
|
def clear_changes(self) -> Self:
|
|
return replace(self, _changes=())
|