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 Favorites:
    """Sync favorites 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/favorites", query=params)

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

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


class AsyncFavorites:
    """Async favorites 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/favorites", query=params)

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

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