from __future__ import annotations

import json

from app.modules.api.domain.events.client_event import ClientEventRecord


class SseEncoder:
    def encode(self, event: ClientEventRecord) -> str:
        payload = {
            "event_id": event.event_id,
            "request_id": event.request_id,
            "type": event.type.value,
            "source": event.source,
            "text": event.text,
            "payload": event.payload,
            "created_at": event.created_at.isoformat(),
        }
        return f"event: {event.type.value}\ndata: {json.dumps(payload, ensure_ascii=False)}\n\n"
