"""
Auto-generated reddit 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 RedditResource:
    """
    Reddit search and feed.
    """

    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 search_reddit(
        self,
        account_id: str,
        q: str,
        *,
        subreddit: str | None = None,
        restrict_sr: str | None = None,
        sort: str | None = "new",
        limit: int | None = 25,
        after: str | None = None,
    ) -> dict[str, Any]:
        """Search Reddit posts via a connected account"""
        params = self._build_params(
            account_id=account_id,
            subreddit=subreddit,
            q=q,
            restrict_sr=restrict_sr,
            sort=sort,
            limit=limit,
            after=after,
        )
        return self._client._get("/v1/reddit/search", params=params)

    def get_reddit_feed(
        self,
        account_id: str,
        *,
        subreddit: str | None = None,
        sort: str | None = "hot",
        limit: int | None = 25,
        after: str | None = None,
        t: str | None = None,
    ) -> dict[str, Any]:
        """Fetch subreddit feed via a connected account"""
        params = self._build_params(
            account_id=account_id,
            subreddit=subreddit,
            sort=sort,
            limit=limit,
            after=after,
            t=t,
        )
        return self._client._get("/v1/reddit/feed", params=params)

    async def asearch_reddit(
        self,
        account_id: str,
        q: str,
        *,
        subreddit: str | None = None,
        restrict_sr: str | None = None,
        sort: str | None = "new",
        limit: int | None = 25,
        after: str | None = None,
    ) -> dict[str, Any]:
        """Search Reddit posts via a connected account (async)"""
        params = self._build_params(
            account_id=account_id,
            subreddit=subreddit,
            q=q,
            restrict_sr=restrict_sr,
            sort=sort,
            limit=limit,
            after=after,
        )
        return await self._client._aget("/v1/reddit/search", params=params)

    async def aget_reddit_feed(
        self,
        account_id: str,
        *,
        subreddit: str | None = None,
        sort: str | None = "hot",
        limit: int | None = 25,
        after: str | None = None,
        t: str | None = None,
    ) -> dict[str, Any]:
        """Fetch subreddit feed via a connected account (async)"""
        params = self._build_params(
            account_id=account_id,
            subreddit=subreddit,
            sort=sort,
            limit=limit,
            after=after,
            t=t,
        )
        return await self._client._aget("/v1/reddit/feed", params=params)
