"""Observability broadcast — destinations and config."""

from __future__ import annotations

from typing import Any, Dict, Optional

from .._resource import AsyncResource, Resource


class Observability(Resource):
    """Sync observability operations."""

    def get_config(self) -> Dict[str, Any]:
        """Get observability configuration with destinations."""
        return self._get("/v1/observability/config")

    def update_config(self, params: Dict[str, Any]) -> Dict[str, Any]:
        """Update observability configuration."""
        return self._put("/v1/observability/config", params)

    def list_destinations(self) -> Dict[str, Any]:
        """List broadcast destinations."""
        return self._get("/v1/observability/destinations")

    def add_destination(self, params: Dict[str, Any]) -> Dict[str, Any]:
        """Add a broadcast destination."""
        return self._post("/v1/observability/destinations", params)

    def update_destination(self, dest_id: str, params: Dict[str, Any]) -> Dict[str, Any]:
        """Update a broadcast destination."""
        return self._put(f"/v1/observability/destinations/{dest_id}", params)

    def remove_destination(self, dest_id: str) -> Dict[str, Any]:
        """Remove a broadcast destination."""
        return self._delete(f"/v1/observability/destinations/{dest_id}")

    def templates(self, provider: Optional[str] = None) -> Dict[str, Any]:
        """Get integration templates. If provider specified, get that provider's template."""
        if provider:
            return self._get(f"/v1/observability/templates/{provider}")
        return self._get("/v1/observability/templates")


class AsyncObservability(AsyncResource):
    """Async observability operations."""

    async def get_config(self) -> Dict[str, Any]:
        return await self._get("/v1/observability/config")

    async def update_config(self, params: Dict[str, Any]) -> Dict[str, Any]:
        return await self._put("/v1/observability/config", params)

    async def list_destinations(self) -> Dict[str, Any]:
        return await self._get("/v1/observability/destinations")

    async def add_destination(self, params: Dict[str, Any]) -> Dict[str, Any]:
        return await self._post("/v1/observability/destinations", params)

    async def update_destination(self, dest_id: str, params: Dict[str, Any]) -> Dict[str, Any]:
        return await self._put(f"/v1/observability/destinations/{dest_id}", params)

    async def remove_destination(self, dest_id: str) -> Dict[str, Any]:
        return await self._delete(f"/v1/observability/destinations/{dest_id}")

    async def templates(self, provider: Optional[str] = None) -> Dict[str, Any]:
        if provider:
            return await self._get(f"/v1/observability/templates/{provider}")
        return await self._get("/v1/observability/templates")
