# 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_create_response import ApiKeyCreateResponse
from ..types.api_key_list_response import ApiKeyListResponse
from ..types.api_key_response import ApiKeyResponse
from ..types.api_key_scope import ApiKeyScope
from ..types.delete_response import DeleteResponse
from .raw_client import AsyncRawApiKeysClient, RawApiKeysClient

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


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(
        self, *, include_revoked: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyListResponse:
        """
        List all API keys for the organization. Only org admins can list keys.

        Parameters
        ----------
        include_revoked : typing.Optional[bool]

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

        Returns
        -------
        ApiKeyListResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.api_keys.list()
        """
        _response = self._raw_client.list(include_revoked=include_revoked, request_options=request_options)
        return _response.data

    def create(
        self,
        *,
        name: str,
        scopes: typing.Sequence[ApiKeyScope],
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyCreateResponse:
        """
        Create a new org-level API key. Only org admins can create API keys.

        Parameters
        ----------
        name : str
            Human-readable name for the API key.

        scopes : typing.Sequence[ApiKeyScope]
            List of resource scopes. At least one scope is required.

        description : typing.Optional[str]
            Optional description.

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

        Returns
        -------
        ApiKeyCreateResponse
            Successful Response

        Examples
        --------
        from terminaluse import ApiKeyScope, TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.api_keys.create(
            name="name",
            scopes=[
                ApiKeyScope(
                    resource_id="resource_id",
                    resource_type="resource_type",
                    role="viewer",
                )
            ],
        )
        """
        _response = self._raw_client.create(
            name=name, scopes=scopes, description=description, request_options=request_options
        )
        return _response.data

    def retrieve(self, api_key_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> ApiKeyResponse:
        """
        Get details of a specific API key. Only org admins can view keys.

        Parameters
        ----------
        api_key_id : str

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

        Returns
        -------
        ApiKeyResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.api_keys.retrieve(
            api_key_id="api_key_id",
        )
        """
        _response = self._raw_client.retrieve(api_key_id, request_options=request_options)
        return _response.data

    def delete(self, api_key_id: str, *, request_options: typing.Optional[RequestOptions] = None) -> DeleteResponse:
        """
        Revoke an API key. Only org admins can revoke keys.

        Parameters
        ----------
        api_key_id : str

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

        Returns
        -------
        DeleteResponse
            Successful Response

        Examples
        --------
        from terminaluse import TerminalUseBase

        client = TerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )
        client.api_keys.delete(
            api_key_id="api_key_id",
        )
        """
        _response = self._raw_client.delete(api_key_id, 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(
        self, *, include_revoked: typing.Optional[bool] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyListResponse:
        """
        List all API keys for the organization. Only org admins can list keys.

        Parameters
        ----------
        include_revoked : typing.Optional[bool]

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

        Returns
        -------
        ApiKeyListResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


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


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

    async def create(
        self,
        *,
        name: str,
        scopes: typing.Sequence[ApiKeyScope],
        description: typing.Optional[str] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyCreateResponse:
        """
        Create a new org-level API key. Only org admins can create API keys.

        Parameters
        ----------
        name : str
            Human-readable name for the API key.

        scopes : typing.Sequence[ApiKeyScope]
            List of resource scopes. At least one scope is required.

        description : typing.Optional[str]
            Optional description.

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

        Returns
        -------
        ApiKeyCreateResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import ApiKeyScope, AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


        async def main() -> None:
            await client.api_keys.create(
                name="name",
                scopes=[
                    ApiKeyScope(
                        resource_id="resource_id",
                        resource_type="resource_type",
                        role="viewer",
                    )
                ],
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create(
            name=name, scopes=scopes, description=description, request_options=request_options
        )
        return _response.data

    async def retrieve(
        self, api_key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyResponse:
        """
        Get details of a specific API key. Only org admins can view keys.

        Parameters
        ----------
        api_key_id : str

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

        Returns
        -------
        ApiKeyResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


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


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

    async def delete(
        self, api_key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> DeleteResponse:
        """
        Revoke an API key. Only org admins can revoke keys.

        Parameters
        ----------
        api_key_id : str

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

        Returns
        -------
        DeleteResponse
            Successful Response

        Examples
        --------
        import asyncio

        from terminaluse import AsyncTerminalUseBase

        client = AsyncTerminalUseBase(
            agent_api_key="YOUR_AGENT_API_KEY",
            token="YOUR_TOKEN",
            base_url="https://yourhost.com/path/to/api",
        )


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


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