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
12import uuid
13from msrest.pipeline import ClientRawResponse
14
15from .. import models
16
17
18class ForecastsOperations(object):
19    """ForecastsOperations operations.
20
21    :param client: Client for service requests.
22    :param config: Configuration of service client.
23    :param serializer: An object model serializer.
24    :param deserializer: An object model deserializer.
25    :ivar api_version: Version of the API to be used with the client request. The current version is 2019-04-01-preview. Constant value: "2019-04-01-preview".
26    """
27
28    models = models
29
30    def __init__(self, client, config, serializer, deserializer):
31
32        self._client = client
33        self._serialize = serializer
34        self._deserialize = deserializer
35        self.api_version = "2019-04-01-preview"
36
37        self.config = config
38
39    def list(
40            self, filter=None, custom_headers=None, raw=False, **operation_config):
41        """Lists the forecast charges by subscriptionId.
42
43        :param filter: May be used to filter forecasts by properties/usageDate
44         (Utc time), properties/chargeType or properties/grain. The filter
45         supports 'eq', 'lt', 'gt', 'le', 'ge', and 'and'. It does not
46         currently support 'ne', 'or', or 'not'.
47        :type filter: str
48        :param dict custom_headers: headers that will be added to the request
49        :param bool raw: returns the direct response alongside the
50         deserialized response
51        :param operation_config: :ref:`Operation configuration
52         overrides<msrest:optionsforoperations>`.
53        :return: An iterator like instance of Forecast
54        :rtype:
55         ~azure.mgmt.consumption.models.ForecastPaged[~azure.mgmt.consumption.models.Forecast]
56        :raises:
57         :class:`ErrorResponseException<azure.mgmt.consumption.models.ErrorResponseException>`
58        """
59        def internal_paging(next_link=None, raw=False):
60
61            if not next_link:
62                # Construct URL
63                url = self.list.metadata['url']
64                path_format_arguments = {
65                    'subscriptionId': self._serialize.url("self.config.subscription_id", self.config.subscription_id, 'str')
66                }
67                url = self._client.format_url(url, **path_format_arguments)
68
69                # Construct parameters
70                query_parameters = {}
71                if filter is not None:
72                    query_parameters['$filter'] = self._serialize.query("filter", filter, 'str')
73                query_parameters['api-version'] = self._serialize.query("self.api_version", self.api_version, 'str')
74
75            else:
76                url = next_link
77                query_parameters = {}
78
79            # Construct headers
80            header_parameters = {}
81            header_parameters['Accept'] = 'application/json'
82            if self.config.generate_client_request_id:
83                header_parameters['x-ms-client-request-id'] = str(uuid.uuid1())
84            if custom_headers:
85                header_parameters.update(custom_headers)
86            if self.config.accept_language is not None:
87                header_parameters['accept-language'] = self._serialize.header("self.config.accept_language", self.config.accept_language, 'str')
88
89            # Construct and send request
90            request = self._client.get(url, query_parameters, header_parameters)
91            response = self._client.send(request, stream=False, **operation_config)
92
93            if response.status_code not in [200]:
94                raise models.ErrorResponseException(self._deserialize, response)
95
96            return response
97
98        # Deserialize response
99        deserialized = models.ForecastPaged(internal_paging, self._deserialize.dependencies)
100
101        if raw:
102            header_dict = {}
103            client_raw_response = models.ForecastPaged(internal_paging, self._deserialize.dependencies, header_dict)
104            return client_raw_response
105
106        return deserialized
107    list.metadata = {'url': '/subscriptions/{subscriptionId}/providers/Microsoft.Consumption/forecasts'}
108