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

import typing
from json.decoder import JSONDecodeError

from .....core.api_error import ApiError
from .....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper
from .....core.http_response import AsyncHttpResponse, HttpResponse
from .....core.jsonable_encoder import jsonable_encoder
from .....core.pydantic_utilities import parse_obj_as
from .....core.request_options import RequestOptions
from .....errors.bad_request_error import BadRequestError
from .....types.usage_v1response import UsageV1Response
from .types.usage_get_request_deployment import UsageGetRequestDeployment
from .types.usage_get_request_endpoint import UsageGetRequestEndpoint
from .types.usage_get_request_method import UsageGetRequestMethod


class RawUsageClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._client_wrapper = client_wrapper

    def get(
        self,
        project_id: str,
        *,
        start: typing.Optional[str] = None,
        end: typing.Optional[str] = None,
        accessor: typing.Optional[str] = None,
        alternatives: typing.Optional[bool] = None,
        callback_method: typing.Optional[bool] = None,
        callback: typing.Optional[bool] = None,
        channels: typing.Optional[bool] = None,
        custom_intent_mode: typing.Optional[bool] = None,
        custom_intent: typing.Optional[bool] = None,
        custom_topic_mode: typing.Optional[bool] = None,
        custom_topic: typing.Optional[bool] = None,
        deployment: typing.Optional[UsageGetRequestDeployment] = None,
        detect_entities: typing.Optional[bool] = None,
        detect_language: typing.Optional[bool] = None,
        diarize: typing.Optional[bool] = None,
        dictation: typing.Optional[bool] = None,
        encoding: typing.Optional[bool] = None,
        endpoint: typing.Optional[UsageGetRequestEndpoint] = None,
        extra: typing.Optional[bool] = None,
        filler_words: typing.Optional[bool] = None,
        intents: typing.Optional[bool] = None,
        keyterm: typing.Optional[bool] = None,
        keywords: typing.Optional[bool] = None,
        language: typing.Optional[bool] = None,
        measurements: typing.Optional[bool] = None,
        method: typing.Optional[UsageGetRequestMethod] = None,
        model: typing.Optional[str] = None,
        multichannel: typing.Optional[bool] = None,
        numerals: typing.Optional[bool] = None,
        paragraphs: typing.Optional[bool] = None,
        profanity_filter: typing.Optional[bool] = None,
        punctuate: typing.Optional[bool] = None,
        redact: typing.Optional[bool] = None,
        replace: typing.Optional[bool] = None,
        sample_rate: typing.Optional[bool] = None,
        search: typing.Optional[bool] = None,
        sentiment: typing.Optional[bool] = None,
        smart_format: typing.Optional[bool] = None,
        summarize: typing.Optional[bool] = None,
        tag: typing.Optional[str] = None,
        topics: typing.Optional[bool] = None,
        utt_split: typing.Optional[bool] = None,
        utterances: typing.Optional[bool] = None,
        version: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> HttpResponse[UsageV1Response]:
        """
        Retrieves the usage for a specific project. Use Get Project Usage Breakdown for a more comprehensive usage summary.

        Parameters
        ----------
        project_id : str
            The unique identifier of the project

        start : typing.Optional[str]
            Start date of the requested date range. Format accepted is YYYY-MM-DD

        end : typing.Optional[str]
            End date of the requested date range. Format accepted is YYYY-MM-DD

        accessor : typing.Optional[str]
            Filter for requests where a specific accessor was used

        alternatives : typing.Optional[bool]
            Filter for requests where alternatives were used

        callback_method : typing.Optional[bool]
            Filter for requests where callback method was used

        callback : typing.Optional[bool]
            Filter for requests where callback was used

        channels : typing.Optional[bool]
            Filter for requests where channels were used

        custom_intent_mode : typing.Optional[bool]
            Filter for requests where custom intent mode was used

        custom_intent : typing.Optional[bool]
            Filter for requests where custom intent was used

        custom_topic_mode : typing.Optional[bool]
            Filter for requests where custom topic mode was used

        custom_topic : typing.Optional[bool]
            Filter for requests where custom topic was used

        deployment : typing.Optional[UsageGetRequestDeployment]
            Filter for requests where a specific deployment was used

        detect_entities : typing.Optional[bool]
            Filter for requests where detect entities was used

        detect_language : typing.Optional[bool]
            Filter for requests where detect language was used

        diarize : typing.Optional[bool]
            Filter for requests where diarize was used

        dictation : typing.Optional[bool]
            Filter for requests where dictation was used

        encoding : typing.Optional[bool]
            Filter for requests where encoding was used

        endpoint : typing.Optional[UsageGetRequestEndpoint]
            Filter for requests where a specific endpoint was used

        extra : typing.Optional[bool]
            Filter for requests where extra was used

        filler_words : typing.Optional[bool]
            Filter for requests where filler words was used

        intents : typing.Optional[bool]
            Filter for requests where intents was used

        keyterm : typing.Optional[bool]
            Filter for requests where keyterm was used

        keywords : typing.Optional[bool]
            Filter for requests where keywords was used

        language : typing.Optional[bool]
            Filter for requests where language was used

        measurements : typing.Optional[bool]
            Filter for requests where measurements were used

        method : typing.Optional[UsageGetRequestMethod]
            Filter for requests where a specific method was used

        model : typing.Optional[str]
            Filter for requests where a specific model uuid was used

        multichannel : typing.Optional[bool]
            Filter for requests where multichannel was used

        numerals : typing.Optional[bool]
            Filter for requests where numerals were used

        paragraphs : typing.Optional[bool]
            Filter for requests where paragraphs were used

        profanity_filter : typing.Optional[bool]
            Filter for requests where profanity filter was used

        punctuate : typing.Optional[bool]
            Filter for requests where punctuate was used

        redact : typing.Optional[bool]
            Filter for requests where redact was used

        replace : typing.Optional[bool]
            Filter for requests where replace was used

        sample_rate : typing.Optional[bool]
            Filter for requests where sample rate was used

        search : typing.Optional[bool]
            Filter for requests where search was used

        sentiment : typing.Optional[bool]
            Filter for requests where sentiment was used

        smart_format : typing.Optional[bool]
            Filter for requests where smart format was used

        summarize : typing.Optional[bool]
            Filter for requests where summarize was used

        tag : typing.Optional[str]
            Filter for requests where a specific tag was used

        topics : typing.Optional[bool]
            Filter for requests where topics was used

        utt_split : typing.Optional[bool]
            Filter for requests where utt split was used

        utterances : typing.Optional[bool]
            Filter for requests where utterances was used

        version : typing.Optional[bool]
            Filter for requests where version was used

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

        Returns
        -------
        HttpResponse[UsageV1Response]
            A specific request for a specific project
        """
        _response = self._client_wrapper.httpx_client.request(
            f"v1/projects/{jsonable_encoder(project_id)}/usage",
            base_url=self._client_wrapper.get_environment().base,
            method="GET",
            params={
                "start": start,
                "end": end,
                "accessor": accessor,
                "alternatives": alternatives,
                "callback_method": callback_method,
                "callback": callback,
                "channels": channels,
                "custom_intent_mode": custom_intent_mode,
                "custom_intent": custom_intent,
                "custom_topic_mode": custom_topic_mode,
                "custom_topic": custom_topic,
                "deployment": deployment,
                "detect_entities": detect_entities,
                "detect_language": detect_language,
                "diarize": diarize,
                "dictation": dictation,
                "encoding": encoding,
                "endpoint": endpoint,
                "extra": extra,
                "filler_words": filler_words,
                "intents": intents,
                "keyterm": keyterm,
                "keywords": keywords,
                "language": language,
                "measurements": measurements,
                "method": method,
                "model": model,
                "multichannel": multichannel,
                "numerals": numerals,
                "paragraphs": paragraphs,
                "profanity_filter": profanity_filter,
                "punctuate": punctuate,
                "redact": redact,
                "replace": replace,
                "sample_rate": sample_rate,
                "search": search,
                "sentiment": sentiment,
                "smart_format": smart_format,
                "summarize": summarize,
                "tag": tag,
                "topics": topics,
                "utt_split": utt_split,
                "utterances": utterances,
                "version": version,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    UsageV1Response,
                    parse_obj_as(
                        type_=UsageV1Response,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return HttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)


class AsyncRawUsageClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._client_wrapper = client_wrapper

    async def get(
        self,
        project_id: str,
        *,
        start: typing.Optional[str] = None,
        end: typing.Optional[str] = None,
        accessor: typing.Optional[str] = None,
        alternatives: typing.Optional[bool] = None,
        callback_method: typing.Optional[bool] = None,
        callback: typing.Optional[bool] = None,
        channels: typing.Optional[bool] = None,
        custom_intent_mode: typing.Optional[bool] = None,
        custom_intent: typing.Optional[bool] = None,
        custom_topic_mode: typing.Optional[bool] = None,
        custom_topic: typing.Optional[bool] = None,
        deployment: typing.Optional[UsageGetRequestDeployment] = None,
        detect_entities: typing.Optional[bool] = None,
        detect_language: typing.Optional[bool] = None,
        diarize: typing.Optional[bool] = None,
        dictation: typing.Optional[bool] = None,
        encoding: typing.Optional[bool] = None,
        endpoint: typing.Optional[UsageGetRequestEndpoint] = None,
        extra: typing.Optional[bool] = None,
        filler_words: typing.Optional[bool] = None,
        intents: typing.Optional[bool] = None,
        keyterm: typing.Optional[bool] = None,
        keywords: typing.Optional[bool] = None,
        language: typing.Optional[bool] = None,
        measurements: typing.Optional[bool] = None,
        method: typing.Optional[UsageGetRequestMethod] = None,
        model: typing.Optional[str] = None,
        multichannel: typing.Optional[bool] = None,
        numerals: typing.Optional[bool] = None,
        paragraphs: typing.Optional[bool] = None,
        profanity_filter: typing.Optional[bool] = None,
        punctuate: typing.Optional[bool] = None,
        redact: typing.Optional[bool] = None,
        replace: typing.Optional[bool] = None,
        sample_rate: typing.Optional[bool] = None,
        search: typing.Optional[bool] = None,
        sentiment: typing.Optional[bool] = None,
        smart_format: typing.Optional[bool] = None,
        summarize: typing.Optional[bool] = None,
        tag: typing.Optional[str] = None,
        topics: typing.Optional[bool] = None,
        utt_split: typing.Optional[bool] = None,
        utterances: typing.Optional[bool] = None,
        version: typing.Optional[bool] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> AsyncHttpResponse[UsageV1Response]:
        """
        Retrieves the usage for a specific project. Use Get Project Usage Breakdown for a more comprehensive usage summary.

        Parameters
        ----------
        project_id : str
            The unique identifier of the project

        start : typing.Optional[str]
            Start date of the requested date range. Format accepted is YYYY-MM-DD

        end : typing.Optional[str]
            End date of the requested date range. Format accepted is YYYY-MM-DD

        accessor : typing.Optional[str]
            Filter for requests where a specific accessor was used

        alternatives : typing.Optional[bool]
            Filter for requests where alternatives were used

        callback_method : typing.Optional[bool]
            Filter for requests where callback method was used

        callback : typing.Optional[bool]
            Filter for requests where callback was used

        channels : typing.Optional[bool]
            Filter for requests where channels were used

        custom_intent_mode : typing.Optional[bool]
            Filter for requests where custom intent mode was used

        custom_intent : typing.Optional[bool]
            Filter for requests where custom intent was used

        custom_topic_mode : typing.Optional[bool]
            Filter for requests where custom topic mode was used

        custom_topic : typing.Optional[bool]
            Filter for requests where custom topic was used

        deployment : typing.Optional[UsageGetRequestDeployment]
            Filter for requests where a specific deployment was used

        detect_entities : typing.Optional[bool]
            Filter for requests where detect entities was used

        detect_language : typing.Optional[bool]
            Filter for requests where detect language was used

        diarize : typing.Optional[bool]
            Filter for requests where diarize was used

        dictation : typing.Optional[bool]
            Filter for requests where dictation was used

        encoding : typing.Optional[bool]
            Filter for requests where encoding was used

        endpoint : typing.Optional[UsageGetRequestEndpoint]
            Filter for requests where a specific endpoint was used

        extra : typing.Optional[bool]
            Filter for requests where extra was used

        filler_words : typing.Optional[bool]
            Filter for requests where filler words was used

        intents : typing.Optional[bool]
            Filter for requests where intents was used

        keyterm : typing.Optional[bool]
            Filter for requests where keyterm was used

        keywords : typing.Optional[bool]
            Filter for requests where keywords was used

        language : typing.Optional[bool]
            Filter for requests where language was used

        measurements : typing.Optional[bool]
            Filter for requests where measurements were used

        method : typing.Optional[UsageGetRequestMethod]
            Filter for requests where a specific method was used

        model : typing.Optional[str]
            Filter for requests where a specific model uuid was used

        multichannel : typing.Optional[bool]
            Filter for requests where multichannel was used

        numerals : typing.Optional[bool]
            Filter for requests where numerals were used

        paragraphs : typing.Optional[bool]
            Filter for requests where paragraphs were used

        profanity_filter : typing.Optional[bool]
            Filter for requests where profanity filter was used

        punctuate : typing.Optional[bool]
            Filter for requests where punctuate was used

        redact : typing.Optional[bool]
            Filter for requests where redact was used

        replace : typing.Optional[bool]
            Filter for requests where replace was used

        sample_rate : typing.Optional[bool]
            Filter for requests where sample rate was used

        search : typing.Optional[bool]
            Filter for requests where search was used

        sentiment : typing.Optional[bool]
            Filter for requests where sentiment was used

        smart_format : typing.Optional[bool]
            Filter for requests where smart format was used

        summarize : typing.Optional[bool]
            Filter for requests where summarize was used

        tag : typing.Optional[str]
            Filter for requests where a specific tag was used

        topics : typing.Optional[bool]
            Filter for requests where topics was used

        utt_split : typing.Optional[bool]
            Filter for requests where utt split was used

        utterances : typing.Optional[bool]
            Filter for requests where utterances was used

        version : typing.Optional[bool]
            Filter for requests where version was used

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

        Returns
        -------
        AsyncHttpResponse[UsageV1Response]
            A specific request for a specific project
        """
        _response = await self._client_wrapper.httpx_client.request(
            f"v1/projects/{jsonable_encoder(project_id)}/usage",
            base_url=self._client_wrapper.get_environment().base,
            method="GET",
            params={
                "start": start,
                "end": end,
                "accessor": accessor,
                "alternatives": alternatives,
                "callback_method": callback_method,
                "callback": callback,
                "channels": channels,
                "custom_intent_mode": custom_intent_mode,
                "custom_intent": custom_intent,
                "custom_topic_mode": custom_topic_mode,
                "custom_topic": custom_topic,
                "deployment": deployment,
                "detect_entities": detect_entities,
                "detect_language": detect_language,
                "diarize": diarize,
                "dictation": dictation,
                "encoding": encoding,
                "endpoint": endpoint,
                "extra": extra,
                "filler_words": filler_words,
                "intents": intents,
                "keyterm": keyterm,
                "keywords": keywords,
                "language": language,
                "measurements": measurements,
                "method": method,
                "model": model,
                "multichannel": multichannel,
                "numerals": numerals,
                "paragraphs": paragraphs,
                "profanity_filter": profanity_filter,
                "punctuate": punctuate,
                "redact": redact,
                "replace": replace,
                "sample_rate": sample_rate,
                "search": search,
                "sentiment": sentiment,
                "smart_format": smart_format,
                "summarize": summarize,
                "tag": tag,
                "topics": topics,
                "utt_split": utt_split,
                "utterances": utterances,
                "version": version,
            },
            request_options=request_options,
        )
        try:
            if 200 <= _response.status_code < 300:
                _data = typing.cast(
                    UsageV1Response,
                    parse_obj_as(
                        type_=UsageV1Response,  # type: ignore
                        object_=_response.json(),
                    ),
                )
                return AsyncHttpResponse(response=_response, data=_data)
            if _response.status_code == 400:
                raise BadRequestError(
                    headers=dict(_response.headers),
                    body=typing.cast(
                        typing.Any,
                        parse_obj_as(
                            type_=typing.Any,  # type: ignore
                            object_=_response.json(),
                        ),
                    ),
                )
            _response_json = _response.json()
        except JSONDecodeError:
            raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response.text)
        raise ApiError(status_code=_response.status_code, headers=dict(_response.headers), body=_response_json)
