"""Asynchronous Meraki dashboard API SDK.

This file is automatically @generated from the Meraki API specification.
Do not edit this file manually.
"""

import os
import sys
from types import TracebackType
from typing import Self

from meraki_client import types
from meraki_client._api.batch import Batch
from meraki_client._common import BaseURL
from meraki_client.aio._api.administered import Administered
from meraki_client.aio._api.appliance import Appliance
from meraki_client.aio._api.camera import Camera
from meraki_client.aio._api.campus_gateway import CampusGateway
from meraki_client.aio._api.cellular_gateway import CellularGateway
from meraki_client.aio._api.devices import Devices
from meraki_client.aio._api.insight import Insight
from meraki_client.aio._api.licensing import Licensing
from meraki_client.aio._api.networks import Networks
from meraki_client.aio._api.organizations import Organizations
from meraki_client.aio._api.sensor import Sensor
from meraki_client.aio._api.sm import Sm
from meraki_client.aio._api.spaces import Spaces
from meraki_client.aio._api.switch import Switch
from meraki_client.aio._api.wireless import Wireless
from meraki_client.aio._api.wireless_controller import WirelessController
from meraki_client.aio._session import AsyncPaginatedResponse, Session

if sys.version_info < (3, 11):  # noqa: UP036
    raise RuntimeError(
        "Python 3.11 or higher is required. "
        f"You are using Python {sys.version_info.major}.{sys.version_info.minor}."
    )


__all__ = [
    "AsyncMerakiClient",
    "AsyncPaginatedResponse",
    "BaseURL",
    "types",
]
__version__ = "0.10.1"
__api_version__ = "v1.67.0"


class AsyncMerakiClient:
    """Asynchronous client class for the Meraki dashboard API.

    Args:
        api_key: API key generated in dashboard; can also be set as an environment variable
            `MERAKI_DASHBOARD_API_KEY`.
        base_url: Base URL preceding all endpoint resources.
        single_request_timeout: Maximum number of seconds for each API call. Defaults to 30.
        total_request_timeout: Total time in seconds to wait for a request to complete including
            retries. Defaults to 60.
        certificate_path: Path for TLS/SSL certificate verification if behind local proxy.
        requests_proxy: Proxy server and port, if needed, for HTTPS.
        wait_on_rate_limit: Retry if 429 rate limit error encountered? Defaults to True.
        maximum_retries: Retry up to this many times when encountering 429s or other server-side
            errors. Defaults to 2.
        caller: Optional identifier for API usage tracking; can also be set as an environment
            variable `MERAKI_PYTHON_SDK_CALLER`.
        maximum_concurrent_requests: Number of concurrent API requests. Defaults to 8.

    """

    def __init__(
        self,
        *,
        api_key: str | None = None,
        base_url: BaseURL = BaseURL.DEFAULT,
        single_request_timeout: int = 30,
        total_request_timeout: int = 60,
        wait_on_rate_limit: bool = True,
        maximum_retries: int = 2,
        certificate_path: str | None = None,
        requests_proxy: str | None = None,
        caller: str | None = None,
        maximum_concurrent_requests: int = 8,
    ) -> None:
        # Check that the API key is defined
        api_key = api_key or os.environ.get("MERAKI_DASHBOARD_API_KEY")
        if not api_key:
            raise ValueError(
                "API key needs to be defined. Give the API key as an argument "
                "or set the MERAKI_DASHBOARD_API_KEY environment variable."
            )
        caller = caller or os.environ.get("MERAKI_PYTHON_SDK_CALLER")

        # Creates the API session
        self._session = Session(
            api_key=api_key,
            base_url=base_url,
            single_request_timeout=single_request_timeout,
            total_request_timeout=total_request_timeout,
            certificate_path=certificate_path,
            proxy=requests_proxy,
            wait_on_rate_limit=wait_on_rate_limit,
            maximum_retries=maximum_retries,
            caller=caller,
            version=__version__,
            maximum_concurrent_requests=maximum_concurrent_requests,
        )

        # API endpoints by section
        self.administered = Administered(self._session)
        self.appliance = Appliance(self._session)
        self.camera = Camera(self._session)
        self.campus_gateway = CampusGateway(self._session)
        self.cellular_gateway = CellularGateway(self._session)
        self.devices = Devices(self._session)
        self.insight = Insight(self._session)
        self.licensing = Licensing(self._session)
        self.networks = Networks(self._session)
        self.organizations = Organizations(self._session)
        self.sensor = Sensor(self._session)
        self.sm = Sm(self._session)
        self.spaces = Spaces(self._session)
        self.switch = Switch(self._session)
        self.wireless = Wireless(self._session)
        self.wireless_controller = WirelessController(self._session)

        # Batch definitions
        self.batch = Batch()

    async def __aenter__(self) -> Self:
        return self

    async def __aexit__(
        self,
        exc_type: type[BaseException] | None,
        exc: BaseException | None,
        tb: TracebackType | None,
    ) -> None:
        await self._session.close()
