"""
Auto-generated messages 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 MessagesResource:
    """
    messages 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_inbox_conversations(self, *, profile_id: str | None = None, platform: str | None = None, status: str | None = None, sort_order: str | None = "desc", limit: int | None = 50, cursor: str | None = None, account_id: str | None = None) -> dict[str, Any]:
        """List conversations"""
        params = self._build_params(
            profile_id=profile_id,
            platform=platform,
            status=status,
            sort_order=sort_order,
            limit=limit,
            cursor=cursor,
            account_id=account_id,
        )
        return self._client._get("/v1/inbox/conversations", params=params)

    def get_inbox_conversation(self, conversation_id: str, account_id: str) -> dict[str, Any]:
        """Get conversation"""
        params = self._build_params(
            account_id=account_id,
        )
        return self._client._get(f"/v1/inbox/conversations/{conversation_id}", params=params)

    def update_inbox_conversation(self, conversation_id: str, account_id: str, status: str) -> dict[str, Any]:
        """Update conversation status"""
        payload = self._build_payload(
            account_id=account_id,
            status=status,
        )
        return self._client._put(f"/v1/inbox/conversations/{conversation_id}", data=payload)

    def get_inbox_conversation_messages(self, conversation_id: str, account_id: str) -> dict[str, Any]:
        """List messages"""
        params = self._build_params(
            account_id=account_id,
        )
        return self._client._get(f"/v1/inbox/conversations/{conversation_id}/messages", params=params)

    def send_inbox_message(self, conversation_id: str, account_id: str, *, message: str | None = None, attachment_url: str | None = None, attachment_type: str | None = None, quick_replies: list[dict[str, Any]] | None = None, buttons: list[dict[str, Any]] | None = None, template: dict[str, Any] | None = None, reply_markup: dict[str, Any] | None = None, messaging_type: str | None = None, message_tag: str | None = None, reply_to: str | None = None) -> dict[str, Any]:
        """Send message"""
        payload = self._build_payload(
            account_id=account_id,
            message=message,
            attachment_url=attachment_url,
            attachment_type=attachment_type,
            quick_replies=quick_replies,
            buttons=buttons,
            template=template,
            reply_markup=reply_markup,
            messaging_type=messaging_type,
            message_tag=message_tag,
            reply_to=reply_to,
        )
        return self._client._post(f"/v1/inbox/conversations/{conversation_id}/messages", data=payload)

    def edit_inbox_message(self, conversation_id: str, message_id: str, account_id: str, *, text: str | None = None, reply_markup: dict[str, Any] | None = None) -> dict[str, Any]:
        """Edit message"""
        payload = self._build_payload(
            account_id=account_id,
            text=text,
            reply_markup=reply_markup,
        )
        return self._client._patch(f"/v1/inbox/conversations/{conversation_id}/messages/{message_id}", data=payload)

    def delete_inbox_message(self, conversation_id: str, message_id: str, account_id: str) -> dict[str, Any]:
        """Delete message"""
        params = self._build_params(
            account_id=account_id,
        )
        return self._client._delete(f"/v1/inbox/conversations/{conversation_id}/messages/{message_id}", params=params)

    def send_typing_indicator(self, conversation_id: str, account_id: str) -> dict[str, Any]:
        """Send typing indicator"""
        payload = self._build_payload(
            account_id=account_id,
        )
        return self._client._post(f"/v1/inbox/conversations/{conversation_id}/typing", data=payload)

    def add_message_reaction(self, conversation_id: str, message_id: str, account_id: str, emoji: str) -> dict[str, Any]:
        """Add reaction"""
        payload = self._build_payload(
            account_id=account_id,
            emoji=emoji,
        )
        return self._client._post(f"/v1/inbox/conversations/{conversation_id}/messages/{message_id}/reactions", data=payload)

    def remove_message_reaction(self, conversation_id: str, message_id: str, account_id: str) -> dict[str, Any]:
        """Remove reaction"""
        params = self._build_params(
            account_id=account_id,
        )
        return self._client._delete(f"/v1/inbox/conversations/{conversation_id}/messages/{message_id}/reactions", params=params)

    def upload_media_direct(self) -> dict[str, Any]:
        """Upload media file"""
        return self._client._post("/v1/media/upload-direct")

    async def alist_inbox_conversations(self, *, profile_id: str | None = None, platform: str | None = None, status: str | None = None, sort_order: str | None = "desc", limit: int | None = 50, cursor: str | None = None, account_id: str | None = None) -> dict[str, Any]:
        """List conversations (async)"""
        params = self._build_params(
            profile_id=profile_id,
            platform=platform,
            status=status,
            sort_order=sort_order,
            limit=limit,
            cursor=cursor,
            account_id=account_id,
        )
        return await self._client._aget("/v1/inbox/conversations", params=params)

    async def aget_inbox_conversation(self, conversation_id: str, account_id: str) -> dict[str, Any]:
        """Get conversation (async)"""
        params = self._build_params(
            account_id=account_id,
        )
        return await self._client._aget(f"/v1/inbox/conversations/{conversation_id}", params=params)

    async def aupdate_inbox_conversation(self, conversation_id: str, account_id: str, status: str) -> dict[str, Any]:
        """Update conversation status (async)"""
        payload = self._build_payload(
            account_id=account_id,
            status=status,
        )
        return await self._client._aput(f"/v1/inbox/conversations/{conversation_id}", data=payload)

    async def aget_inbox_conversation_messages(self, conversation_id: str, account_id: str) -> dict[str, Any]:
        """List messages (async)"""
        params = self._build_params(
            account_id=account_id,
        )
        return await self._client._aget(f"/v1/inbox/conversations/{conversation_id}/messages", params=params)

    async def asend_inbox_message(self, conversation_id: str, account_id: str, *, message: str | None = None, attachment_url: str | None = None, attachment_type: str | None = None, quick_replies: list[dict[str, Any]] | None = None, buttons: list[dict[str, Any]] | None = None, template: dict[str, Any] | None = None, reply_markup: dict[str, Any] | None = None, messaging_type: str | None = None, message_tag: str | None = None, reply_to: str | None = None) -> dict[str, Any]:
        """Send message (async)"""
        payload = self._build_payload(
            account_id=account_id,
            message=message,
            attachment_url=attachment_url,
            attachment_type=attachment_type,
            quick_replies=quick_replies,
            buttons=buttons,
            template=template,
            reply_markup=reply_markup,
            messaging_type=messaging_type,
            message_tag=message_tag,
            reply_to=reply_to,
        )
        return await self._client._apost(f"/v1/inbox/conversations/{conversation_id}/messages", data=payload)

    async def aedit_inbox_message(self, conversation_id: str, message_id: str, account_id: str, *, text: str | None = None, reply_markup: dict[str, Any] | None = None) -> dict[str, Any]:
        """Edit message (async)"""
        payload = self._build_payload(
            account_id=account_id,
            text=text,
            reply_markup=reply_markup,
        )
        return await self._client._apatch(f"/v1/inbox/conversations/{conversation_id}/messages/{message_id}", data=payload)

    async def adelete_inbox_message(self, conversation_id: str, message_id: str, account_id: str) -> dict[str, Any]:
        """Delete message (async)"""
        params = self._build_params(
            account_id=account_id,
        )
        return await self._client._adelete(f"/v1/inbox/conversations/{conversation_id}/messages/{message_id}", params=params)

    async def asend_typing_indicator(self, conversation_id: str, account_id: str) -> dict[str, Any]:
        """Send typing indicator (async)"""
        payload = self._build_payload(
            account_id=account_id,
        )
        return await self._client._apost(f"/v1/inbox/conversations/{conversation_id}/typing", data=payload)

    async def aadd_message_reaction(self, conversation_id: str, message_id: str, account_id: str, emoji: str) -> dict[str, Any]:
        """Add reaction (async)"""
        payload = self._build_payload(
            account_id=account_id,
            emoji=emoji,
        )
        return await self._client._apost(f"/v1/inbox/conversations/{conversation_id}/messages/{message_id}/reactions", data=payload)

    async def aremove_message_reaction(self, conversation_id: str, message_id: str, account_id: str) -> dict[str, Any]:
        """Remove reaction (async)"""
        params = self._build_params(
            account_id=account_id,
        )
        return await self._client._adelete(f"/v1/inbox/conversations/{conversation_id}/messages/{message_id}/reactions", params=params)

    async def aupload_media_direct(self) -> dict[str, Any]:
        """Upload media file (async)"""
        return await self._client._apost("/v1/media/upload-direct")
