from uuid import uuid4
from app.models import OutboxEvent
class TransactionalEventPublisher:
    def __init__(self, session): self.session=session
    async def publish(self, *, event_type, aggregate_type, aggregate_id, tenant_id, payload=None):
        row=OutboxEvent(tenant_id=tenant_id,event_type=str(getattr(event_type,"value",event_type)),aggregate_type=aggregate_type,aggregate_id=str(aggregate_id),payload=payload or {})
        self.session.add(row); await self.session.flush(); return row
