from typing import Optional, Any
from datetime import datetime

from ....core.interfaces.dto import Dto
from ....core.interfaces.core import Core
from ....enums.essential.sagas import SagaState


class Saga[Properties: Any](Core[Properties]):
  ttl: int
  job: str

  state: SagaState
  session: str  # Mongo Session ID

  aborted_at: Optional[datetime]
  committed_at: Optional[datetime]


# ----------------------------------------
# Data Transfer Object Interface
# ----------------------------------------


class SagaDto[Properties: Any](Dto[Properties]):
  ttl: int
  job: str

  state: SagaState
  session: str  # Mongo Session ID

  aborted_at: Optional[datetime]
  committed_at: Optional[datetime]


class SagaStartDto[Properties: Any](Dto[Properties]):
  ttl: int
  job: Optional[str]

  state: Optional[SagaState]
  session: Optional[str]  # Mongo Session ID

  aborted_at: Optional[datetime]
  committed_at: Optional[datetime]
