from __future__ import annotations

import uuid

from repo_core.base import BaseRepository

from .model import CodalRequestLog


class CodalRequestLogRepository(BaseRepository[CodalRequestLog]):
    TABLE = "codal_request_logs"
    _backends = {"db"}

    async def log_request(self, data: dict) -> CodalRequestLog:
        """Insert a single request log entry.  Best-effort — callers
        should wrap in try/except."""
        data.setdefault("id", str(uuid.uuid4()))
        return await self.insert_one(self.TABLE, data)
