# Source code for azure.mgmt.web.operations.recommendations_operations

    # 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 msrest.pipeline import ClientRawResponse
    from msrestazure.azure_exceptions import CloudError
    import uuid

    from .. import models

    class RecommendationsOperations(object):
        """RecommendationsOperations operations.

        :param client: Client for service requests.
        :param config: Configuration of service client.
        :param serializer: An object model serializer.
        :param deserializer: An objec model deserializer.
        """

        def __init__(self, client, config, serializer, deserializer):

            self._client = client
            self._serialize = serializer
            self._deserialize = deserializer

            self.config = config

        def get_recommendation_by_subscription(
                self, featured=None, filter=None, custom_headers=None, raw=False, **operation_config):
            """Gets a list of recommendations associated with the specified
            subscription.

            :param featured: If set, this API returns only the most critical
             recommendation among the others. Otherwise this API returns all
             recommendations available
            :type featured: bool
            :param filter: Return only channels specified in the filter. Filter
             is specified by using OData syntax. Example: $filter=channels eq
             'Api' or channel eq 'Notification'
            :type filter: str
            :param dict custom_headers: headers that will be added to the request
            :param bool raw: returns the direct response alongside the
             deserialized response
            :param operation_config: :ref:`Operation configuration
             overrides<msrest:optionsforoperations>`.
            :rtype: list of :class:`Recommendation
             <azure.mgmt.web.models.Recommendation>`
            :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
             if raw=true
            """
            # Construct URL
            url = '/subscriptions/{subscriptionId}/providers/Microsoft.Web/recommendations'
            path_format_arguments = {
                'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
            }
            url = self._client.format_url(url, **path_format_arguments)

            # Construct parameters
            query_parameters = {}
            if featured is not None:
                query_parameters['featured'] = self._serialize.query("featured", featured, 'bool')
            if filter is not None:
                query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
            query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str')

            # Construct headers
            header_parameters = {}
            header_parameters['Content-Type'] = 'application/json; charset=utf-8'
            if self.config.generate_client_request_id:
                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
            if custom_headers:
                header_parameters.update(custom_headers)
            if self.config.accept_language is not None:
                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

            # Construct and send request
            request = self._client.get(url, query_parameters)
            response = self._client.send(request, header_parameters, **operation_config)

            if response.status_code not in [200]:
                exp = CloudError(response)
                exp.request_id = response.headers.get('x-ms-request-id')
                raise exp

            deserialized = None

            if response.status_code == 200:
                deserialized = self._deserialize('[Recommendation]', response)

            if raw:
                client_raw_response = ClientRawResponse(deserialized, response)
                return client_raw_response

            return deserialized

        def get_rule_details_by_site_name(
                self, resource_group_name, site_name, name, custom_headers=None, raw=False, **operation_config):
            """Gets the detailed properties of the recommendation object for the
            specified web site.

            :param resource_group_name: Resource group name
            :type resource_group_name: str
            :param site_name: Site name
            :type site_name: str
            :param name: Recommendation rule name
            :type name: str
            :param dict custom_headers: headers that will be added to the request
            :param bool raw: returns the direct response alongside the
             deserialized response
            :param operation_config: :ref:`Operation configuration
             overrides<msrest:optionsforoperations>`.
            :rtype: :class:`RecommendationRule
             <azure.mgmt.web.models.RecommendationRule>`
            :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
             if raw=true
            """
            # Construct URL
            url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{siteName}/recommendations/{name}'
            path_format_arguments = {
                'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
                'siteName': self._serialize.url("site_name", site_name, 'str'),
                'name': self._serialize.url("name", name, 'str'),
                'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
            }
            url = self._client.format_url(url, **path_format_arguments)

            # Construct parameters
            query_parameters = {}
            query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str')

            # Construct headers
            header_parameters = {}
            header_parameters['Content-Type'] = 'application/json; charset=utf-8'
            if self.config.generate_client_request_id:
                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
            if custom_headers:
                header_parameters.update(custom_headers)
            if self.config.accept_language is not None:
                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

            # Construct and send request
            request = self._client.get(url, query_parameters)
            response = self._client.send(request, header_parameters, **operation_config)

            if response.status_code not in [200]:
                exp = CloudError(response)
                exp.request_id = response.headers.get('x-ms-request-id')
                raise exp

            deserialized = None

            if response.status_code == 200:
                deserialized = self._deserialize('RecommendationRule', response)

            if raw:
                client_raw_response = ClientRawResponse(deserialized, response)
                return client_raw_response

            return deserialized

        def get_recommended_rules_for_site(
                self, resource_group_name, site_name, featured=None, site_sku=None, num_slots=None, custom_headers=None, raw=False, **operation_config):
            """Gets a list of recommendations associated with the specified web site.

            :param resource_group_name: Resource group name
            :type resource_group_name: str
            :param site_name: Site name
            :type site_name: str
            :param featured: If set, this API returns only the most critical
             recommendation among the others. Otherwise this API returns all
             recommendations available
            :type featured: bool
            :param site_sku: The name of site SKU.
            :type site_sku: str
            :param num_slots: The number of site slots associated to the site
            :type num_slots: int
            :param dict custom_headers: headers that will be added to the request
            :param bool raw: returns the direct response alongside the
             deserialized response
            :param operation_config: :ref:`Operation configuration
             overrides<msrest:optionsforoperations>`.
            :rtype: list of :class:`Recommendation
             <azure.mgmt.web.models.Recommendation>`
            :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
             if raw=true
            """
            # Construct URL
            url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{siteName}/recommendations'
            path_format_arguments = {
                'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
                'siteName': self._serialize.url("site_name", site_name, 'str'),
                'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
            }
            url = self._client.format_url(url, **path_format_arguments)

            # Construct parameters
            query_parameters = {}
            if featured is not None:
                query_parameters['featured'] = self._serialize.query("featured", featured, 'bool')
            if site_sku is not None:
                query_parameters['siteSku'] = self._serialize.query("site_sku", site_sku, 'str')
            if num_slots is not None:
                query_parameters['numSlots'] = self._serialize.query("num_slots", num_slots, 'int')
            query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str')

            # Construct headers
            header_parameters = {}
            header_parameters['Content-Type'] = 'application/json; charset=utf-8'
            if self.config.generate_client_request_id:
                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
            if custom_headers:
                header_parameters.update(custom_headers)
            if self.config.accept_language is not None:
                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

            # Construct and send request
            request = self._client.get(url, query_parameters)
            response = self._client.send(request, header_parameters, **operation_config)

            if response.status_code not in [200]:
                exp = CloudError(response)
                exp.request_id = response.headers.get('x-ms-request-id')
                raise exp

            deserialized = None

            if response.status_code == 200:
                deserialized = self._deserialize('[Recommendation]', response)

            if raw:
                client_raw_response = ClientRawResponse(deserialized, response)
                return client_raw_response

            return deserialized

        def get_recommendation_history_for_site(
                self, resource_group_name, site_name, start_time=None, end_time=None, custom_headers=None, raw=False, **operation_config):
            """Gets the list of past recommendations optionally specified by the time
            range.

            :param resource_group_name: Resource group name
            :type resource_group_name: str
            :param site_name: Site name
            :type site_name: str
            :param start_time: The start time of a time range to query, e.g.
             $filter=startTime eq '2015-01-01T00:00:00Z' and endTime eq
             '2015-01-02T00:00:00Z'
            :type start_time: str
            :param end_time: The end time of a time range to query, e.g.
             $filter=startTime eq '2015-01-01T00:00:00Z' and endTime eq
             '2015-01-02T00:00:00Z'
            :type end_time: str
            :param dict custom_headers: headers that will be added to the request
            :param bool raw: returns the direct response alongside the
             deserialized response
            :param operation_config: :ref:`Operation configuration
             overrides<msrest:optionsforoperations>`.
            :rtype: list of :class:`Recommendation
             <azure.mgmt.web.models.Recommendation>`
            :rtype: :class:`ClientRawResponse<msrest.pipeline.ClientRawResponse>`
             if raw=true
            """
            # Construct URL
            url = '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{siteName}/recommendationHistory'
            path_format_arguments = {
                'resourceGroupName': self._serialize.url("resource_group_name", resource_group_name, 'str'),
                'siteName': self._serialize.url("site_name", site_name, 'str'),
                'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
            }
            url = self._client.format_url(url, **path_format_arguments)

            # Construct parameters
            query_parameters = {}
            if start_time is not None:
                query_parameters['startTime'] = self._serialize.query("start_time", start_time, 'str')
            if end_time is not None:
                query_parameters['endTime'] = self._serialize.query("end_time", end_time, 'str')
            query_parameters['api-version'] = self._serialize.query("self.config.api_version", self.config.api_version, 'str')

            # Construct headers
            header_parameters = {}
            header_parameters['Content-Type'] = 'application/json; charset=utf-8'
            if self.config.generate_client_request_id:
                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
            if custom_headers:
                header_parameters.update(custom_headers)
            if self.config.accept_language is not None:
                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')

            # Construct and send request
            request = self._client.get(url, query_parameters)
            response = self._client.send(request, header_parameters, **operation_config)

            if response.status_code not in [200]:
                exp = CloudError(response)
                exp.request_id = response.headers.get('x-ms-request-id')
                raise exp

            deserialized = None

            if response.status_code == 200:
                deserialized = self._deserialize('[Recommendation]', response)

            if raw:
                client_raw_response = ClientRawResponse(deserialized, response)
                return client_raw_response

            return deserialized