from __future__ import annotations

from typing import TYPE_CHECKING, Dict
from urllib.parse import quote

if TYPE_CHECKING:
    from .._core._http_client import APIResponse, AsyncHttpClient, PaginatedResponse, SyncHttpClient


class Webhooks:
    """Sync webhooks resource."""

    def __init__(self, client: SyncHttpClient) -> None:
        self._client = client

    def list(self, params: Dict | None = None) -> PaginatedResponse:
        return self._client.get_paginated("/v1/me/webhooks", query=params)

    def create(self, params: Dict) -> APIResponse:
        return self._client.post("/v1/me/webhooks", body=params)

    def get(self, id: str) -> APIResponse:
        return self._client.get(f"/v1/me/webhooks/{quote(id, safe='')}")

    def update(self, id: str, params: Dict) -> APIResponse:
        return self._client.put(f"/v1/me/webhooks/{quote(id, safe='')}", body=params)

    def delete(self, id: str) -> APIResponse:
        return self._client.delete(f"/v1/me/webhooks/{quote(id, safe='')}")

    def test(self, id: str) -> APIResponse:
        return self._client.post(f"/v1/me/webhooks/{quote(id, safe='')}/test")


class AsyncWebhooks:
    """Async webhooks resource."""

    def __init__(self, client: AsyncHttpClient) -> None:
        self._client = client

    async def list(self, params: Dict | None = None) -> PaginatedResponse:
        return await self._client.get_paginated("/v1/me/webhooks", query=params)

    async def create(self, params: Dict) -> APIResponse:
        return await self._client.post("/v1/me/webhooks", body=params)

    async def get(self, id: str) -> APIResponse:
        return await self._client.get(f"/v1/me/webhooks/{quote(id, safe='')}")

    async def update(self, id: str, params: Dict) -> APIResponse:
        return await self._client.put(
            f"/v1/me/webhooks/{quote(id, safe='')}", body=params
        )

    async def delete(self, id: str) -> APIResponse:
        return await self._client.delete(f"/v1/me/webhooks/{quote(id, safe='')}")

    async def test(self, id: str) -> APIResponse:
        return await self._client.post(f"/v1/me/webhooks/{quote(id, safe='')}/test")
