"""
Auto-generated analytics 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 AnalyticsResource:
    """
    Get performance metrics and analytics.
    """

    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 get_analytics(
        self,
        *,
        post_id: str | None = None,
        platform: str | None = None,
        profile_id: str | None = None,
        source: str | None = "all",
        from_date: str | None = None,
        to_date: str | None = None,
        limit: int | None = 50,
        page: int | None = 1,
        sort_by: str | None = "date",
        order: str | None = "desc",
    ) -> dict[str, Any]:
        """Get post analytics"""
        params = self._build_params(
            post_id=post_id,
            platform=platform,
            profile_id=profile_id,
            source=source,
            from_date=from_date,
            to_date=to_date,
            limit=limit,
            page=page,
            sort_by=sort_by,
            order=order,
        )
        return self._client._get("/v1/analytics", params=params)

    def get_you_tube_daily_views(
        self,
        video_id: str,
        account_id: str,
        *,
        start_date: str | None = None,
        end_date: str | None = None,
    ) -> dict[str, Any]:
        """Get YouTube daily views"""
        params = self._build_params(
            video_id=video_id,
            account_id=account_id,
            start_date=start_date,
            end_date=end_date,
        )
        return self._client._get("/v1/analytics/youtube/daily-views", params=params)

    def get_daily_metrics(
        self,
        *,
        platform: str | None = None,
        profile_id: str | None = None,
        from_date: datetime | str | None = None,
        to_date: datetime | str | None = None,
        source: str | None = "all",
    ) -> dict[str, Any]:
        """Get daily aggregated metrics"""
        params = self._build_params(
            platform=platform,
            profile_id=profile_id,
            from_date=from_date,
            to_date=to_date,
            source=source,
        )
        return self._client._get("/v1/analytics/daily-metrics", params=params)

    def get_best_time_to_post(
        self,
        *,
        platform: str | None = None,
        profile_id: str | None = None,
        source: str | None = "all",
    ) -> dict[str, Any]:
        """Get best times to post"""
        params = self._build_params(
            platform=platform,
            profile_id=profile_id,
            source=source,
        )
        return self._client._get("/v1/analytics/best-time", params=params)

    def get_content_decay(
        self,
        *,
        platform: str | None = None,
        profile_id: str | None = None,
        source: str | None = "all",
    ) -> dict[str, Any]:
        """Get content performance decay"""
        params = self._build_params(
            platform=platform,
            profile_id=profile_id,
            source=source,
        )
        return self._client._get("/v1/analytics/content-decay", params=params)

    def get_posting_frequency(
        self,
        *,
        platform: str | None = None,
        profile_id: str | None = None,
        source: str | None = "all",
    ) -> dict[str, Any]:
        """Get posting frequency vs engagement"""
        params = self._build_params(
            platform=platform,
            profile_id=profile_id,
            source=source,
        )
        return self._client._get("/v1/analytics/posting-frequency", params=params)

    def get_post_timeline(
        self,
        post_id: str,
        *,
        from_date: datetime | str | None = None,
        to_date: datetime | str | None = None,
    ) -> dict[str, Any]:
        """Get post analytics timeline"""
        params = self._build_params(
            post_id=post_id,
            from_date=from_date,
            to_date=to_date,
        )
        return self._client._get("/v1/analytics/post-timeline", params=params)

    def get_linked_in_aggregate_analytics(
        self,
        account_id: str,
        *,
        aggregation: str | None = "TOTAL",
        start_date: str | None = None,
        end_date: str | None = None,
        metrics: str | None = None,
    ) -> dict[str, Any]:
        """Get LinkedIn aggregate stats"""
        params = self._build_params(
            aggregation=aggregation,
            start_date=start_date,
            end_date=end_date,
            metrics=metrics,
        )
        return self._client._get(
            f"/v1/accounts/{account_id}/linkedin-aggregate-analytics", params=params
        )

    def get_linked_in_post_analytics(self, account_id: str, urn: str) -> dict[str, Any]:
        """Get LinkedIn post stats"""
        params = self._build_params(
            urn=urn,
        )
        return self._client._get(
            f"/v1/accounts/{account_id}/linkedin-post-analytics", params=params
        )

    def get_linked_in_post_reactions(
        self,
        account_id: str,
        urn: str,
        *,
        limit: int | None = 25,
        cursor: str | None = None,
    ) -> dict[str, Any]:
        """Get LinkedIn post reactions"""
        params = self._build_params(
            urn=urn,
            limit=limit,
            cursor=cursor,
        )
        return self._client._get(
            f"/v1/accounts/{account_id}/linkedin-post-reactions", params=params
        )

    async def aget_analytics(
        self,
        *,
        post_id: str | None = None,
        platform: str | None = None,
        profile_id: str | None = None,
        source: str | None = "all",
        from_date: str | None = None,
        to_date: str | None = None,
        limit: int | None = 50,
        page: int | None = 1,
        sort_by: str | None = "date",
        order: str | None = "desc",
    ) -> dict[str, Any]:
        """Get post analytics (async)"""
        params = self._build_params(
            post_id=post_id,
            platform=platform,
            profile_id=profile_id,
            source=source,
            from_date=from_date,
            to_date=to_date,
            limit=limit,
            page=page,
            sort_by=sort_by,
            order=order,
        )
        return await self._client._aget("/v1/analytics", params=params)

    async def aget_you_tube_daily_views(
        self,
        video_id: str,
        account_id: str,
        *,
        start_date: str | None = None,
        end_date: str | None = None,
    ) -> dict[str, Any]:
        """Get YouTube daily views (async)"""
        params = self._build_params(
            video_id=video_id,
            account_id=account_id,
            start_date=start_date,
            end_date=end_date,
        )
        return await self._client._aget(
            "/v1/analytics/youtube/daily-views", params=params
        )

    async def aget_daily_metrics(
        self,
        *,
        platform: str | None = None,
        profile_id: str | None = None,
        from_date: datetime | str | None = None,
        to_date: datetime | str | None = None,
        source: str | None = "all",
    ) -> dict[str, Any]:
        """Get daily aggregated metrics (async)"""
        params = self._build_params(
            platform=platform,
            profile_id=profile_id,
            from_date=from_date,
            to_date=to_date,
            source=source,
        )
        return await self._client._aget("/v1/analytics/daily-metrics", params=params)

    async def aget_best_time_to_post(
        self,
        *,
        platform: str | None = None,
        profile_id: str | None = None,
        source: str | None = "all",
    ) -> dict[str, Any]:
        """Get best times to post (async)"""
        params = self._build_params(
            platform=platform,
            profile_id=profile_id,
            source=source,
        )
        return await self._client._aget("/v1/analytics/best-time", params=params)

    async def aget_content_decay(
        self,
        *,
        platform: str | None = None,
        profile_id: str | None = None,
        source: str | None = "all",
    ) -> dict[str, Any]:
        """Get content performance decay (async)"""
        params = self._build_params(
            platform=platform,
            profile_id=profile_id,
            source=source,
        )
        return await self._client._aget("/v1/analytics/content-decay", params=params)

    async def aget_posting_frequency(
        self,
        *,
        platform: str | None = None,
        profile_id: str | None = None,
        source: str | None = "all",
    ) -> dict[str, Any]:
        """Get posting frequency vs engagement (async)"""
        params = self._build_params(
            platform=platform,
            profile_id=profile_id,
            source=source,
        )
        return await self._client._aget(
            "/v1/analytics/posting-frequency", params=params
        )

    async def aget_post_timeline(
        self,
        post_id: str,
        *,
        from_date: datetime | str | None = None,
        to_date: datetime | str | None = None,
    ) -> dict[str, Any]:
        """Get post analytics timeline (async)"""
        params = self._build_params(
            post_id=post_id,
            from_date=from_date,
            to_date=to_date,
        )
        return await self._client._aget("/v1/analytics/post-timeline", params=params)

    async def aget_linked_in_aggregate_analytics(
        self,
        account_id: str,
        *,
        aggregation: str | None = "TOTAL",
        start_date: str | None = None,
        end_date: str | None = None,
        metrics: str | None = None,
    ) -> dict[str, Any]:
        """Get LinkedIn aggregate stats (async)"""
        params = self._build_params(
            aggregation=aggregation,
            start_date=start_date,
            end_date=end_date,
            metrics=metrics,
        )
        return await self._client._aget(
            f"/v1/accounts/{account_id}/linkedin-aggregate-analytics", params=params
        )

    async def aget_linked_in_post_analytics(
        self, account_id: str, urn: str
    ) -> dict[str, Any]:
        """Get LinkedIn post stats (async)"""
        params = self._build_params(
            urn=urn,
        )
        return await self._client._aget(
            f"/v1/accounts/{account_id}/linkedin-post-analytics", params=params
        )

    async def aget_linked_in_post_reactions(
        self,
        account_id: str,
        urn: str,
        *,
        limit: int | None = 25,
        cursor: str | None = None,
    ) -> dict[str, Any]:
        """Get LinkedIn post reactions (async)"""
        params = self._build_params(
            urn=urn,
            limit=limit,
            cursor=cursor,
        )
        return await self._client._aget(
            f"/v1/accounts/{account_id}/linkedin-post-reactions", params=params
        )
