"""
Auto-generated ads 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 datetime import datetime

    from ..client.base import BaseClient


class AdsResource:
    """
    ads 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_ads(self, *, page: int | None = 1, limit: int | None = 50, source: str | None = "zernio", status: str | None = None, platform: str | None = None, account_id: str | None = None, profile_id: str | None = None, campaign_id: str | None = None) -> dict[str, Any]:
        """List ads"""
        params = self._build_params(
            page=page,
            limit=limit,
            source=source,
            status=status,
            platform=platform,
            account_id=account_id,
            profile_id=profile_id,
            campaign_id=campaign_id,
        )
        return self._client._get("/v1/ads", params=params)

    def get_ad(self, ad_id: str) -> dict[str, Any]:
        """Get ad details"""
        return self._client._get(f"/v1/ads/{ad_id}")

    def update_ad(self, ad_id: str, *, status: str | None = None, budget: dict[str, Any] | None = None, targeting: dict[str, Any] | None = None, name: str | None = None) -> dict[str, Any]:
        """Update ad (pause/resume, budget, targeting, name)"""
        payload = self._build_payload(
            status=status,
            budget=budget,
            targeting=targeting,
            name=name,
        )
        return self._client._put(f"/v1/ads/{ad_id}", data=payload)

    def delete_ad(self, ad_id: str) -> dict[str, Any]:
        """Cancel an ad"""
        return self._client._delete(f"/v1/ads/{ad_id}")

    def get_ad_analytics(self, ad_id: str, *, breakdowns: str | None = None) -> dict[str, Any]:
        """Get ad analytics with daily breakdown"""
        params = self._build_params(
            breakdowns=breakdowns,
        )
        return self._client._get(f"/v1/ads/{ad_id}/analytics", params=params)

    def list_ad_accounts(self, account_id: str) -> dict[str, Any]:
        """List ad accounts for a social account"""
        params = self._build_params(
            account_id=account_id,
        )
        return self._client._get("/v1/ads/accounts", params=params)

    def boost_post(self, account_id: str, ad_account_id: str, name: str, goal: str, budget: dict[str, Any], *, post_id: str | None = None, platform_post_id: str | None = None, currency: str | None = None, schedule: dict[str, Any] | None = None, targeting: dict[str, Any] | None = None, bid_amount: float | None = None, tracking: dict[str, Any] | None = None, special_ad_categories: list[str] | None = None) -> dict[str, Any]:
        """Boost an existing post as a paid ad"""
        payload = self._build_payload(
            post_id=post_id,
            platform_post_id=platform_post_id,
            account_id=account_id,
            ad_account_id=ad_account_id,
            name=name,
            goal=goal,
            budget=budget,
            currency=currency,
            schedule=schedule,
            targeting=targeting,
            bid_amount=bid_amount,
            tracking=tracking,
            special_ad_categories=special_ad_categories,
        )
        return self._client._post("/v1/ads/boost", data=payload)

    def create_standalone_ad(self, account_id: str, ad_account_id: str, name: str, goal: str, budget_amount: float, budget_type: str, body: str, *, currency: str | None = None, headline: str | None = None, long_headline: str | None = None, call_to_action: str | None = None, link_url: str | None = None, image_url: str | None = None, business_name: str | None = None, board_id: str | None = None, countries: list[str] | None = None, age_min: int | None = None, age_max: int | None = None, interests: list[str] | None = None, end_date: datetime | str | None = None, audience_id: str | None = None, campaign_type: str | None = "display", keywords: list[str] | None = None, additional_headlines: list[str] | None = None, additional_descriptions: list[str] | None = None) -> dict[str, Any]:
        """Create a standalone ad with custom creative"""
        payload = self._build_payload(
            account_id=account_id,
            ad_account_id=ad_account_id,
            name=name,
            goal=goal,
            budget_amount=budget_amount,
            budget_type=budget_type,
            currency=currency,
            headline=headline,
            long_headline=long_headline,
            body=body,
            call_to_action=call_to_action,
            link_url=link_url,
            image_url=image_url,
            business_name=business_name,
            board_id=board_id,
            countries=countries,
            age_min=age_min,
            age_max=age_max,
            interests=interests,
            end_date=end_date,
            audience_id=audience_id,
            campaign_type=campaign_type,
            keywords=keywords,
            additional_headlines=additional_headlines,
            additional_descriptions=additional_descriptions,
        )
        return self._client._post("/v1/ads/create", data=payload)

    def sync_external_ads(self) -> dict[str, Any]:
        """Sync external ads from platform ad managers"""
        return self._client._post("/v1/ads/sync")

    def search_ad_interests(self, q: str, account_id: str) -> dict[str, Any]:
        """Search targeting interests"""
        params = self._build_params(
            q=q,
            account_id=account_id,
        )
        return self._client._get("/v1/ads/interests", params=params)

    async def alist_ads(self, *, page: int | None = 1, limit: int | None = 50, source: str | None = "zernio", status: str | None = None, platform: str | None = None, account_id: str | None = None, profile_id: str | None = None, campaign_id: str | None = None) -> dict[str, Any]:
        """List ads (async)"""
        params = self._build_params(
            page=page,
            limit=limit,
            source=source,
            status=status,
            platform=platform,
            account_id=account_id,
            profile_id=profile_id,
            campaign_id=campaign_id,
        )
        return await self._client._aget("/v1/ads", params=params)

    async def aget_ad(self, ad_id: str) -> dict[str, Any]:
        """Get ad details (async)"""
        return await self._client._aget(f"/v1/ads/{ad_id}")

    async def aupdate_ad(self, ad_id: str, *, status: str | None = None, budget: dict[str, Any] | None = None, targeting: dict[str, Any] | None = None, name: str | None = None) -> dict[str, Any]:
        """Update ad (pause/resume, budget, targeting, name) (async)"""
        payload = self._build_payload(
            status=status,
            budget=budget,
            targeting=targeting,
            name=name,
        )
        return await self._client._aput(f"/v1/ads/{ad_id}", data=payload)

    async def adelete_ad(self, ad_id: str) -> dict[str, Any]:
        """Cancel an ad (async)"""
        return await self._client._adelete(f"/v1/ads/{ad_id}")

    async def aget_ad_analytics(self, ad_id: str, *, breakdowns: str | None = None) -> dict[str, Any]:
        """Get ad analytics with daily breakdown (async)"""
        params = self._build_params(
            breakdowns=breakdowns,
        )
        return await self._client._aget(f"/v1/ads/{ad_id}/analytics", params=params)

    async def alist_ad_accounts(self, account_id: str) -> dict[str, Any]:
        """List ad accounts for a social account (async)"""
        params = self._build_params(
            account_id=account_id,
        )
        return await self._client._aget("/v1/ads/accounts", params=params)

    async def aboost_post(self, account_id: str, ad_account_id: str, name: str, goal: str, budget: dict[str, Any], *, post_id: str | None = None, platform_post_id: str | None = None, currency: str | None = None, schedule: dict[str, Any] | None = None, targeting: dict[str, Any] | None = None, bid_amount: float | None = None, tracking: dict[str, Any] | None = None, special_ad_categories: list[str] | None = None) -> dict[str, Any]:
        """Boost an existing post as a paid ad (async)"""
        payload = self._build_payload(
            post_id=post_id,
            platform_post_id=platform_post_id,
            account_id=account_id,
            ad_account_id=ad_account_id,
            name=name,
            goal=goal,
            budget=budget,
            currency=currency,
            schedule=schedule,
            targeting=targeting,
            bid_amount=bid_amount,
            tracking=tracking,
            special_ad_categories=special_ad_categories,
        )
        return await self._client._apost("/v1/ads/boost", data=payload)

    async def acreate_standalone_ad(self, account_id: str, ad_account_id: str, name: str, goal: str, budget_amount: float, budget_type: str, body: str, *, currency: str | None = None, headline: str | None = None, long_headline: str | None = None, call_to_action: str | None = None, link_url: str | None = None, image_url: str | None = None, business_name: str | None = None, board_id: str | None = None, countries: list[str] | None = None, age_min: int | None = None, age_max: int | None = None, interests: list[str] | None = None, end_date: datetime | str | None = None, audience_id: str | None = None, campaign_type: str | None = "display", keywords: list[str] | None = None, additional_headlines: list[str] | None = None, additional_descriptions: list[str] | None = None) -> dict[str, Any]:
        """Create a standalone ad with custom creative (async)"""
        payload = self._build_payload(
            account_id=account_id,
            ad_account_id=ad_account_id,
            name=name,
            goal=goal,
            budget_amount=budget_amount,
            budget_type=budget_type,
            currency=currency,
            headline=headline,
            long_headline=long_headline,
            body=body,
            call_to_action=call_to_action,
            link_url=link_url,
            image_url=image_url,
            business_name=business_name,
            board_id=board_id,
            countries=countries,
            age_min=age_min,
            age_max=age_max,
            interests=interests,
            end_date=end_date,
            audience_id=audience_id,
            campaign_type=campaign_type,
            keywords=keywords,
            additional_headlines=additional_headlines,
            additional_descriptions=additional_descriptions,
        )
        return await self._client._apost("/v1/ads/create", data=payload)

    async def async_external_ads(self) -> dict[str, Any]:
        """Sync external ads from platform ad managers (async)"""
        return await self._client._apost("/v1/ads/sync")

    async def asearch_ad_interests(self, q: str, account_id: str) -> dict[str, Any]:
        """Search targeting interests (async)"""
        params = self._build_params(
            q=q,
            account_id=account_id,
        )
        return await self._client._aget("/v1/ads/interests", params=params)
