# 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.clear_all_caches_response import ClearAllCachesResponse
from ..types.invalidate_limit_cache_response import InvalidateLimitCacheResponse
from .raw_client import AsyncRawAdminCacheClient, RawAdminCacheClient

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


class AdminCacheClient:
    def __init__(self, *, client_wrapper: SyncClientWrapper):
        self._raw_client = RawAdminCacheClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        RawAdminCacheClient
        """
        return self._raw_client

    def invalidate_limit_caches(
        self,
        *,
        organization_id: str,
        api_key: typing.Optional[str] = None,
        api_key_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> InvalidateLimitCacheResponse:
        """
        Invalidate limit caches for organization and/or API keys.

        Use this endpoint when limits are updated directly in the database
        to ensure the cache reflects the new limits immediately.

        Requires:
        - Header: api-key: {ADMIN_API_KEY}

        Args:
            cache_request: Cache invalidation request with organization_id and optional api_key_ids
            cache_manager: Limit cache manager instance

        Returns:
            Response with success status and count of caches cleared

        Raises:
            AuthenticationException: If admin API key is missing or invalid

        Parameters
        ----------
        organization_id : str
            Organization ID to invalidate caches for

        api_key : typing.Optional[str]

        api_key_ids : typing.Optional[typing.Sequence[str]]
            Optional list of API key IDs to invalidate per-key caches

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

        Returns
        -------
        InvalidateLimitCacheResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.admin_cache.invalidate_limit_caches(
            organization_id="organization_id",
        )
        """
        _response = self._raw_client.invalidate_limit_caches(
            organization_id=organization_id, api_key=api_key, api_key_ids=api_key_ids, request_options=request_options
        )
        return _response.data

    def clear_all_caches(
        self, *, api_key: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ClearAllCachesResponse:
        """
        Clear all application caches (distributed + in-memory).

        Parameters
        ----------
        api_key : typing.Optional[str]

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

        Returns
        -------
        ClearAllCachesResponse
            Successful Response

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

        client = Aitronos(
            api_key="YOUR_API_KEY",
            token="YOUR_TOKEN",
        )
        client.admin_cache.clear_all_caches()
        """
        _response = self._raw_client.clear_all_caches(api_key=api_key, request_options=request_options)
        return _response.data


class AsyncAdminCacheClient:
    def __init__(self, *, client_wrapper: AsyncClientWrapper):
        self._raw_client = AsyncRawAdminCacheClient(client_wrapper=client_wrapper)

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

        Returns
        -------
        AsyncRawAdminCacheClient
        """
        return self._raw_client

    async def invalidate_limit_caches(
        self,
        *,
        organization_id: str,
        api_key: typing.Optional[str] = None,
        api_key_ids: typing.Optional[typing.Sequence[str]] = OMIT,
        request_options: typing.Optional[RequestOptions] = None,
    ) -> InvalidateLimitCacheResponse:
        """
        Invalidate limit caches for organization and/or API keys.

        Use this endpoint when limits are updated directly in the database
        to ensure the cache reflects the new limits immediately.

        Requires:
        - Header: api-key: {ADMIN_API_KEY}

        Args:
            cache_request: Cache invalidation request with organization_id and optional api_key_ids
            cache_manager: Limit cache manager instance

        Returns:
            Response with success status and count of caches cleared

        Raises:
            AuthenticationException: If admin API key is missing or invalid

        Parameters
        ----------
        organization_id : str
            Organization ID to invalidate caches for

        api_key : typing.Optional[str]

        api_key_ids : typing.Optional[typing.Sequence[str]]
            Optional list of API key IDs to invalidate per-key caches

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

        Returns
        -------
        InvalidateLimitCacheResponse
            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.admin_cache.invalidate_limit_caches(
                organization_id="organization_id",
            )


        asyncio.run(main())
        """
        _response = await self._raw_client.invalidate_limit_caches(
            organization_id=organization_id, api_key=api_key, api_key_ids=api_key_ids, request_options=request_options
        )
        return _response.data

    async def clear_all_caches(
        self, *, api_key: typing.Optional[str] = None, request_options: typing.Optional[RequestOptions] = None
    ) -> ClearAllCachesResponse:
        """
        Clear all application caches (distributed + in-memory).

        Parameters
        ----------
        api_key : typing.Optional[str]

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

        Returns
        -------
        ClearAllCachesResponse
            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.admin_cache.clear_all_caches()


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