"""
Auto-generated tools 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 ToolsResource:
    """
    Media download and utility tools.
    """

    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 download_you_tube_video(
        self,
        url: str,
        *,
        action: str | None = "download",
        format: str | None = "video",
        quality: str | None = "hd",
        format_id: str | None = None,
    ) -> dict[str, Any]:
        """Download YouTube video"""
        params = self._build_params(
            url=url,
            action=action,
            format=format,
            quality=quality,
            format_id=format_id,
        )
        return self._client._get("/v1/tools/youtube/download", params=params)

    def get_you_tube_transcript(
        self, url: str, *, lang: str | None = "en"
    ) -> dict[str, Any]:
        """Get YouTube transcript"""
        params = self._build_params(
            url=url,
            lang=lang,
        )
        return self._client._get("/v1/tools/youtube/transcript", params=params)

    def download_instagram_media(self, url: str) -> dict[str, Any]:
        """Download Instagram media"""
        params = self._build_params(
            url=url,
        )
        return self._client._get("/v1/tools/instagram/download", params=params)

    def check_instagram_hashtags(self, hashtags: list[str]) -> dict[str, Any]:
        """Check IG hashtag bans"""
        payload = self._build_payload(
            hashtags=hashtags,
        )
        return self._client._post("/v1/tools/instagram/hashtag-checker", data=payload)

    def download_tik_tok_video(
        self, url: str, *, action: str | None = "download", format_id: str | None = None
    ) -> dict[str, Any]:
        """Download TikTok video"""
        params = self._build_params(
            url=url,
            action=action,
            format_id=format_id,
        )
        return self._client._get("/v1/tools/tiktok/download", params=params)

    def download_twitter_media(
        self, url: str, *, action: str | None = "download", format_id: str | None = None
    ) -> dict[str, Any]:
        """Download Twitter/X media"""
        params = self._build_params(
            url=url,
            action=action,
            format_id=format_id,
        )
        return self._client._get("/v1/tools/twitter/download", params=params)

    def download_facebook_video(self, url: str) -> dict[str, Any]:
        """Download Facebook video"""
        params = self._build_params(
            url=url,
        )
        return self._client._get("/v1/tools/facebook/download", params=params)

    def download_linked_in_video(self, url: str) -> dict[str, Any]:
        """Download LinkedIn video"""
        params = self._build_params(
            url=url,
        )
        return self._client._get("/v1/tools/linkedin/download", params=params)

    def download_bluesky_media(self, url: str) -> dict[str, Any]:
        """Download Bluesky media"""
        params = self._build_params(
            url=url,
        )
        return self._client._get("/v1/tools/bluesky/download", params=params)

    async def adownload_you_tube_video(
        self,
        url: str,
        *,
        action: str | None = "download",
        format: str | None = "video",
        quality: str | None = "hd",
        format_id: str | None = None,
    ) -> dict[str, Any]:
        """Download YouTube video (async)"""
        params = self._build_params(
            url=url,
            action=action,
            format=format,
            quality=quality,
            format_id=format_id,
        )
        return await self._client._aget("/v1/tools/youtube/download", params=params)

    async def aget_you_tube_transcript(
        self, url: str, *, lang: str | None = "en"
    ) -> dict[str, Any]:
        """Get YouTube transcript (async)"""
        params = self._build_params(
            url=url,
            lang=lang,
        )
        return await self._client._aget("/v1/tools/youtube/transcript", params=params)

    async def adownload_instagram_media(self, url: str) -> dict[str, Any]:
        """Download Instagram media (async)"""
        params = self._build_params(
            url=url,
        )
        return await self._client._aget("/v1/tools/instagram/download", params=params)

    async def acheck_instagram_hashtags(self, hashtags: list[str]) -> dict[str, Any]:
        """Check IG hashtag bans (async)"""
        payload = self._build_payload(
            hashtags=hashtags,
        )
        return await self._client._apost(
            "/v1/tools/instagram/hashtag-checker", data=payload
        )

    async def adownload_tik_tok_video(
        self, url: str, *, action: str | None = "download", format_id: str | None = None
    ) -> dict[str, Any]:
        """Download TikTok video (async)"""
        params = self._build_params(
            url=url,
            action=action,
            format_id=format_id,
        )
        return await self._client._aget("/v1/tools/tiktok/download", params=params)

    async def adownload_twitter_media(
        self, url: str, *, action: str | None = "download", format_id: str | None = None
    ) -> dict[str, Any]:
        """Download Twitter/X media (async)"""
        params = self._build_params(
            url=url,
            action=action,
            format_id=format_id,
        )
        return await self._client._aget("/v1/tools/twitter/download", params=params)

    async def adownload_facebook_video(self, url: str) -> dict[str, Any]:
        """Download Facebook video (async)"""
        params = self._build_params(
            url=url,
        )
        return await self._client._aget("/v1/tools/facebook/download", params=params)

    async def adownload_linked_in_video(self, url: str) -> dict[str, Any]:
        """Download LinkedIn video (async)"""
        params = self._build_params(
            url=url,
        )
        return await self._client._aget("/v1/tools/linkedin/download", params=params)

    async def adownload_bluesky_media(self, url: str) -> dict[str, Any]:
        """Download Bluesky media (async)"""
        params = self._build_params(
            url=url,
        )
        return await self._client._aget("/v1/tools/bluesky/download", params=params)
