# coding=utf-8
# --------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT License. See License.txt in the project root for license information.
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is regenerated.
# --------------------------------------------------------------------------

from typing import Any, Optional

from azure.core import AsyncPipelineClient
from msrest import Deserializer, Serializer

from ._configuration_async import ServiceBusManagementClientConfiguration
from .operations_async import EntityOperations
from .operations_async import ServiceBusManagementClientOperationsMixin
from .operations_async import SubscriptionOperations
from .operations_async import RuleOperations
from .operations_async import NamespaceOperations
from .. import models


class ServiceBusManagementClient(ServiceBusManagementClientOperationsMixin):
    """Azure Service Bus client for managing Queues, Topics, and Subscriptions.

    :ivar entity: EntityOperations operations
    :vartype entity: azure.servicebus.management._generated.aio.operations_async.EntityOperations
    :ivar subscription: SubscriptionOperations operations
    :vartype subscription: azure.servicebus.management._generated.aio.operations_async.SubscriptionOperations
    :ivar rule: RuleOperations operations
    :vartype rule: azure.servicebus.management._generated.aio.operations_async.RuleOperations
    :ivar namespace: NamespaceOperations operations
    :vartype namespace: azure.servicebus.management._generated.aio.operations_async.NamespaceOperations
    :param endpoint: The Service Bus fully qualified domain name.
    :type endpoint: str
    :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
    """

    def __init__(
        self,
        endpoint: str,
        **kwargs: Any
    ) -> None:
        base_url = 'https://{endpoint}'
        self._config = ServiceBusManagementClientConfiguration(endpoint, **kwargs)
        self._client = AsyncPipelineClient(base_url=base_url, config=self._config, **kwargs)

        client_models = {k: v for k, v in models.__dict__.items() if isinstance(v, type)}
        self._serialize = Serializer(client_models)
        self._deserialize = Deserializer(client_models)

        self.entity = EntityOperations(
            self._client, self._config, self._serialize, self._deserialize)
        self.subscription = SubscriptionOperations(
            self._client, self._config, self._serialize, self._deserialize)
        self.rule = RuleOperations(
            self._client, self._config, self._serialize, self._deserialize)
        self.namespace = NamespaceOperations(
            self._client, self._config, self._serialize, self._deserialize)

    async def close(self) -> None:
        await self._client.close()

    async def __aenter__(self) -> "ServiceBusManagementClient":
        await self._client.__aenter__()
        return self

    async def __aexit__(self, *exc_details) -> None:
        await self._client.__aexit__(*exc_details)
