# 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.usage_detail_report_response import UsageDetailReportResponse
from ..types.usage_event_list_response import UsageEventListResponse
from .raw_client import AsyncRawAnalyticsUsageDetailClient, RawAnalyticsUsageDetailClient


class AnalyticsUsageDetailClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAnalyticsUsageDetailClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAnalyticsUsageDetailClient
        """
        return self._raw_client

    def get_usage_detail_report(
        self,
        org_id: str,
        *,
        year: typing.Optional[int] = None,
        month: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UsageDetailReportResponse:
        """
        Multi-dimensional cost breakdown report for an organization.

        Returns cost and usage broken down by model, API key, priority level,
        Flowplate workflow source, and daily totals for the period.

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

        year : typing.Optional[int]
            Year (defaults to current)

        month : typing.Optional[int]
            Month (defaults to current)

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

        Returns
        -------
        UsageDetailReportResponse
            Successful Response

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

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

    def get_usage_events(
        self,
        org_id: str,
        *,
        year: typing.Optional[int] = None,
        month: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        model: typing.Optional[str] = None,
        api_key_id: typing.Optional[str] = None,
        priority: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UsageEventListResponse:
        """
        Paginated list of individual usage events with optional filters.

        Supports filtering by model, API key, and priority. Use limit + offset
        for pagination; the response includes total_count and has_more.

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

        year : typing.Optional[int]
            Year (defaults to current)

        month : typing.Optional[int]
            Month (defaults to current)

        limit : typing.Optional[int]
            Events per page

        offset : typing.Optional[int]
            Pagination offset

        model : typing.Optional[str]
            Filter by model identifier

        api_key_id : typing.Optional[str]
            Filter by API key ID

        priority : typing.Optional[str]
            Filter by priority: low, default, high

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

        Returns
        -------
        UsageEventListResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.analytics_usage_detail.get_usage_events(
            org_id="org_id",
        )
        """
        _response = self._raw_client.get_usage_events(
            org_id,
            year=year,
            month=month,
            limit=limit,
            offset=offset,
            model=model,
            api_key_id=api_key_id,
            priority=priority,
            request_options=request_options,
        )
        return _response.data


class AsyncAnalyticsUsageDetailClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAnalyticsUsageDetailClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAnalyticsUsageDetailClient
        """
        return self._raw_client

    async def get_usage_detail_report(
        self,
        org_id: str,
        *,
        year: typing.Optional[int] = None,
        month: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UsageDetailReportResponse:
        """
        Multi-dimensional cost breakdown report for an organization.

        Returns cost and usage broken down by model, API key, priority level,
        Flowplate workflow source, and daily totals for the period.

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

        year : typing.Optional[int]
            Year (defaults to current)

        month : typing.Optional[int]
            Month (defaults to current)

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

        Returns
        -------
        UsageDetailReportResponse
            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_usage_detail.get_usage_detail_report(
                org_id="org_id",
            )


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

    async def get_usage_events(
        self,
        org_id: str,
        *,
        year: typing.Optional[int] = None,
        month: typing.Optional[int] = None,
        limit: typing.Optional[int] = None,
        offset: typing.Optional[int] = None,
        model: typing.Optional[str] = None,
        api_key_id: typing.Optional[str] = None,
        priority: typing.Optional[str] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> UsageEventListResponse:
        """
        Paginated list of individual usage events with optional filters.

        Supports filtering by model, API key, and priority. Use limit + offset
        for pagination; the response includes total_count and has_more.

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

        year : typing.Optional[int]
            Year (defaults to current)

        month : typing.Optional[int]
            Month (defaults to current)

        limit : typing.Optional[int]
            Events per page

        offset : typing.Optional[int]
            Pagination offset

        model : typing.Optional[str]
            Filter by model identifier

        api_key_id : typing.Optional[str]
            Filter by API key ID

        priority : typing.Optional[str]
            Filter by priority: low, default, high

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

        Returns
        -------
        UsageEventListResponse
            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_usage_detail.get_usage_events(
                org_id="org_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_usage_events(
            org_id,
            year=year,
            month=month,
            limit=limit,
            offset=offset,
            model=model,
            api_key_id=api_key_id,
            priority=priority,
            request_options=request_options,
        )
        return _response.data
