"""
Auto-generated whatsapp_phone_numbers resource.

DO NOT EDIT THIS FILE MANUALLY.
Run `python scripts/generate_resources.py` to regenerate.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
    from ..client.base import BaseClient


class WhatsappPhoneNumbersResource:
    """
    whatsapp_phone_numbers operations.
    """

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

    def _build_params(self, **kwargs: Any) -> dict[str, Any]:
        """Build query parameters, filtering None values."""

        def to_camel(s: str) -> str:
            parts = s.split("_")
            return parts[0] + "".join(p.title() for p in parts[1:])

        return {to_camel(k): v for k, v in kwargs.items() if v is not None}

    def _build_payload(self, **kwargs: Any) -> dict[str, Any]:
        """Build request payload, filtering None values."""
        from datetime import datetime

        def to_camel(s: str) -> str:
            parts = s.split("_")
            return parts[0] + "".join(p.title() for p in parts[1:])

        result: dict[str, Any] = {}
        for k, v in kwargs.items():
            if v is None:
                continue
            if isinstance(v, datetime):
                result[to_camel(k)] = v.isoformat()
            else:
                result[to_camel(k)] = v
        return result

    def get_whats_app_phone_numbers(
        self, *, status: str | None = None, profile_id: str | None = None
    ) -> dict[str, Any]:
        """List phone numbers"""
        params = self._build_params(
            status=status,
            profile_id=profile_id,
        )
        return self._client._get("/v1/whatsapp/phone-numbers", params=params)

    def purchase_whats_app_phone_number(self, profile_id: str) -> dict[str, Any]:
        """Purchase phone number"""
        payload = self._build_payload(
            profile_id=profile_id,
        )
        return self._client._post("/v1/whatsapp/phone-numbers/purchase", data=payload)

    def get_whats_app_phone_number(self, phone_number_id: str) -> dict[str, Any]:
        """Get phone number"""
        return self._client._get(f"/v1/whatsapp/phone-numbers/{phone_number_id}")

    def release_whats_app_phone_number(self, phone_number_id: str) -> dict[str, Any]:
        """Release phone number"""
        return self._client._delete(f"/v1/whatsapp/phone-numbers/{phone_number_id}")

    async def aget_whats_app_phone_numbers(
        self, *, status: str | None = None, profile_id: str | None = None
    ) -> dict[str, Any]:
        """List phone numbers (async)"""
        params = self._build_params(
            status=status,
            profile_id=profile_id,
        )
        return await self._client._aget("/v1/whatsapp/phone-numbers", params=params)

    async def apurchase_whats_app_phone_number(self, profile_id: str) -> dict[str, Any]:
        """Purchase phone number (async)"""
        payload = self._build_payload(
            profile_id=profile_id,
        )
        return await self._client._apost(
            "/v1/whatsapp/phone-numbers/purchase", data=payload
        )

    async def aget_whats_app_phone_number(self, phone_number_id: str) -> dict[str, Any]:
        """Get phone number (async)"""
        return await self._client._aget(f"/v1/whatsapp/phone-numbers/{phone_number_id}")

    async def arelease_whats_app_phone_number(
        self, phone_number_id: str
    ) -> dict[str, Any]:
        """Release phone number (async)"""
        return await self._client._adelete(
            f"/v1/whatsapp/phone-numbers/{phone_number_id}"
        )
