# This file was auto-generated by Fern from our API Definition.

import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.api_key_daily_usage_response import ApiKeyDailyUsageResponse
from ..types.api_key_usage_summary import ApiKeyUsageSummary
from .raw_client import AsyncRawAnalyticsApiKeysClient, RawAnalyticsApiKeysClient


class AnalyticsApiKeysClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAnalyticsApiKeysClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> RawAnalyticsApiKeysClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        RawAnalyticsApiKeysClient
        """
        return self._raw_client

    def get_api_key_usage_summary(
        self,
        org_id: str,
        *,
        year: typing.Optional[int] = None,
        month: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyUsageSummary:
        """
        Get API Key Usage Summary.

        Returns summary statistics for API key usage only (programmatic access).
        This excludes bearer token usage from web applications.

        **Use Case:** API Management Pages - show only programmatic usage

        **Metrics:**
        - Total API key requests
        - Total cost in CHF
        - Average cost per request
        - Total synapses
        - Total neurons

        Parameters
        ----------
        org_id : str

        year : typing.Optional[int]
            Year

        month : typing.Optional[int]
            Month

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ApiKeyUsageSummary
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.analytics_api_keys.get_api_key_usage_summary(
            org_id="org_id",
        )
        """
        _response = self._raw_client.get_api_key_usage_summary(
            org_id, year=year, month=month, request_options=request_options
        )
        return _response.data

    def get_api_key_daily_usage(
        self,
        org_id: str,
        *,
        year: typing.Optional[int] = None,
        month: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyDailyUsageResponse:
        """
        Get API Key Daily Usage.

        Returns daily breakdown of API key usage only (programmatic access).
        This excludes bearer token usage from web applications.

        **Use Case:** API Management Pages - show daily API usage patterns

        **Metrics per Day:**
        - Request count
        - Total cost in CHF
        - Total synapses
        - Total neurons

        Parameters
        ----------
        org_id : str

        year : typing.Optional[int]
            Year

        month : typing.Optional[int]
            Month

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ApiKeyDailyUsageResponse
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.analytics_api_keys.get_api_key_daily_usage(
            org_id="org_id",
        )
        """
        _response = self._raw_client.get_api_key_daily_usage(
            org_id, year=year, month=month, request_options=request_options
        )
        return _response.data

    def get_top_api_keys(
        self,
        org_id: str,
        month: int,
        year: int,
        *,
        limit: typing.Optional[int] = None,
        period: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Any]:
        """
        Get top API keys by usage.

        Returns the top API keys ranked by total cost for the specified period.
        Always returns data even when no usage exists (empty list).

        Args:
            org_id: Organization ID
            month: Month (1-12)
            year: Year
            auth: Authenticated user
            db: Database session
            limit: Number of top keys to return (1-100)
            period: Period type (daily, monthly)

        Returns:
            Top API keys with usage metrics

        Parameters
        ----------
        org_id : str

        month : int

        year : int

        limit : typing.Optional[int]
            Number of top keys to return

        period : typing.Optional[str]
            Period type (daily, monthly)

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.Dict[str, typing.Any]
            Successful Response

        Examples
        --------
        from aitronos import Aitronos

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.analytics_api_keys.get_top_api_keys(
            org_id="org_id",
            month=1,
            year=1,
        )
        """
        _response = self._raw_client.get_top_api_keys(
            org_id, month, year, limit=limit, period=period, request_options=request_options
        )
        return _response.data


class AsyncAnalyticsApiKeysClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAnalyticsApiKeysClient(client_wrapper=client_wrapper)

    @property
    def with_raw_response(self) -> AsyncRawAnalyticsApiKeysClient:
        """
        Retrieves a raw implementation of this client that returns raw responses.

        Returns
        -------
        AsyncRawAnalyticsApiKeysClient
        """
        return self._raw_client

    async def get_api_key_usage_summary(
        self,
        org_id: str,
        *,
        year: typing.Optional[int] = None,
        month: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyUsageSummary:
        """
        Get API Key Usage Summary.

        Returns summary statistics for API key usage only (programmatic access).
        This excludes bearer token usage from web applications.

        **Use Case:** API Management Pages - show only programmatic usage

        **Metrics:**
        - Total API key requests
        - Total cost in CHF
        - Average cost per request
        - Total synapses
        - Total neurons

        Parameters
        ----------
        org_id : str

        year : typing.Optional[int]
            Year

        month : typing.Optional[int]
            Month

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ApiKeyUsageSummary
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.analytics_api_keys.get_api_key_usage_summary(
                org_id="org_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_api_key_usage_summary(
            org_id, year=year, month=month, request_options=request_options
        )
        return _response.data

    async def get_api_key_daily_usage(
        self,
        org_id: str,
        *,
        year: typing.Optional[int] = None,
        month: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyDailyUsageResponse:
        """
        Get API Key Daily Usage.

        Returns daily breakdown of API key usage only (programmatic access).
        This excludes bearer token usage from web applications.

        **Use Case:** API Management Pages - show daily API usage patterns

        **Metrics per Day:**
        - Request count
        - Total cost in CHF
        - Total synapses
        - Total neurons

        Parameters
        ----------
        org_id : str

        year : typing.Optional[int]
            Year

        month : typing.Optional[int]
            Month

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ApiKeyDailyUsageResponse
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.analytics_api_keys.get_api_key_daily_usage(
                org_id="org_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_api_key_daily_usage(
            org_id, year=year, month=month, request_options=request_options
        )
        return _response.data

    async def get_top_api_keys(
        self,
        org_id: str,
        month: int,
        year: int,
        *,
        limit: typing.Optional[int] = None,
        period: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Dict[str, typing.Any]:
        """
        Get top API keys by usage.

        Returns the top API keys ranked by total cost for the specified period.
        Always returns data even when no usage exists (empty list).

        Args:
            org_id: Organization ID
            month: Month (1-12)
            year: Year
            auth: Authenticated user
            db: Database session
            limit: Number of top keys to return (1-100)
            period: Period type (daily, monthly)

        Returns:
            Top API keys with usage metrics

        Parameters
        ----------
        org_id : str

        month : int

        year : int

        limit : typing.Optional[int]
            Number of top keys to return

        period : typing.Optional[str]
            Period type (daily, monthly)

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        typing.Dict[str, typing.Any]
            Successful Response

        Examples
        --------
        import asyncio

        from aitronos import AsyncAitronos

        client = AsyncAitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.analytics_api_keys.get_top_api_keys(
                org_id="org_id",
                month=1,
                year=1,
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_top_api_keys(
            org_id, month, year, limit=limit, period=period, request_options=request_options
        )
        return _response.data
