"""
Auto-generated validate 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 ValidateResource:
    """
    validate 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 validate_post_length(self, text: str) -> dict[str, Any]:
        """Validate post character count"""
        payload = self._build_payload(
            text=text,
        )
        return self._client._post("/v1/tools/validate/post-length", data=payload)

    def validate_post(
        self,
        platforms: list[dict[str, Any]],
        *,
        content: str | None = None,
        media_items: list[dict[str, Any]] | None = None,
    ) -> dict[str, Any]:
        """Validate post content"""
        payload = self._build_payload(
            content=content,
            platforms=platforms,
            media_items=media_items,
        )
        return self._client._post("/v1/tools/validate/post", data=payload)

    def validate_media(self, url: str) -> dict[str, Any]:
        """Validate media URL"""
        payload = self._build_payload(
            url=url,
        )
        return self._client._post("/v1/tools/validate/media", data=payload)

    def validate_subreddit(self, name: str) -> dict[str, Any]:
        """Check subreddit existence"""
        params = self._build_params(
            name=name,
        )
        return self._client._get("/v1/tools/validate/subreddit", params=params)

    async def avalidate_post_length(self, text: str) -> dict[str, Any]:
        """Validate post character count (async)"""
        payload = self._build_payload(
            text=text,
        )
        return await self._client._apost("/v1/tools/validate/post-length", data=payload)

    async def avalidate_post(
        self,
        platforms: list[dict[str, Any]],
        *,
        content: str | None = None,
        media_items: list[dict[str, Any]] | None = None,
    ) -> dict[str, Any]:
        """Validate post content (async)"""
        payload = self._build_payload(
            content=content,
            platforms=platforms,
            media_items=media_items,
        )
        return await self._client._apost("/v1/tools/validate/post", data=payload)

    async def avalidate_media(self, url: str) -> dict[str, Any]:
        """Validate media URL (async)"""
        payload = self._build_payload(
            url=url,
        )
        return await self._client._apost("/v1/tools/validate/media", data=payload)

    async def avalidate_subreddit(self, name: str) -> dict[str, Any]:
        """Check subreddit existence (async)"""
        params = self._build_params(
            name=name,
        )
        return await self._client._aget("/v1/tools/validate/subreddit", params=params)
