from typing import Any, Dict, Optional, TYPE_CHECKING

if TYPE_CHECKING:
    from ..client import Aeterdum

class Logs:
    def __init__(self, client: "Aeterdum"):
        self._client = client

    def create(self, 
               event: str, 
               actor: str, 
               payload: Optional[Dict[str, Any]] = None, 
               metadata: Optional[Dict[str, Any]] = None,
               id: Optional[str] = None) -> Dict[str, Any]:
        """
        Ingest a new audit log.
        If `id` is not provided, one will be generated by the API.
        """
        data = {
            "event": event,
            "actor": actor,
            "payload": payload,
            "metadata": metadata,
        }
        if id:
            data["id"] = id

        return self._client.request("POST", "/v1/logs", json=data)

    def list(self, limit: int = 50, offset: int = 0) -> Dict[str, Any]:
        """
        List logs with pagination.
        """
        params = {"limit": limit, "offset": offset}
        return self._client.request("GET", "/v1/logs", params=params)

    def get(self, id: str) -> Dict[str, Any]:
        """
        Get a single log by ID.
        """
        return self._client.request("GET", f"/v1/logs/{id}")

    def verify(self, id: str) -> Dict[str, Any]:
        """
        Verify the integrity of a log entry.
        """
        return self._client.request("GET", f"/v1/verify/{id}")
