# 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.api_key_action_response import ApiKeyActionResponse
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_rotate_response import ApiKeyRotateResponse
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_api_keys(
        self,
        org_id: str,
        *,
        page: typing.Optional[int] = None,
        page_size: typing.Optional[int] = None,
        skip: typing.Optional[int] = None,
        take: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyListResponse:
        """
        List API keys for an organization.

        Supports both page/page_size and skip/take pagination styles.
        Returns empty list when no API keys exist.

        Args:
            org_id: Organization ID
            db: Database session
            auth: Authenticated user
            page: Page number (1-indexed, optional)
            page_size: Items per page (optional)
            skip: Number of items to skip (alternative to page)
            take: Number of items to take (alternative to page_size)

        Returns:
            Paginated list of API keys (empty list if none exist)

        Raises:
            ResourceNotFoundException: If organization not found
            AuthorizationException: If user is not a member

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

        page : typing.Optional[int]
            Page number (1-indexed)

        page_size : typing.Optional[int]
            Items per page

        skip : typing.Optional[int]
            Number of items to skip

        take : typing.Optional[int]
            Number of items to take

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

        Returns
        -------
        ApiKeyListResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.api_keys.list_api_keys(
            org_id="org_id",
        )
        """
        _response = self._raw_client.list_api_keys(
            org_id, page=page, page_size=page_size, skip=skip, take=take, request_options=request_options
        )
        return _response.data

    def create_api_key(
        self,
        org_id: str,
        *,
        key_name: str,
        usage_limit_chf: typing.Optional[float] = OMIT,
        scopes: typing.Optional[typing.Sequence[str]] = OMIT,
        expires_at: typing.Optional[dt.datetime] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyCreateResponse:
        """
        Create a new API key for an organization.

        Requires admin or owner role.
        The raw API key is returned ONCE and must be stored securely by the client.

        Args:
            org_id: Organization ID
            request: API key creation request
            db: Database session
            auth: Authenticated user

        Returns:
            Created API key with raw key (shown ONCE only)

        Raises:
            ResourceNotFoundException: If organization not found
            AuthorizationException: If user lacks permissions
            ConflictException: If organization has reached max API keys
            ValidationException: If validation fails

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

        key_name : str
            Human-readable name for the API key

        usage_limit_chf : typing.Optional[float]
            Per-key monthly spending limit in CHF

        scopes : typing.Optional[typing.Sequence[str]]
            Permission scopes for the key

        expires_at : typing.Optional[dt.datetime]
            Optional expiration timestamp

        metadata : typing.Optional[typing.Dict[str, typing.Any]]
            Additional key metadata (e.g., deletable: false)

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

        Returns
        -------
        ApiKeyCreateResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.api_keys.create_api_key(
            org_id="org_id",
            key_name="key_name",
        )
        """
        _response = self._raw_client.create_api_key(
            org_id,
            key_name=key_name,
            usage_limit_chf=usage_limit_chf,
            scopes=scopes,
            expires_at=expires_at,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    def get_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyResponse:
        """
        Get details of a specific API key.

        Requires organization membership.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            API key details

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user is not a member
            ValidationException: If key ID format is invalid

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

        key_id : str

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

        Returns
        -------
        ApiKeyResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.api_keys.get_api_key(
            org_id="org_id",
            key_id="key_id",
        )
        """
        _response = self._raw_client.get_api_key(org_id, key_id, request_options=request_options)
        return _response.data

    def delete_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyActionResponse:
        """
        Soft delete an API key (idempotent).

        Requires admin or owner role.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            Action result with deleted key info

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions

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

        key_id : str

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

        Returns
        -------
        ApiKeyActionResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.api_keys.delete_api_key(
            org_id="org_id",
            key_id="key_id",
        )
        """
        _response = self._raw_client.delete_api_key(org_id, key_id, request_options=request_options)
        return _response.data

    def update_api_key(
        self,
        org_id: str,
        key_id: str,
        *,
        key_name: typing.Optional[str] = OMIT,
        usage_limit_chf: typing.Optional[float] = OMIT,
        scopes: typing.Optional[typing.Sequence[str]] = OMIT,
        expires_at: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyResponse:
        """
        Update API key metadata.

        Requires admin or owner role.
        Invalidates per-key limit cache when usage_limit_chf is updated.

        Args:
            org_id: Organization ID
            key_id: API key ID
            request: Update request
            db: Database session
            auth: Authenticated user

        Returns:
            Updated API key details

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions
            ValidationException: If validation fails

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

        key_id : str

        key_name : typing.Optional[str]
            New name for the API key

        usage_limit_chf : typing.Optional[float]
            New per-key monthly spending limit in CHF

        scopes : typing.Optional[typing.Sequence[str]]
            New permission scopes

        expires_at : typing.Optional[dt.datetime]
            New expiration timestamp

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

        Returns
        -------
        ApiKeyResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.api_keys.update_api_key(
            org_id="org_id",
            key_id="key_id",
        )
        """
        _response = self._raw_client.update_api_key(
            org_id,
            key_id,
            key_name=key_name,
            usage_limit_chf=usage_limit_chf,
            scopes=scopes,
            expires_at=expires_at,
            request_options=request_options,
        )
        return _response.data

    def activate_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyActionResponse:
        """
        Activate an API key.

        Requires admin or owner role.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            Action result with updated key

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions

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

        key_id : str

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

        Returns
        -------
        ApiKeyActionResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.api_keys.activate_api_key(
            org_id="org_id",
            key_id="key_id",
        )
        """
        _response = self._raw_client.activate_api_key(org_id, key_id, request_options=request_options)
        return _response.data

    def deactivate_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyActionResponse:
        """
        Deactivate an API key.

        Requires admin or owner role.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            Action result with updated key

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions

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

        key_id : str

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

        Returns
        -------
        ApiKeyActionResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.api_keys.deactivate_api_key(
            org_id="org_id",
            key_id="key_id",
        )
        """
        _response = self._raw_client.deactivate_api_key(org_id, key_id, request_options=request_options)
        return _response.data

    def pause_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyActionResponse:
        """
        Pause an API key temporarily.

        Requires admin or owner role.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            Action result with updated key

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions

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

        key_id : str

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

        Returns
        -------
        ApiKeyActionResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.api_keys.pause_api_key(
            org_id="org_id",
            key_id="key_id",
        )
        """
        _response = self._raw_client.pause_api_key(org_id, key_id, request_options=request_options)
        return _response.data

    def unpause_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyActionResponse:
        """
        Unpause an API key.

        Requires admin or owner role.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            Action result with updated key

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions

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

        key_id : str

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

        Returns
        -------
        ApiKeyActionResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.api_keys.unpause_api_key(
            org_id="org_id",
            key_id="key_id",
        )
        """
        _response = self._raw_client.unpause_api_key(org_id, key_id, request_options=request_options)
        return _response.data

    def rotate_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyRotateResponse:
        """
        Rotate an API key (delete old, create new with same settings).

        Requires admin or owner role.
        The new raw API key is returned ONCE and must be stored securely.

        Args:
            org_id: Organization ID
            key_id: API key ID to rotate
            db: Database session
            auth: Authenticated user

        Returns:
            Rotation result with new key (raw key shown ONCE only)

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions
            ConflictException: If key is already deleted

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

        key_id : str

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

        Returns
        -------
        ApiKeyRotateResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.api_keys.rotate_api_key(
            org_id="org_id",
            key_id="key_id",
        )
        """
        _response = self._raw_client.rotate_api_key(org_id, 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_api_keys(
        self,
        org_id: str,
        *,
        page: typing.Optional[int] = None,
        page_size: typing.Optional[int] = None,
        skip: typing.Optional[int] = None,
        take: typing.Optional[int] = None,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyListResponse:
        """
        List API keys for an organization.

        Supports both page/page_size and skip/take pagination styles.
        Returns empty list when no API keys exist.

        Args:
            org_id: Organization ID
            db: Database session
            auth: Authenticated user
            page: Page number (1-indexed, optional)
            page_size: Items per page (optional)
            skip: Number of items to skip (alternative to page)
            take: Number of items to take (alternative to page_size)

        Returns:
            Paginated list of API keys (empty list if none exist)

        Raises:
            ResourceNotFoundException: If organization not found
            AuthorizationException: If user is not a member

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

        page : typing.Optional[int]
            Page number (1-indexed)

        page_size : typing.Optional[int]
            Items per page

        skip : typing.Optional[int]
            Number of items to skip

        take : typing.Optional[int]
            Number of items to take

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

        Returns
        -------
        ApiKeyListResponse
            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.api_keys.list_api_keys(
                org_id="org_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.list_api_keys(
            org_id, page=page, page_size=page_size, skip=skip, take=take, request_options=request_options
        )
        return _response.data

    async def create_api_key(
        self,
        org_id: str,
        *,
        key_name: str,
        usage_limit_chf: typing.Optional[float] = OMIT,
        scopes: typing.Optional[typing.Sequence[str]] = OMIT,
        expires_at: typing.Optional[dt.datetime] = OMIT,
        metadata: typing.Optional[typing.Dict[str, typing.Any]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyCreateResponse:
        """
        Create a new API key for an organization.

        Requires admin or owner role.
        The raw API key is returned ONCE and must be stored securely by the client.

        Args:
            org_id: Organization ID
            request: API key creation request
            db: Database session
            auth: Authenticated user

        Returns:
            Created API key with raw key (shown ONCE only)

        Raises:
            ResourceNotFoundException: If organization not found
            AuthorizationException: If user lacks permissions
            ConflictException: If organization has reached max API keys
            ValidationException: If validation fails

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

        key_name : str
            Human-readable name for the API key

        usage_limit_chf : typing.Optional[float]
            Per-key monthly spending limit in CHF

        scopes : typing.Optional[typing.Sequence[str]]
            Permission scopes for the key

        expires_at : typing.Optional[dt.datetime]
            Optional expiration timestamp

        metadata : typing.Optional[typing.Dict[str, typing.Any]]
            Additional key metadata (e.g., deletable: false)

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

        Returns
        -------
        ApiKeyCreateResponse
            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.api_keys.create_api_key(
                org_id="org_id",
                key_name="key_name",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.create_api_key(
            org_id,
            key_name=key_name,
            usage_limit_chf=usage_limit_chf,
            scopes=scopes,
            expires_at=expires_at,
            metadata=metadata,
            request_options=request_options,
        )
        return _response.data

    async def get_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyResponse:
        """
        Get details of a specific API key.

        Requires organization membership.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            API key details

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user is not a member
            ValidationException: If key ID format is invalid

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

        key_id : str

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

        Returns
        -------
        ApiKeyResponse
            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.api_keys.get_api_key(
                org_id="org_id",
                key_id="key_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.get_api_key(org_id, key_id, request_options=request_options)
        return _response.data

    async def delete_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyActionResponse:
        """
        Soft delete an API key (idempotent).

        Requires admin or owner role.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            Action result with deleted key info

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions

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

        key_id : str

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

        Returns
        -------
        ApiKeyActionResponse
            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.api_keys.delete_api_key(
                org_id="org_id",
                key_id="key_id",
            )


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

    async def update_api_key(
        self,
        org_id: str,
        key_id: str,
        *,
        key_name: typing.Optional[str] = OMIT,
        usage_limit_chf: typing.Optional[float] = OMIT,
        scopes: typing.Optional[typing.Sequence[str]] = OMIT,
        expires_at: typing.Optional[dt.datetime] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> ApiKeyResponse:
        """
        Update API key metadata.

        Requires admin or owner role.
        Invalidates per-key limit cache when usage_limit_chf is updated.

        Args:
            org_id: Organization ID
            key_id: API key ID
            request: Update request
            db: Database session
            auth: Authenticated user

        Returns:
            Updated API key details

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions
            ValidationException: If validation fails

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

        key_id : str

        key_name : typing.Optional[str]
            New name for the API key

        usage_limit_chf : typing.Optional[float]
            New per-key monthly spending limit in CHF

        scopes : typing.Optional[typing.Sequence[str]]
            New permission scopes

        expires_at : typing.Optional[dt.datetime]
            New expiration timestamp

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

        Returns
        -------
        ApiKeyResponse
            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.api_keys.update_api_key(
                org_id="org_id",
                key_id="key_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.update_api_key(
            org_id,
            key_id,
            key_name=key_name,
            usage_limit_chf=usage_limit_chf,
            scopes=scopes,
            expires_at=expires_at,
            request_options=request_options,
        )
        return _response.data

    async def activate_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyActionResponse:
        """
        Activate an API key.

        Requires admin or owner role.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            Action result with updated key

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions

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

        key_id : str

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

        Returns
        -------
        ApiKeyActionResponse
            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.api_keys.activate_api_key(
                org_id="org_id",
                key_id="key_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.activate_api_key(org_id, key_id, request_options=request_options)
        return _response.data

    async def deactivate_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyActionResponse:
        """
        Deactivate an API key.

        Requires admin or owner role.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            Action result with updated key

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions

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

        key_id : str

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

        Returns
        -------
        ApiKeyActionResponse
            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.api_keys.deactivate_api_key(
                org_id="org_id",
                key_id="key_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.deactivate_api_key(org_id, key_id, request_options=request_options)
        return _response.data

    async def pause_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyActionResponse:
        """
        Pause an API key temporarily.

        Requires admin or owner role.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            Action result with updated key

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions

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

        key_id : str

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

        Returns
        -------
        ApiKeyActionResponse
            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.api_keys.pause_api_key(
                org_id="org_id",
                key_id="key_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.pause_api_key(org_id, key_id, request_options=request_options)
        return _response.data

    async def unpause_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyActionResponse:
        """
        Unpause an API key.

        Requires admin or owner role.

        Args:
            org_id: Organization ID
            key_id: API key ID
            db: Database session
            auth: Authenticated user

        Returns:
            Action result with updated key

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions

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

        key_id : str

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

        Returns
        -------
        ApiKeyActionResponse
            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.api_keys.unpause_api_key(
                org_id="org_id",
                key_id="key_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.unpause_api_key(org_id, key_id, request_options=request_options)
        return _response.data

    async def rotate_api_key(
        self, org_id: str, key_id: str, *, request_options: typing.Optional[RequestOptions] = None
    ) -> ApiKeyRotateResponse:
        """
        Rotate an API key (delete old, create new with same settings).

        Requires admin or owner role.
        The new raw API key is returned ONCE and must be stored securely.

        Args:
            org_id: Organization ID
            key_id: API key ID to rotate
            db: Database session
            auth: Authenticated user

        Returns:
            Rotation result with new key (raw key shown ONCE only)

        Raises:
            ResourceNotFoundException: If organization or key not found
            AuthorizationException: If user lacks permissions
            ConflictException: If key is already deleted

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

        key_id : str

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

        Returns
        -------
        ApiKeyRotateResponse
            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.api_keys.rotate_api_key(
                org_id="org_id",
                key_id="key_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.rotate_api_key(org_id, key_id, request_options=request_options)
        return _response.data
