"""
Auto-generated twitter_engagement 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 TwitterEngagementResource:
    """
    twitter_engagement 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 retweet_post(self, account_id: str, tweet_id: str) -> dict[str, Any]:
        """Retweet a post"""
        payload = self._build_payload(
            account_id=account_id,
            tweet_id=tweet_id,
        )
        return self._client._post("/v1/twitter/retweet", data=payload)

    def undo_retweet(self, account_id: str, tweet_id: str) -> dict[str, Any]:
        """Undo retweet"""
        params = self._build_params(
            account_id=account_id,
            tweet_id=tweet_id,
        )
        return self._client._delete("/v1/twitter/retweet", params=params)

    def bookmark_post(self, account_id: str, tweet_id: str) -> dict[str, Any]:
        """Bookmark a tweet"""
        payload = self._build_payload(
            account_id=account_id,
            tweet_id=tweet_id,
        )
        return self._client._post("/v1/twitter/bookmark", data=payload)

    def remove_bookmark(self, account_id: str, tweet_id: str) -> dict[str, Any]:
        """Remove bookmark"""
        params = self._build_params(
            account_id=account_id,
            tweet_id=tweet_id,
        )
        return self._client._delete("/v1/twitter/bookmark", params=params)

    def follow_user(self, account_id: str, target_user_id: str) -> dict[str, Any]:
        """Follow a user"""
        payload = self._build_payload(
            account_id=account_id,
            target_user_id=target_user_id,
        )
        return self._client._post("/v1/twitter/follow", data=payload)

    def unfollow_user(self, account_id: str, target_user_id: str) -> dict[str, Any]:
        """Unfollow a user"""
        params = self._build_params(
            account_id=account_id,
            target_user_id=target_user_id,
        )
        return self._client._delete("/v1/twitter/follow", params=params)

    async def aretweet_post(self, account_id: str, tweet_id: str) -> dict[str, Any]:
        """Retweet a post (async)"""
        payload = self._build_payload(
            account_id=account_id,
            tweet_id=tweet_id,
        )
        return await self._client._apost("/v1/twitter/retweet", data=payload)

    async def aundo_retweet(self, account_id: str, tweet_id: str) -> dict[str, Any]:
        """Undo retweet (async)"""
        params = self._build_params(
            account_id=account_id,
            tweet_id=tweet_id,
        )
        return await self._client._adelete("/v1/twitter/retweet", params=params)

    async def abookmark_post(self, account_id: str, tweet_id: str) -> dict[str, Any]:
        """Bookmark a tweet (async)"""
        payload = self._build_payload(
            account_id=account_id,
            tweet_id=tweet_id,
        )
        return await self._client._apost("/v1/twitter/bookmark", data=payload)

    async def aremove_bookmark(self, account_id: str, tweet_id: str) -> dict[str, Any]:
        """Remove bookmark (async)"""
        params = self._build_params(
            account_id=account_id,
            tweet_id=tweet_id,
        )
        return await self._client._adelete("/v1/twitter/bookmark", params=params)

    async def afollow_user(
        self, account_id: str, target_user_id: str
    ) -> dict[str, Any]:
        """Follow a user (async)"""
        payload = self._build_payload(
            account_id=account_id,
            target_user_id=target_user_id,
        )
        return await self._client._apost("/v1/twitter/follow", data=payload)

    async def aunfollow_user(
        self, account_id: str, target_user_id: str
    ) -> dict[str, Any]:
        """Unfollow a user (async)"""
        params = self._build_params(
            account_id=account_id,
            target_user_id=target_user_id,
        )
        return await self._client._adelete("/v1/twitter/follow", params=params)
