"""
Auto-generated gmb_media 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 GmbMediaResource:
    """
    gmb_media 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 list_google_business_media(
        self,
        account_id: str,
        *,
        page_size: int | None = 100,
        page_token: str | None = None,
    ) -> dict[str, Any]:
        """List Google Business Profile media (photos)"""
        params = self._build_params(
            page_size=page_size,
            page_token=page_token,
        )
        return self._client._get(f"/v1/accounts/{account_id}/gmb-media", params=params)

    def create_google_business_media(
        self,
        account_id: str,
        source_url: str,
        *,
        media_format: str | None = "PHOTO",
        description: str | None = None,
        category: str | None = None,
    ) -> dict[str, Any]:
        """Upload a photo to Google Business Profile"""
        payload = self._build_payload(
            source_url=source_url,
            media_format=media_format,
            description=description,
            category=category,
        )
        return self._client._post(f"/v1/accounts/{account_id}/gmb-media", data=payload)

    def delete_google_business_media(
        self, account_id: str, media_id: str
    ) -> dict[str, Any]:
        """Delete a photo from Google Business Profile"""
        params = self._build_params(
            media_id=media_id,
        )
        return self._client._delete(
            f"/v1/accounts/{account_id}/gmb-media", params=params
        )

    async def alist_google_business_media(
        self,
        account_id: str,
        *,
        page_size: int | None = 100,
        page_token: str | None = None,
    ) -> dict[str, Any]:
        """List Google Business Profile media (photos) (async)"""
        params = self._build_params(
            page_size=page_size,
            page_token=page_token,
        )
        return await self._client._aget(
            f"/v1/accounts/{account_id}/gmb-media", params=params
        )

    async def acreate_google_business_media(
        self,
        account_id: str,
        source_url: str,
        *,
        media_format: str | None = "PHOTO",
        description: str | None = None,
        category: str | None = None,
    ) -> dict[str, Any]:
        """Upload a photo to Google Business Profile (async)"""
        payload = self._build_payload(
            source_url=source_url,
            media_format=media_format,
            description=description,
            category=category,
        )
        return await self._client._apost(
            f"/v1/accounts/{account_id}/gmb-media", data=payload
        )

    async def adelete_google_business_media(
        self, account_id: str, media_id: str
    ) -> dict[str, Any]:
        """Delete a photo from Google Business Profile (async)"""
        params = self._build_params(
            media_id=media_id,
        )
        return await self._client._adelete(
            f"/v1/accounts/{account_id}/gmb-media", params=params
        )
