"""Crypto Addresses resource."""

from __future__ import annotations

from typing import Any, Dict, Iterator, AsyncIterator, Optional

from ..client import HttpClient, AsyncHttpClient
from ..pagination import PaginatedResponse, async_paginate, paginate

BASE_PATH = "/api/v1/crypto-addresses"


class CryptoAddressesResource:
    """Sync crypto address operations."""

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

    def create(self, **params: Any) -> Dict[str, Any]:
        return self._client.request("POST", BASE_PATH, json_body=params)

    def list(self, *, page: int = 1, size: int = 10, **params: Any) -> PaginatedResponse:
        return self._client.request_paginated("GET", BASE_PATH, params={"page": page, "size": size, **params})

    def list_auto_paginate(self, **kwargs: Any) -> Iterator[Any]:
        return paginate(self.list, params=kwargs)

    def get(self, address_id: str) -> Dict[str, Any]:
        return self._client.request("GET", f"{BASE_PATH}/{address_id}")

    def update(self, address_id: str, **params: Any) -> Dict[str, Any]:
        return self._client.request("PATCH", f"{BASE_PATH}/{address_id}", json_body=params)

    def delete(self, address_id: str) -> Dict[str, Any]:
        return self._client.request("DELETE", f"{BASE_PATH}/{address_id}")

    def validate(self, **params: Any) -> Dict[str, Any]:
        return self._client.request("GET", f"{BASE_PATH}/validate", params=params)


class AsyncCryptoAddressesResource:
    """Async crypto address operations."""

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

    async def create(self, **params: Any) -> Dict[str, Any]:
        return await self._client.request("POST", BASE_PATH, json_body=params)

    async def list(self, *, page: int = 1, size: int = 10, **params: Any) -> PaginatedResponse:
        return await self._client.request_paginated("GET", BASE_PATH, params={"page": page, "size": size, **params})

    def list_auto_paginate(self, **kwargs: Any) -> AsyncIterator[Any]:
        return async_paginate(self.list, params=kwargs)

    async def get(self, address_id: str) -> Dict[str, Any]:
        return await self._client.request("GET", f"{BASE_PATH}/{address_id}")

    async def update(self, address_id: str, **params: Any) -> Dict[str, Any]:
        return await self._client.request("PATCH", f"{BASE_PATH}/{address_id}", json_body=params)

    async def delete(self, address_id: str) -> Dict[str, Any]:
        return await self._client.request("DELETE", f"{BASE_PATH}/{address_id}")

    async def validate(self, **params: Any) -> Dict[str, Any]:
        return await self._client.request("GET", f"{BASE_PATH}/validate", params=params)
