| 1 | from __future__ import annotations |
| 2 | |
| 3 | from uuid import UUID |
| 4 | |
| 5 | from app.models import PlatformEvent, ResearchDocument, ResearchEvent |
| 6 | |
| 7 | |
| 8 | def document_event(event_type: str, document: ResearchDocument, correlation_id: str | None = None) -> PlatformEvent: |
| 9 | return PlatformEvent( |
| 10 | event_type=event_type, |
| 11 | correlation_id=correlation_id, |
| 12 | payload={ |
| 13 | "documentId": str(document.document_id), |
| 14 | "instrumentId": str(document.instrument_id) if document.instrument_id else None, |
| 15 | "sourceType": document.source_type, |
| 16 | "status": document.status, |
| 17 | "canonicalUrl": document.canonical_url, |
| 18 | }, |
| 19 | ) |
| 20 | |
| 21 | |
| 22 | def research_event_extracted(event: ResearchEvent, correlation_id: str | None = None) -> PlatformEvent: |
| 23 | return PlatformEvent( |
| 24 | event_type="research.event.extracted", |
| 25 | correlation_id=correlation_id, |
| 26 | payload={ |
| 27 | "eventId": str(event.event_id), |
| 28 | "instrumentId": str(event.instrument_id), |
| 29 | "eventType": event.event_type, |
| 30 | "impact": event.impact, |
| 31 | "confidence": event.confidence, |
| 32 | "sourceDocumentId": str(event.source_document_id), |
| 33 | }, |
| 34 | ) |
| 35 | |
| 36 | |
| 37 | def company_updated(instrument_id: UUID, correlation_id: str | None = None) -> PlatformEvent: |
| 38 | return PlatformEvent( |
| 39 | event_type="research.company.updated", |
| 40 | correlation_id=correlation_id, |
| 41 | payload={"instrumentId": str(instrument_id)}, |
| 42 | ) |