from __future__ import annotations

from app.domain.observability import AuditLogEntry, SystemEvent
from app.repositories.native.audit_logs import AuditLogRepository
from app.repositories.native.system_events import SystemEventRepository


class ObservabilityService:
    """Facade for audit and telemetry writes.

    Keeping this behind one service lets us fan out later to:
    - native PostgreSQL tables
    - queue/stream pipelines
    - external monitoring sinks
    without changing runtime/admin services.
    """

    def __init__(
        self,
        audit_repository: AuditLogRepository | None = None,
        system_event_repository: SystemEventRepository | None = None,
    ) -> None:
        self.audit_repository = audit_repository or AuditLogRepository()
        self.system_event_repository = system_event_repository or SystemEventRepository()

    async def record_audit(self, entry: AuditLogEntry) -> AuditLogEntry:
        return await self.audit_repository.add(entry)

    async def record_system_event(self, event: SystemEvent) -> SystemEvent:
        return await self.system_event_repository.add(event)

