1# coding=utf-8
2# --------------------------------------------------------------------------
3# Copyright (c) Microsoft Corporation. All rights reserved.
4# Licensed under the MIT License. See License.txt in the project root for
5# license information.
6#
7# Code generated by Microsoft (R) AutoRest Code Generator.
8# Changes may cause incorrect behavior and will be lost if the code is
9# regenerated.
10# --------------------------------------------------------------------------
11
12from azure.mgmt.core import AsyncARMPipelineClient
13from msrest import Serializer, Deserializer
14
15from azure.profiles import KnownProfiles, ProfileDefinition
16from azure.profiles.multiapiclient import MultiApiClientMixin
17from ._configuration_async import ApplicationClientConfiguration
18
19class _SDKClient(object):
20    def __init__(self, *args, **kwargs):
21        """This is a fake class to support current implemetation of MultiApiClientMixin."
22        Will be removed in final version of multiapi azure-core based client
23        """
24        pass
25
26class ApplicationClient(MultiApiClientMixin, _SDKClient):
27    """ARM applications.
28
29    This ready contains multiple API versions, to help you deal with all of the Azure clouds
30    (Azure Stack, Azure Government, Azure China, etc.).
31    By default, it uses the latest API version available on public Azure.
32    For production, you should stick to a particular api-version and/or profile.
33    The profile sets a mapping between an operation group and its API version.
34    The api-version parameter sets the default API version if the operation
35    group is not described in the profile.
36
37    :param credential: Credential needed for the client to connect to Azure.
38    :type credential: ~azure.core.credentials_async.AsyncTokenCredential
39    :param subscription_id: The ID of the target subscription.
40    :type subscription_id: str
41    :param str api_version: API version to use if no profile is provided, or if
42     missing in profile.
43    :param str base_url: Service URL
44    :param profile: A profile definition, from KnownProfiles to dict.
45    :type profile: azure.profiles.KnownProfiles
46    :keyword int polling_interval: Default waiting time between two polls for LRO operations if no Retry-After header is present.
47    """
48
49    DEFAULT_API_VERSION = '2018-06-01'
50    _PROFILE_TAG = "azure.mgmt.resource.ApplicationClient"
51    LATEST_PROFILE = ProfileDefinition({
52        _PROFILE_TAG: {
53            None: DEFAULT_API_VERSION,
54        }},
55        _PROFILE_TAG + " latest"
56    )
57
58    def __init__(
59        self,
60        credential,  # type: "AsyncTokenCredential"
61        subscription_id,  # type: str
62        api_version=None,
63        base_url=None,
64        profile=KnownProfiles.default,
65        **kwargs  # type: Any
66    ) -> None:
67        if not base_url:
68            base_url = 'https://management.azure.com'
69        self._config = ApplicationClientConfiguration(credential, subscription_id, **kwargs)
70        self._client = AsyncARMPipelineClient(base_url=base_url, config=self._config, **kwargs)
71        super(ApplicationClient, self).__init__(
72            credential,
73            self._config,
74            api_version=api_version,
75            profile=profile
76        )
77
78    @classmethod
79    def _models_dict(cls, api_version):
80        return {k: v for k, v in cls.models(api_version).__dict__.items() if isinstance(v, type)}
81
82    @classmethod
83    def models(cls, api_version=DEFAULT_API_VERSION):
84        """Module depends on the API version:
85
86           * 2018-06-01: :mod:`managedapplications.models<azure.mgmt.resource.managedapplications.models>`
87        """
88        if api_version == '2018-06-01':
89            from ..managedapplications import models
90            return models
91        raise NotImplementedError("APIVersion {} is not available".format(api_version))
92
93    @property
94    def application_definitions(self):
95        """Instance depends on the API version:
96
97           * 2018-06-01: :class:`ApplicationDefinitionsOperations<azure.mgmt.resource.managedapplications.aio.operations_async.ApplicationDefinitionsOperations>`
98        """
99        api_version = self._get_api_version('application_definitions')
100        if api_version == '2018-06-01':
101            from ..managedapplications.aio.operations_async import ApplicationDefinitionsOperations as OperationClass
102        else:
103            raise NotImplementedError("APIVersion {} is not available".format(api_version))
104        return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))
105
106    @property
107    def applications(self):
108        """Instance depends on the API version:
109
110           * 2018-06-01: :class:`ApplicationsOperations<azure.mgmt.resource.managedapplications.aio.operations_async.ApplicationsOperations>`
111        """
112        api_version = self._get_api_version('applications')
113        if api_version == '2018-06-01':
114            from ..managedapplications.aio.operations_async import ApplicationsOperations as OperationClass
115        else:
116            raise NotImplementedError("APIVersion {} is not available".format(api_version))
117        return OperationClass(self._client, self._config, Serializer(self._models_dict(api_version)), Deserializer(self._models_dict(api_version)))
118
119    async def close(self):
120        await self._client.close()
121    async def __aenter__(self):
122        await self._client.__aenter__()
123        return self
124    async def __aexit__(self, *exc_details):
125        await self._client.__aexit__(*exc_details)
126