# encoding: utf-8
# Code generated by Microsoft (R) AutoRest Code Generator.
# Changes may cause incorrect behavior and will be lost if the code is
# regenerated.

module Azure::Monitor::Mgmt::V2019_03_01
  #
  # Monitor Management Client
  #
  class Baselines
    include MsRestAzure

    #
    # Creates and initializes a new instance of the Baselines class.
    # @param client service class for accessing basic functionality.
    #
    def initialize(client)
      @client = client
    end

    # @return [MonitorManagementClient] reference to the MonitorManagementClient
    attr_reader :client

    #
    # **Lists the metric baseline values for a resource**.
    #
    # @param resource_uri [String] The identifier of the resource.
    # @param metricnames [String] The names of the metrics (comma separated) to
    # retrieve.
    # @param metricnamespace [String] Metric namespace to query metric definitions
    # for.
    # @param timespan [String] The timespan of the query. It is a string with the
    # following format 'startDateTime_ISO/endDateTime_ISO'.
    # @param interval [Duration] The interval (i.e. timegrain) of the query.
    # @param aggregation [String] The list of aggregation types (comma separated)
    # to retrieve.
    # @param sensitivities [String] The list of sensitivities (comma separated) to
    # retrieve.
    # @param filter [String] The **$filter** is used to reduce the set of metric
    # data returned.<br>Example:<br>Metric contains metadata A, B and C.<br>-
    # Return all time series of C where A = a1 and B = b1 or b2<br>**$filter=A eq
    # ‘a1’ and B eq ‘b1’ or B eq ‘b2’ and C eq ‘*’**<br>- Invalid
    # variant:<br>**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘*’ or B =
    # ‘b2’**<br>This is invalid because the logical or operator cannot separate two
    # different metadata names.<br>- Return all time series where A = a1, B = b1
    # and C = c1:<br>**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘c1’**<br>- Return
    # all time series where A = a1<br>**$filter=A eq ‘a1’ and B eq ‘*’ and C eq
    # ‘*’**.
    # @param result_type [ResultType] Allows retrieving only metadata of the
    # baseline. On data request all information is retrieved. Possible values
    # include: 'Data', 'Metadata'
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MetricBaselinesResponse] operation results.
    #
    def list(resource_uri, metricnames:nil, metricnamespace:nil, timespan:nil, interval:nil, aggregation:nil, sensitivities:nil, filter:nil, result_type:nil, custom_headers:nil)
      response = list_async(resource_uri, metricnames:metricnames, metricnamespace:metricnamespace, timespan:timespan, interval:interval, aggregation:aggregation, sensitivities:sensitivities, filter:filter, result_type:result_type, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # **Lists the metric baseline values for a resource**.
    #
    # @param resource_uri [String] The identifier of the resource.
    # @param metricnames [String] The names of the metrics (comma separated) to
    # retrieve.
    # @param metricnamespace [String] Metric namespace to query metric definitions
    # for.
    # @param timespan [String] The timespan of the query. It is a string with the
    # following format 'startDateTime_ISO/endDateTime_ISO'.
    # @param interval [Duration] The interval (i.e. timegrain) of the query.
    # @param aggregation [String] The list of aggregation types (comma separated)
    # to retrieve.
    # @param sensitivities [String] The list of sensitivities (comma separated) to
    # retrieve.
    # @param filter [String] The **$filter** is used to reduce the set of metric
    # data returned.<br>Example:<br>Metric contains metadata A, B and C.<br>-
    # Return all time series of C where A = a1 and B = b1 or b2<br>**$filter=A eq
    # ‘a1’ and B eq ‘b1’ or B eq ‘b2’ and C eq ‘*’**<br>- Invalid
    # variant:<br>**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘*’ or B =
    # ‘b2’**<br>This is invalid because the logical or operator cannot separate two
    # different metadata names.<br>- Return all time series where A = a1, B = b1
    # and C = c1:<br>**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘c1’**<br>- Return
    # all time series where A = a1<br>**$filter=A eq ‘a1’ and B eq ‘*’ and C eq
    # ‘*’**.
    # @param result_type [ResultType] Allows retrieving only metadata of the
    # baseline. On data request all information is retrieved. Possible values
    # include: 'Data', 'Metadata'
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MsRestAzure::AzureOperationResponse] HTTP response information.
    #
    def list_with_http_info(resource_uri, metricnames:nil, metricnamespace:nil, timespan:nil, interval:nil, aggregation:nil, sensitivities:nil, filter:nil, result_type:nil, custom_headers:nil)
      list_async(resource_uri, metricnames:metricnames, metricnamespace:metricnamespace, timespan:timespan, interval:interval, aggregation:aggregation, sensitivities:sensitivities, filter:filter, result_type:result_type, custom_headers:custom_headers).value!
    end

    #
    # **Lists the metric baseline values for a resource**.
    #
    # @param resource_uri [String] The identifier of the resource.
    # @param metricnames [String] The names of the metrics (comma separated) to
    # retrieve.
    # @param metricnamespace [String] Metric namespace to query metric definitions
    # for.
    # @param timespan [String] The timespan of the query. It is a string with the
    # following format 'startDateTime_ISO/endDateTime_ISO'.
    # @param interval [Duration] The interval (i.e. timegrain) of the query.
    # @param aggregation [String] The list of aggregation types (comma separated)
    # to retrieve.
    # @param sensitivities [String] The list of sensitivities (comma separated) to
    # retrieve.
    # @param filter [String] The **$filter** is used to reduce the set of metric
    # data returned.<br>Example:<br>Metric contains metadata A, B and C.<br>-
    # Return all time series of C where A = a1 and B = b1 or b2<br>**$filter=A eq
    # ‘a1’ and B eq ‘b1’ or B eq ‘b2’ and C eq ‘*’**<br>- Invalid
    # variant:<br>**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘*’ or B =
    # ‘b2’**<br>This is invalid because the logical or operator cannot separate two
    # different metadata names.<br>- Return all time series where A = a1, B = b1
    # and C = c1:<br>**$filter=A eq ‘a1’ and B eq ‘b1’ and C eq ‘c1’**<br>- Return
    # all time series where A = a1<br>**$filter=A eq ‘a1’ and B eq ‘*’ and C eq
    # ‘*’**.
    # @param result_type [ResultType] Allows retrieving only metadata of the
    # baseline. On data request all information is retrieved. Possible values
    # include: 'Data', 'Metadata'
    # @param [Hash{String => String}] A hash of custom headers that will be added
    # to the HTTP request.
    #
    # @return [Concurrent::Promise] Promise object which holds the HTTP response.
    #
    def list_async(resource_uri, metricnames:nil, metricnamespace:nil, timespan:nil, interval:nil, aggregation:nil, sensitivities:nil, filter:nil, result_type:nil, custom_headers:nil)
      fail ArgumentError, 'resource_uri is nil' if resource_uri.nil?
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?


      request_headers = {}
      request_headers['Content-Type'] = 'application/json; charset=utf-8'

      # Set Headers
      request_headers['x-ms-client-request-id'] = SecureRandom.uuid
      request_headers['accept-language'] = @client.accept_language unless @client.accept_language.nil?
      path_template = '{resourceUri}/providers/microsoft.insights/metricBaselines'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'resourceUri' => resource_uri},
          query_params: {'metricnames' => metricnames,'metricnamespace' => metricnamespace,'timespan' => timespan,'interval' => interval,'aggregation' => aggregation,'sensitivities' => sensitivities,'$filter' => filter,'resultType' => result_type,'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:get, path_template, options)

      promise = promise.then do |result|
        http_response = result.response
        status_code = http_response.status
        response_content = http_response.body
        unless status_code == 200
          error_model = JSON.load(response_content)
          fail MsRest::HttpOperationError.new(result.request, http_response, error_model)
        end

        result.request_id = http_response['x-ms-request-id'] unless http_response['x-ms-request-id'].nil?
        result.correlation_request_id = http_response['x-ms-correlation-request-id'] unless http_response['x-ms-correlation-request-id'].nil?
        result.client_request_id = http_response['x-ms-client-request-id'] unless http_response['x-ms-client-request-id'].nil?
        # Deserialize Response
        if status_code == 200
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::Monitor::Mgmt::V2019_03_01::Models::MetricBaselinesResponse.mapper()
            result.body = @client.deserialize(result_mapper, parsed_response)
          rescue Exception => e
            fail MsRest::DeserializationError.new('Error occurred in deserializing the response', e.message, e.backtrace, result)
          end
        end

        result
      end

      promise.execute
    end

  end
end
