# 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.list_api_keys_response import ListApiKeysResponse
from .raw_client import AsyncRawApiKeysClient, RawApiKeysClient


class ApiKeysClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawApiKeysClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawApiKeysClient
        """
        return self._raw_client

    def list_api_keys(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[ListApiKeysResponse]:
        """
        List all API keys associated with the authenticated user.

        Args:
            request (Request): The incoming request object.

        Returns:
            List[ListAPIKeysResponse]: A list of API Keys associated with the user.

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

        Returns
        -------
        typing.List[ListApiKeysResponse]
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.api_keys.list_api_keys()
        """
        _response = self._raw_client.list_api_keys(request_options=request_options)
        return _response.data

    def create_api_key(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> str:
        """
        Creates an API key for a user.

        Args:
            request (Request): The request object containing the user ID in the request state.

        Returns:
            str: The created API key.

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

        Returns
        -------
        str
            Successful Response

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.api_keys.create_api_key()
        """
        _response = self._raw_client.create_api_key(request_options=request_options)
        return _response.data

    def delete_api_key(
        self,
        key_prefix: str,
        *,
        request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Delete an API key with the given key prefix for the authenticated user.

        Args:
            key_prefix (str): The prefix of the API key to be deleted.
            request (Request): The incoming request object.

        Returns:
            dict: A dictionary containing a success message upon successful deletion.

        Raises:
            HTTPException: If the API key is not found or does not belong to the user.

        Parameters
        ----------
        key_prefix : str

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

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

        Examples
        --------
        from agenta import AgentaApi

        client = AgentaApi(
            api_key="YOUR_API_KEY",
        )
        client.api_keys.delete_api_key(
            key_prefix="key_prefix",
        )
        """
        _response = self._raw_client.delete_api_key(
            key_prefix, request_options=request_options
        )
        return _response.data


class AsyncApiKeysClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawApiKeysClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawApiKeysClient
        """
        return self._raw_client

    async def list_api_keys(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> typing.List[ListApiKeysResponse]:
        """
        List all API keys associated with the authenticated user.

        Args:
            request (Request): The incoming request object.

        Returns:
            List[ListAPIKeysResponse]: A list of API Keys associated with the user.

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

        Returns
        -------
        typing.List[ListApiKeysResponse]
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.api_keys.list_api_keys()


        asyncio.run(main())
        """
        _response = await self._raw_client.list_api_keys(
            request_options=request_options
        )
        return _response.data

    async def create_api_key(
        self, *, request_options: typing.Optional[RequestOptions] = None
    ) -> str:
        """
        Creates an API key for a user.

        Args:
            request (Request): The request object containing the user ID in the request state.

        Returns:
            str: The created API key.

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

        Returns
        -------
        str
            Successful Response

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.api_keys.create_api_key()


        asyncio.run(main())
        """
        _response = await self._raw_client.create_api_key(
            request_options=request_options
        )
        return _response.data

    async def delete_api_key(
        self,
        key_prefix: str,
        *,
        request_options: typing.Optional[RequestOptions] = None
    ) -> typing.Dict[str, typing.Optional[typing.Any]]:
        """
        Delete an API key with the given key prefix for the authenticated user.

        Args:
            key_prefix (str): The prefix of the API key to be deleted.
            request (Request): The incoming request object.

        Returns:
            dict: A dictionary containing a success message upon successful deletion.

        Raises:
            HTTPException: If the API key is not found or does not belong to the user.

        Parameters
        ----------
        key_prefix : str

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

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

        Examples
        --------
        import asyncio

        from agenta import AsyncAgentaApi

        client = AsyncAgentaApi(
            api_key="YOUR_API_KEY",
        )


        async def main() -> None:
            await client.api_keys.delete_api_key(
                key_prefix="key_prefix",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.delete_api_key(
            key_prefix, request_options=request_options
        )
        return _response.data
