"""
Analytics resource.
"""

from __future__ import annotations

from typing import TYPE_CHECKING, Any

if TYPE_CHECKING:
    from ..client.base import BaseClient


class AnalyticsResource:
    """Resource for analytics and usage stats."""

    def __init__(self, client: "BaseClient") -> None:
        self._client = client

    def get(
        self,
        *,
        page: int = 1,
        limit: int = 10,
        period: str | None = None,
    ) -> dict[str, Any]:
        """Get post analytics."""
        params: dict[str, Any] = {"page": page, "limit": limit}
        if period:
            params["period"] = period
        return self._client._get("/v1/analytics", params=params)

    def get_usage(self) -> dict[str, Any]:
        """Get plan usage statistics."""
        return self._client._get("/v1/usage-stats")

    # Async
    async def aget(self, **kwargs: Any) -> dict[str, Any]:
        params: dict[str, Any] = {"page": kwargs.get("page", 1), "limit": kwargs.get("limit", 10)}
        if kwargs.get("period"):
            params["period"] = kwargs["period"]
        return await self._client._aget("/v1/analytics", params=params)

    async def aget_usage(self) -> dict[str, Any]:
        return await self._client._aget("/v1/usage-stats")
