from __future__ import annotations

from dataclasses import dataclass, asdict
from datetime import datetime, timezone
import json
import uuid

@dataclass(frozen=True)
class Event:
    event_id: str
    event_type: str
    occurred_at: str
    task_id: str
    run_id: str
    step_id: str | None
    attempt_id: str | None
    status: str


def emit_event(event_type, task_id, run_id, status,
               step_id=None, attempt_id=None):
    event = Event(
        event_id=str(uuid.uuid4()),
        event_type=event_type,
        occurred_at=datetime.now(timezone.utc).isoformat(),
        task_id=task_id,
        run_id=run_id,
        step_id=step_id,
        attempt_id=attempt_id,
        status=status,
    )
    print(json.dumps(asdict(event), ensure_ascii=False))
    return event

if __name__ == "__main__":
    result = emit_event(
        "agent.step.completed", "task_1", "run_1",
        "succeeded", "step_review", "attempt_1"
    )
    assert result.task_id == "task_1"
    assert result.event_type == "agent.step.completed"
