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 Support:
    """Sync support resource."""

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

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

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

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

    def reply(self, ticket_id: str, params: Dict) -> APIResponse:
        return self._client.post(
            f"/v1/me/support/{quote(ticket_id, safe='')}/replies", body=params
        )


class AsyncSupport:
    """Async support resource."""

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

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

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

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

    async def reply(self, ticket_id: str, params: Dict) -> APIResponse:
        return await self._client.post(
            f"/v1/me/support/{quote(ticket_id, safe='')}/replies", body=params
        )
