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

import datetime as dt
import typing

from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from ..core.request_options import RequestOptions
from ..types.create_usage_event_summary_response import CreateUsageEventSummaryResponse
from ..types.period import Period
from .raw_client import AsyncRawUsageEventsClient, RawUsageEventsClient
from .types.create_usage_event_summary_request_aggregation_type import CreateUsageEventSummaryRequestAggregationType

# this is used as the default value for optional parameters
OMIT = typing.cast(typing.Any, ...)


class UsageEventsClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawUsageEventsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawUsageEventsClient
        """
        return self._raw_client

    def create_usage_event(
        self,
        *,
        idempotency_key: str,
        event_name: str,
        subject_id: str,
        data: typing.Dict[str, typing.Optional[typing.Any]],
        timestamp: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Parameters
        ----------
        idempotency_key : str

        event_name : str

        subject_id : str

        data : typing.Dict[str, typing.Optional[typing.Any]]

        timestamp : typing.Optional[dt.datetime]

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        from lark import Lark

        client = Lark(
            api_key="YOUR_API_KEY",
        )
        client.usage_events.create_usage_event(
            idempotency_key="idempotency_key",
            event_name="event_name",
            subject_id="subject_id",
            data={"key": "value"},
        )
        """
        _response = self._raw_client.create_usage_event(
            idempotency_key=idempotency_key,
            event_name=event_name,
            subject_id=subject_id,
            data=data,
            timestamp=timestamp,
            request_options=request_options,
        )
        return _response.data

    def create_usage_event_summary(
        self,
        *,
        event_name: str,
        subject_id: str,
        period: Period,
        aggregation_type: CreateUsageEventSummaryRequestAggregationType,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateUsageEventSummaryResponse:
        """
        Parameters
        ----------
        event_name : str

        subject_id : str

        period : Period

        aggregation_type : CreateUsageEventSummaryRequestAggregationType

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

        Returns
        -------
        CreateUsageEventSummaryResponse
            Successful Response

        Examples
        --------
        from lark import Lark, Period

        client = Lark(
            api_key="YOUR_API_KEY",
        )
        client.usage_events.create_usage_event_summary(
            event_name="event_name",
            subject_id="subject_id",
            period=Period(
                start="2024-01-15T09:30:00Z",
                end="2024-01-15T09:30:00Z",
            ),
            aggregation_type="sum",
        )
        """
        _response = self._raw_client.create_usage_event_summary(
            event_name=event_name,
            subject_id=subject_id,
            period=period,
            aggregation_type=aggregation_type,
            request_options=request_options,
        )
        return _response.data


class AsyncUsageEventsClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawUsageEventsClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawUsageEventsClient
        """
        return self._raw_client

    async def create_usage_event(
        self,
        *,
        idempotency_key: str,
        event_name: str,
        subject_id: str,
        data: typing.Dict[str, typing.Optional[typing.Any]],
        timestamp: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> typing.Optional[typing.Any]:
        """
        Parameters
        ----------
        idempotency_key : str

        event_name : str

        subject_id : str

        data : typing.Dict[str, typing.Optional[typing.Any]]

        timestamp : typing.Optional[dt.datetime]

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

        Returns
        -------
        typing.Optional[typing.Any]
            Successful Response

        Examples
        --------
        import asyncio

        from lark import AsyncLark

        client = AsyncLark(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.usage_events.create_usage_event(
                idempotency_key="idempotency_key",
                event_name="event_name",
                subject_id="subject_id",
                data={"key": "value"},
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_usage_event(
            idempotency_key=idempotency_key,
            event_name=event_name,
            subject_id=subject_id,
            data=data,
            timestamp=timestamp,
            request_options=request_options,
        )
        return _response.data

    async def create_usage_event_summary(
        self,
        *,
        event_name: str,
        subject_id: str,
        period: Period,
        aggregation_type: CreateUsageEventSummaryRequestAggregationType,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> CreateUsageEventSummaryResponse:
        """
        Parameters
        ----------
        event_name : str

        subject_id : str

        period : Period

        aggregation_type : CreateUsageEventSummaryRequestAggregationType

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

        Returns
        -------
        CreateUsageEventSummaryResponse
            Successful Response

        Examples
        --------
        import asyncio

        from lark import AsyncLark, Period

        client = AsyncLark(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.usage_events.create_usage_event_summary(
                event_name="event_name",
                subject_id="subject_id",
                period=Period(
                    start="2024-01-15T09:30:00Z",
                    end="2024-01-15T09:30:00Z",
                ),
                aggregation_type="sum",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_usage_event_summary(
            event_name=event_name,
            subject_id=subject_id,
            period=period,
            aggregation_type=aggregation_type,
            request_options=request_options,
        )
        return _response.data
