# 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::ADHybridHealthService::Mgmt::V2014_01_01
  #
  # REST APIs for Azure Active Directory Connect Health
  #
  class AddsServices
    include MsRestAzure

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

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

    #
    # Gets the details of Active Directory Domain Service, for a tenant, that are
    # onboarded to Azure Active Directory Connect Health.
    #
    # @param filter [String] The service property filter to apply.
    # @param service_type [String] The service type for the services onboarded to
    # Azure Active Directory Connect Health. Depending on whether the service is
    # monitoring, ADFS, Sync or ADDS roles, the service type can either be
    # AdFederationService or AadSyncService or AdDomainService.
    # @param skip_count [Integer] The skip count, which specifies the number of
    # elements that can be bypassed from a sequence and then return the remaining
    # elements.
    # @param take_count [Integer] The take count , which specifies the number of
    # elements that can be returned from a sequence.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<ServiceProperties>] operation results.
    #
    def list(filter:nil, service_type:nil, skip_count:nil, take_count:nil, custom_headers:nil)
      first_page = list_as_lazy(filter:filter, service_type:service_type, skip_count:skip_count, take_count:take_count, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # Gets the details of Active Directory Domain Service, for a tenant, that are
    # onboarded to Azure Active Directory Connect Health.
    #
    # @param filter [String] The service property filter to apply.
    # @param service_type [String] The service type for the services onboarded to
    # Azure Active Directory Connect Health. Depending on whether the service is
    # monitoring, ADFS, Sync or ADDS roles, the service type can either be
    # AdFederationService or AadSyncService or AdDomainService.
    # @param skip_count [Integer] The skip count, which specifies the number of
    # elements that can be bypassed from a sequence and then return the remaining
    # elements.
    # @param take_count [Integer] The take count , which specifies the number of
    # elements that can be returned from a sequence.
    # @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(filter:nil, service_type:nil, skip_count:nil, take_count:nil, custom_headers:nil)
      list_async(filter:filter, service_type:service_type, skip_count:skip_count, take_count:take_count, custom_headers:custom_headers).value!
    end

    #
    # Gets the details of Active Directory Domain Service, for a tenant, that are
    # onboarded to Azure Active Directory Connect Health.
    #
    # @param filter [String] The service property filter to apply.
    # @param service_type [String] The service type for the services onboarded to
    # Azure Active Directory Connect Health. Depending on whether the service is
    # monitoring, ADFS, Sync or ADDS roles, the service type can either be
    # AdFederationService or AadSyncService or AdDomainService.
    # @param skip_count [Integer] The skip count, which specifies the number of
    # elements that can be bypassed from a sequence and then return the remaining
    # elements.
    # @param take_count [Integer] The take count , which specifies the number of
    # elements that can be returned from a sequence.
    # @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(filter:nil, service_type:nil, skip_count:nil, take_count:nil, custom_headers: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 = 'providers/Microsoft.ADHybridHealthService/addsservices'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          query_params: {'$filter' => filter,'serviceType' => service_type,'skipCount' => skip_count,'takeCount' => take_count,'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::Services.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

    #
    # Onboards a service for a given tenant in Azure Active Directory Connect
    # Health.
    #
    # @param service [ServiceProperties] The service object.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ServiceProperties] operation results.
    #
    def add(service, custom_headers:nil)
      response = add_async(service, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Onboards a service for a given tenant in Azure Active Directory Connect
    # Health.
    #
    # @param service [ServiceProperties] The service object.
    # @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 add_with_http_info(service, custom_headers:nil)
      add_async(service, custom_headers:custom_headers).value!
    end

    #
    # Onboards a service for a given tenant in Azure Active Directory Connect
    # Health.
    #
    # @param service [ServiceProperties] The service object.
    # @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 add_async(service, custom_headers:nil)
      fail ArgumentError, '@client.api_version is nil' if @client.api_version.nil?
      fail ArgumentError, 'service is nil' if service.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?

      # Serialize Request
      request_mapper = Azure::ADHybridHealthService::Mgmt::V2014_01_01::Models::ServiceProperties.mapper()
      request_content = @client.serialize(request_mapper,  service)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'providers/Microsoft.ADHybridHealthService/addsservices'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          query_params: {'api-version' => @client.api_version},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:post, 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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::ServiceProperties.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

    #
    # Gets the details of an Active Directory Domain Service for a tenant having
    # Azure AD Premium license and is onboarded to Azure Active Directory Connect
    # Health.
    #
    # @param service_name [String] The name of the service.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ServiceProperties] operation results.
    #
    def get(service_name, custom_headers:nil)
      response = get_async(service_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the details of an Active Directory Domain Service for a tenant having
    # Azure AD Premium license and is onboarded to Azure Active Directory Connect
    # Health.
    #
    # @param service_name [String] The name of the service.
    # @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 get_with_http_info(service_name, custom_headers:nil)
      get_async(service_name, custom_headers:custom_headers).value!
    end

    #
    # Gets the details of an Active Directory Domain Service for a tenant having
    # Azure AD Premium license and is onboarded to Azure Active Directory Connect
    # Health.
    #
    # @param service_name [String] The name of the service.
    # @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 get_async(service_name, custom_headers:nil)
      fail ArgumentError, 'service_name is nil' if service_name.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 = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceName' => service_name},
          query_params: {'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::ServiceProperties.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

    #
    # Deletes an Active Directory Domain Service which is onboarded to Azure Active
    # Directory Connect Health.
    #
    # @param service_name [String] The name of the service which needs to be
    # deleted.
    # @param confirm [Boolean] Indicates if the service will be permanently deleted
    # or disabled. True indicates that the service will be permanently deleted and
    # False indicates that the service will be marked disabled and then deleted
    # after 30 days, if it is not re-registered.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def delete(service_name, confirm:nil, custom_headers:nil)
      response = delete_async(service_name, confirm:confirm, custom_headers:custom_headers).value!
      nil
    end

    #
    # Deletes an Active Directory Domain Service which is onboarded to Azure Active
    # Directory Connect Health.
    #
    # @param service_name [String] The name of the service which needs to be
    # deleted.
    # @param confirm [Boolean] Indicates if the service will be permanently deleted
    # or disabled. True indicates that the service will be permanently deleted and
    # False indicates that the service will be marked disabled and then deleted
    # after 30 days, if it is not re-registered.
    # @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 delete_with_http_info(service_name, confirm:nil, custom_headers:nil)
      delete_async(service_name, confirm:confirm, custom_headers:custom_headers).value!
    end

    #
    # Deletes an Active Directory Domain Service which is onboarded to Azure Active
    # Directory Connect Health.
    #
    # @param service_name [String] The name of the service which needs to be
    # deleted.
    # @param confirm [Boolean] Indicates if the service will be permanently deleted
    # or disabled. True indicates that the service will be permanently deleted and
    # False indicates that the service will be marked disabled and then deleted
    # after 30 days, if it is not re-registered.
    # @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 delete_async(service_name, confirm:nil, custom_headers:nil)
      fail ArgumentError, 'service_name is nil' if service_name.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 = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceName' => service_name},
          query_params: {'confirm' => confirm,'api-version' => @client.api_version},
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:delete, 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 == 204
          error_model = JSON.load(response_content)
          fail MsRestAzure::AzureOperationError.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?

        result
      end

      promise.execute
    end

    #
    # Updates an Active Directory Domain Service properties of an onboarded
    # service.
    #
    # @param service_name [String] The name of the service which needs to be
    # deleted.
    # @param service [ServiceProperties] The service object.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ServiceProperties] operation results.
    #
    def update(service_name, service, custom_headers:nil)
      response = update_async(service_name, service, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Updates an Active Directory Domain Service properties of an onboarded
    # service.
    #
    # @param service_name [String] The name of the service which needs to be
    # deleted.
    # @param service [ServiceProperties] The service object.
    # @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 update_with_http_info(service_name, service, custom_headers:nil)
      update_async(service_name, service, custom_headers:custom_headers).value!
    end

    #
    # Updates an Active Directory Domain Service properties of an onboarded
    # service.
    #
    # @param service_name [String] The name of the service which needs to be
    # deleted.
    # @param service [ServiceProperties] The service object.
    # @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 update_async(service_name, service, custom_headers:nil)
      fail ArgumentError, 'service_name is nil' if service_name.nil?
      fail ArgumentError, 'service is nil' if service.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?

      # Serialize Request
      request_mapper = Azure::ADHybridHealthService::Mgmt::V2014_01_01::Models::ServiceProperties.mapper()
      request_content = @client.serialize(request_mapper,  service)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceName' => service_name},
          query_params: {'api-version' => @client.api_version},
          body: request_content,
          headers: request_headers.merge(custom_headers || {}),
          base_url: request_url
      }
      promise = @client.make_request_async(:patch, 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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::ServiceProperties.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

    #
    # Gets the forest summary for a given Active Directory Domain Service, that is
    # onboarded to Azure Active Directory Connect Health.
    #
    # @param service_name [String] The name of the service.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ForestSummary] operation results.
    #
    def get_forest_summary(service_name, custom_headers:nil)
      response = get_forest_summary_async(service_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the forest summary for a given Active Directory Domain Service, that is
    # onboarded to Azure Active Directory Connect Health.
    #
    # @param service_name [String] The name of the service.
    # @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 get_forest_summary_with_http_info(service_name, custom_headers:nil)
      get_forest_summary_async(service_name, custom_headers:custom_headers).value!
    end

    #
    # Gets the forest summary for a given Active Directory Domain Service, that is
    # onboarded to Azure Active Directory Connect Health.
    #
    # @param service_name [String] The name of the service.
    # @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 get_forest_summary_async(service_name, custom_headers:nil)
      fail ArgumentError, 'service_name is nil' if service_name.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 = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/forestsummary'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceName' => service_name},
          query_params: {'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::ForestSummary.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

    #
    # Gets the average of the metric values for a given metric and group
    # combination.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param group_name [String] The group name
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<Item>] operation results.
    #
    def list_metrics_average(service_name, metric_name, group_name, custom_headers:nil)
      first_page = list_metrics_average_as_lazy(service_name, metric_name, group_name, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # Gets the average of the metric values for a given metric and group
    # combination.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param group_name [String] The group name
    # @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_metrics_average_with_http_info(service_name, metric_name, group_name, custom_headers:nil)
      list_metrics_average_async(service_name, metric_name, group_name, custom_headers:custom_headers).value!
    end

    #
    # Gets the average of the metric values for a given metric and group
    # combination.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param group_name [String] The group name
    # @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_metrics_average_async(service_name, metric_name, group_name, custom_headers:nil)
      fail ArgumentError, 'service_name is nil' if service_name.nil?
      fail ArgumentError, 'metric_name is nil' if metric_name.nil?
      fail ArgumentError, 'group_name is nil' if group_name.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 = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/metrics/{metricName}/groups/{groupName}/average'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceName' => service_name,'metricName' => metric_name,'groupName' => group_name},
          query_params: {'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::Metrics.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

    #
    # Gets the sum of the metric values for a given metric and group combination.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param group_name [String] The group name
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<Item>] operation results.
    #
    def list_metrics_sum(service_name, metric_name, group_name, custom_headers:nil)
      first_page = list_metrics_sum_as_lazy(service_name, metric_name, group_name, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # Gets the sum of the metric values for a given metric and group combination.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param group_name [String] The group name
    # @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_metrics_sum_with_http_info(service_name, metric_name, group_name, custom_headers:nil)
      list_metrics_sum_async(service_name, metric_name, group_name, custom_headers:custom_headers).value!
    end

    #
    # Gets the sum of the metric values for a given metric and group combination.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param group_name [String] The group name
    # @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_metrics_sum_async(service_name, metric_name, group_name, custom_headers:nil)
      fail ArgumentError, 'service_name is nil' if service_name.nil?
      fail ArgumentError, 'metric_name is nil' if metric_name.nil?
      fail ArgumentError, 'group_name is nil' if group_name.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 = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/metrics/{metricName}/groups/{groupName}/sum'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceName' => service_name,'metricName' => metric_name,'groupName' => group_name},
          query_params: {'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::Metrics.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

    #
    # Gets the service related metrics information.
    #
    # @param service_name [String] The name of the service.
    # @param filter [String] The metric metadata property filter to apply.
    # @param perf_counter [Boolean] Indicates if only performance counter metrics
    # are requested.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<MetricMetadata>] operation results.
    #
    def list_metric_metadata(service_name, filter:nil, perf_counter:nil, custom_headers:nil)
      first_page = list_metric_metadata_as_lazy(service_name, filter:filter, perf_counter:perf_counter, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # Gets the service related metrics information.
    #
    # @param service_name [String] The name of the service.
    # @param filter [String] The metric metadata property filter to apply.
    # @param perf_counter [Boolean] Indicates if only performance counter metrics
    # are requested.
    # @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_metric_metadata_with_http_info(service_name, filter:nil, perf_counter:nil, custom_headers:nil)
      list_metric_metadata_async(service_name, filter:filter, perf_counter:perf_counter, custom_headers:custom_headers).value!
    end

    #
    # Gets the service related metrics information.
    #
    # @param service_name [String] The name of the service.
    # @param filter [String] The metric metadata property filter to apply.
    # @param perf_counter [Boolean] Indicates if only performance counter metrics
    # are requested.
    # @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_metric_metadata_async(service_name, filter:nil, perf_counter:nil, custom_headers:nil)
      fail ArgumentError, 'service_name is nil' if service_name.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 = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/metricmetadata'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceName' => service_name},
          query_params: {'$filter' => filter,'perfCounter' => perf_counter,'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::MetricMetadataList.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

    #
    # Gets the service related metric information.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MetricMetadata] operation results.
    #
    def get_metric_metadata(service_name, metric_name, custom_headers:nil)
      response = get_metric_metadata_async(service_name, metric_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the service related metric information.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @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 get_metric_metadata_with_http_info(service_name, metric_name, custom_headers:nil)
      get_metric_metadata_async(service_name, metric_name, custom_headers:custom_headers).value!
    end

    #
    # Gets the service related metric information.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @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 get_metric_metadata_async(service_name, metric_name, custom_headers:nil)
      fail ArgumentError, 'service_name is nil' if service_name.nil?
      fail ArgumentError, 'metric_name is nil' if metric_name.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 = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/metricmetadata/{metricName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceName' => service_name,'metricName' => metric_name},
          query_params: {'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::MetricMetadata.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

    #
    # Gets the service related metrics for a given metric and group combination.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param group_name [String] The group name
    # @param group_key [String] The group key
    # @param from_date [DateTime] The start date.
    # @param to_date [DateTime] The end date.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MetricSets] operation results.
    #
    def get_metric_metadata_for_group(service_name, metric_name, group_name, group_key:nil, from_date:nil, to_date:nil, custom_headers:nil)
      response = get_metric_metadata_for_group_async(service_name, metric_name, group_name, group_key:group_key, from_date:from_date, to_date:to_date, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the service related metrics for a given metric and group combination.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param group_name [String] The group name
    # @param group_key [String] The group key
    # @param from_date [DateTime] The start date.
    # @param to_date [DateTime] The end date.
    # @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 get_metric_metadata_for_group_with_http_info(service_name, metric_name, group_name, group_key:nil, from_date:nil, to_date:nil, custom_headers:nil)
      get_metric_metadata_for_group_async(service_name, metric_name, group_name, group_key:group_key, from_date:from_date, to_date:to_date, custom_headers:custom_headers).value!
    end

    #
    # Gets the service related metrics for a given metric and group combination.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param group_name [String] The group name
    # @param group_key [String] The group key
    # @param from_date [DateTime] The start date.
    # @param to_date [DateTime] The end date.
    # @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 get_metric_metadata_for_group_async(service_name, metric_name, group_name, group_key:nil, from_date:nil, to_date:nil, custom_headers:nil)
      fail ArgumentError, 'service_name is nil' if service_name.nil?
      fail ArgumentError, 'metric_name is nil' if metric_name.nil?
      fail ArgumentError, 'group_name is nil' if group_name.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 = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/metricmetadata/{metricName}/groups/{groupName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceName' => service_name,'metricName' => metric_name,'groupName' => group_name},
          query_params: {'groupKey' => group_key,'fromDate' => from_date,'toDate' => to_date,'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::MetricSets.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

    #
    # Gets complete domain controller list along with replication details for a
    # given Active Directory Domain Service, that is onboarded to Azure Active
    # Directory Connect Health.
    #
    # @param service_name [String] The name of the service.
    # @param filter [String] The server property filter to apply.
    # @param with_details [Boolean] Indicates if InboundReplicationNeighbor details
    # are required or not.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ReplicationDetailsList] operation results.
    #
    def list_replication_details(service_name, filter:nil, with_details:nil, custom_headers:nil)
      response = list_replication_details_async(service_name, filter:filter, with_details:with_details, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets complete domain controller list along with replication details for a
    # given Active Directory Domain Service, that is onboarded to Azure Active
    # Directory Connect Health.
    #
    # @param service_name [String] The name of the service.
    # @param filter [String] The server property filter to apply.
    # @param with_details [Boolean] Indicates if InboundReplicationNeighbor details
    # are required or not.
    # @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_replication_details_with_http_info(service_name, filter:nil, with_details:nil, custom_headers:nil)
      list_replication_details_async(service_name, filter:filter, with_details:with_details, custom_headers:custom_headers).value!
    end

    #
    # Gets complete domain controller list along with replication details for a
    # given Active Directory Domain Service, that is onboarded to Azure Active
    # Directory Connect Health.
    #
    # @param service_name [String] The name of the service.
    # @param filter [String] The server property filter to apply.
    # @param with_details [Boolean] Indicates if InboundReplicationNeighbor details
    # are required or not.
    # @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_replication_details_async(service_name, filter:nil, with_details:nil, custom_headers:nil)
      fail ArgumentError, 'service_name is nil' if service_name.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 = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/replicationdetails'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceName' => service_name},
          query_params: {'$filter' => filter,'withDetails' => with_details,'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::ReplicationDetailsList.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

    #
    # Gets complete domain controller list along with replication details for a
    # given Active Directory Domain Service, that is onboarded to Azure Active
    # Directory Connect Health.
    #
    # @param service_name [String] The name of the service.
    # @param is_groupby_site [Boolean] Indicates if the result should be grouped by
    # site or not.
    # @param query [String] The custom query.
    # @param filter [String] The server property filter to apply.
    # @param take_count [Integer] The take count , which specifies the number of
    # elements that can be returned from a sequence.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [ReplicationSummaryList] operation results.
    #
    def list_replication_summary(service_name, is_groupby_site, query, filter:nil, take_count:nil, custom_headers:nil)
      response = list_replication_summary_async(service_name, is_groupby_site, query, filter:filter, take_count:take_count, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets complete domain controller list along with replication details for a
    # given Active Directory Domain Service, that is onboarded to Azure Active
    # Directory Connect Health.
    #
    # @param service_name [String] The name of the service.
    # @param is_groupby_site [Boolean] Indicates if the result should be grouped by
    # site or not.
    # @param query [String] The custom query.
    # @param filter [String] The server property filter to apply.
    # @param take_count [Integer] The take count , which specifies the number of
    # elements that can be returned from a sequence.
    # @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_replication_summary_with_http_info(service_name, is_groupby_site, query, filter:nil, take_count:nil, custom_headers:nil)
      list_replication_summary_async(service_name, is_groupby_site, query, filter:filter, take_count:take_count, custom_headers:custom_headers).value!
    end

    #
    # Gets complete domain controller list along with replication details for a
    # given Active Directory Domain Service, that is onboarded to Azure Active
    # Directory Connect Health.
    #
    # @param service_name [String] The name of the service.
    # @param is_groupby_site [Boolean] Indicates if the result should be grouped by
    # site or not.
    # @param query [String] The custom query.
    # @param filter [String] The server property filter to apply.
    # @param take_count [Integer] The take count , which specifies the number of
    # elements that can be returned from a sequence.
    # @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_replication_summary_async(service_name, is_groupby_site, query, filter:nil, take_count:nil, custom_headers:nil)
      fail ArgumentError, 'service_name is nil' if service_name.nil?
      fail ArgumentError, 'is_groupby_site is nil' if is_groupby_site.nil?
      fail ArgumentError, 'query is nil' if query.nil?
      next_partition_key = ''
      next_row_key = ''
      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 = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/replicationsummary'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceName' => service_name},
          query_params: {'$filter' => filter,'isGroupbySite' => is_groupby_site,'query' => query,'nextPartitionKey' => next_partition_key,'nextRowKey' => next_row_key,'takeCount' => take_count,'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::ReplicationSummaryList.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

    #
    # Gets the details of an alert for a given Active Directory Domain Controller
    # service and server combination.
    #
    # @param service_member_id The server Id for which the alert details needs to
    # be queried.
    # @param service_name [String] The name of the service.
    # @param filter [String] The alert property filter to apply.
    # @param state [String] The alert state to query for.
    # @param from [DateTime] The start date to query for.
    # @param to [DateTime] The end date till when to query for.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<Alert>] operation results.
    #
    def list_server_alerts(service_member_id, service_name, filter:nil, state:nil, from:nil, to:nil, custom_headers:nil)
      first_page = list_server_alerts_as_lazy(service_member_id, service_name, filter:filter, state:state, from:from, to:to, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # Gets the details of an alert for a given Active Directory Domain Controller
    # service and server combination.
    #
    # @param service_member_id The server Id for which the alert details needs to
    # be queried.
    # @param service_name [String] The name of the service.
    # @param filter [String] The alert property filter to apply.
    # @param state [String] The alert state to query for.
    # @param from [DateTime] The start date to query for.
    # @param to [DateTime] The end date till when to query for.
    # @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_server_alerts_with_http_info(service_member_id, service_name, filter:nil, state:nil, from:nil, to:nil, custom_headers:nil)
      list_server_alerts_async(service_member_id, service_name, filter:filter, state:state, from:from, to:to, custom_headers:custom_headers).value!
    end

    #
    # Gets the details of an alert for a given Active Directory Domain Controller
    # service and server combination.
    #
    # @param service_member_id The server Id for which the alert details needs to
    # be queried.
    # @param service_name [String] The name of the service.
    # @param filter [String] The alert property filter to apply.
    # @param state [String] The alert state to query for.
    # @param from [DateTime] The start date to query for.
    # @param to [DateTime] The end date till when to query for.
    # @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_server_alerts_async(service_member_id, service_name, filter:nil, state:nil, from:nil, to:nil, custom_headers:nil)
      fail ArgumentError, 'service_member_id is nil' if service_member_id.nil?
      fail ArgumentError, 'service_name is nil' if service_name.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 = 'providers/Microsoft.ADHybridHealthService/addsservices/{serviceName}/servicemembers/{serviceMemberId}/alerts'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'serviceMemberId' => service_member_id,'serviceName' => service_name},
          query_params: {'$filter' => filter,'state' => state,'from' => from,'to' => to,'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::Alerts.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

    #
    # Gets the details of Active Directory Domain Services for a tenant having
    # Azure AD Premium license and is onboarded to Azure Active Directory Connect
    # Health.
    #
    # @param filter [String] The service property filter to apply.
    # @param service_type [String] The service type for the services onboarded to
    # Azure Active Directory Connect Health. Depending on whether the service is
    # monitoring, ADFS, Sync or ADDS roles, the service type can either be
    # AdFederationService or AadSyncService or AdDomainService.
    # @param skip_count [Integer] The skip count, which specifies the number of
    # elements that can be bypassed from a sequence and then return the remaining
    # elements.
    # @param take_count [Integer] The take count , which specifies the number of
    # elements that can be returned from a sequence.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<ServiceProperties>] operation results.
    #
    def list_premium_services(filter:nil, service_type:nil, skip_count:nil, take_count:nil, custom_headers:nil)
      first_page = list_premium_services_as_lazy(filter:filter, service_type:service_type, skip_count:skip_count, take_count:take_count, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # Gets the details of Active Directory Domain Services for a tenant having
    # Azure AD Premium license and is onboarded to Azure Active Directory Connect
    # Health.
    #
    # @param filter [String] The service property filter to apply.
    # @param service_type [String] The service type for the services onboarded to
    # Azure Active Directory Connect Health. Depending on whether the service is
    # monitoring, ADFS, Sync or ADDS roles, the service type can either be
    # AdFederationService or AadSyncService or AdDomainService.
    # @param skip_count [Integer] The skip count, which specifies the number of
    # elements that can be bypassed from a sequence and then return the remaining
    # elements.
    # @param take_count [Integer] The take count , which specifies the number of
    # elements that can be returned from a sequence.
    # @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_premium_services_with_http_info(filter:nil, service_type:nil, skip_count:nil, take_count:nil, custom_headers:nil)
      list_premium_services_async(filter:filter, service_type:service_type, skip_count:skip_count, take_count:take_count, custom_headers:custom_headers).value!
    end

    #
    # Gets the details of Active Directory Domain Services for a tenant having
    # Azure AD Premium license and is onboarded to Azure Active Directory Connect
    # Health.
    #
    # @param filter [String] The service property filter to apply.
    # @param service_type [String] The service type for the services onboarded to
    # Azure Active Directory Connect Health. Depending on whether the service is
    # monitoring, ADFS, Sync or ADDS roles, the service type can either be
    # AdFederationService or AadSyncService or AdDomainService.
    # @param skip_count [Integer] The skip count, which specifies the number of
    # elements that can be bypassed from a sequence and then return the remaining
    # elements.
    # @param take_count [Integer] The take count , which specifies the number of
    # elements that can be returned from a sequence.
    # @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_premium_services_async(filter:nil, service_type:nil, skip_count:nil, take_count:nil, custom_headers: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 = 'providers/Microsoft.ADHybridHealthService/addsservices/premiumCheck'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          query_params: {'$filter' => filter,'serviceType' => service_type,'skipCount' => skip_count,'takeCount' => take_count,'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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::Services.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

    #
    # Gets the details of Active Directory Domain Service, for a tenant, that are
    # onboarded to Azure Active Directory Connect Health.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Services] operation results.
    #
    def list_next(next_page_link, custom_headers:nil)
      response = list_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the details of Active Directory Domain Service, for a tenant, that are
    # onboarded to Azure Active Directory Connect Health.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_next_with_http_info(next_page_link, custom_headers:nil)
      list_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # Gets the details of Active Directory Domain Service, for a tenant, that are
    # onboarded to Azure Active Directory Connect Health.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_next_async(next_page_link, custom_headers:nil)
      fail ArgumentError, 'next_page_link is nil' if next_page_link.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 = '{nextLink}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'nextLink' => next_page_link},
          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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::Services.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

    #
    # Gets the average of the metric values for a given metric and group
    # combination.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Metrics] operation results.
    #
    def list_metrics_average_next(next_page_link, custom_headers:nil)
      response = list_metrics_average_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the average of the metric values for a given metric and group
    # combination.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_metrics_average_next_with_http_info(next_page_link, custom_headers:nil)
      list_metrics_average_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # Gets the average of the metric values for a given metric and group
    # combination.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_metrics_average_next_async(next_page_link, custom_headers:nil)
      fail ArgumentError, 'next_page_link is nil' if next_page_link.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 = '{nextLink}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'nextLink' => next_page_link},
          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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::Metrics.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

    #
    # Gets the sum of the metric values for a given metric and group combination.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Metrics] operation results.
    #
    def list_metrics_sum_next(next_page_link, custom_headers:nil)
      response = list_metrics_sum_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the sum of the metric values for a given metric and group combination.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_metrics_sum_next_with_http_info(next_page_link, custom_headers:nil)
      list_metrics_sum_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # Gets the sum of the metric values for a given metric and group combination.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_metrics_sum_next_async(next_page_link, custom_headers:nil)
      fail ArgumentError, 'next_page_link is nil' if next_page_link.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 = '{nextLink}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'nextLink' => next_page_link},
          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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::Metrics.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

    #
    # Gets the service related metrics information.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MetricMetadataList] operation results.
    #
    def list_metric_metadata_next(next_page_link, custom_headers:nil)
      response = list_metric_metadata_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the service related metrics information.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_metric_metadata_next_with_http_info(next_page_link, custom_headers:nil)
      list_metric_metadata_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # Gets the service related metrics information.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_metric_metadata_next_async(next_page_link, custom_headers:nil)
      fail ArgumentError, 'next_page_link is nil' if next_page_link.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 = '{nextLink}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'nextLink' => next_page_link},
          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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::MetricMetadataList.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

    #
    # Gets the details of an alert for a given Active Directory Domain Controller
    # service and server combination.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Alerts] operation results.
    #
    def list_server_alerts_next(next_page_link, custom_headers:nil)
      response = list_server_alerts_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the details of an alert for a given Active Directory Domain Controller
    # service and server combination.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_server_alerts_next_with_http_info(next_page_link, custom_headers:nil)
      list_server_alerts_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # Gets the details of an alert for a given Active Directory Domain Controller
    # service and server combination.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_server_alerts_next_async(next_page_link, custom_headers:nil)
      fail ArgumentError, 'next_page_link is nil' if next_page_link.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 = '{nextLink}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'nextLink' => next_page_link},
          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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::Alerts.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

    #
    # Gets the details of Active Directory Domain Services for a tenant having
    # Azure AD Premium license and is onboarded to Azure Active Directory Connect
    # Health.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Services] operation results.
    #
    def list_premium_services_next(next_page_link, custom_headers:nil)
      response = list_premium_services_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Gets the details of Active Directory Domain Services for a tenant having
    # Azure AD Premium license and is onboarded to Azure Active Directory Connect
    # Health.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_premium_services_next_with_http_info(next_page_link, custom_headers:nil)
      list_premium_services_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # Gets the details of Active Directory Domain Services for a tenant having
    # Azure AD Premium license and is onboarded to Azure Active Directory Connect
    # Health.
    #
    # @param next_page_link [String] The NextLink from the previous successful call
    # to List operation.
    # @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_premium_services_next_async(next_page_link, custom_headers:nil)
      fail ArgumentError, 'next_page_link is nil' if next_page_link.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 = '{nextLink}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          skip_encoding_path_params: {'nextLink' => next_page_link},
          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 MsRestAzure::AzureOperationError.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::ADHybridHealthService::Mgmt::V2014_01_01::Models::Services.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

    #
    # Gets the details of Active Directory Domain Service, for a tenant, that are
    # onboarded to Azure Active Directory Connect Health.
    #
    # @param filter [String] The service property filter to apply.
    # @param service_type [String] The service type for the services onboarded to
    # Azure Active Directory Connect Health. Depending on whether the service is
    # monitoring, ADFS, Sync or ADDS roles, the service type can either be
    # AdFederationService or AadSyncService or AdDomainService.
    # @param skip_count [Integer] The skip count, which specifies the number of
    # elements that can be bypassed from a sequence and then return the remaining
    # elements.
    # @param take_count [Integer] The take count , which specifies the number of
    # elements that can be returned from a sequence.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Services] which provide lazy access to pages of the response.
    #
    def list_as_lazy(filter:nil, service_type:nil, skip_count:nil, take_count:nil, custom_headers:nil)
      response = list_async(filter:filter, service_type:service_type, skip_count:skip_count, take_count:take_count, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # Gets the average of the metric values for a given metric and group
    # combination.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param group_name [String] The group name
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Metrics] which provide lazy access to pages of the response.
    #
    def list_metrics_average_as_lazy(service_name, metric_name, group_name, custom_headers:nil)
      response = list_metrics_average_async(service_name, metric_name, group_name, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_metrics_average_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # Gets the sum of the metric values for a given metric and group combination.
    #
    # @param service_name [String] The name of the service.
    # @param metric_name [String] The metric name
    # @param group_name [String] The group name
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Metrics] which provide lazy access to pages of the response.
    #
    def list_metrics_sum_as_lazy(service_name, metric_name, group_name, custom_headers:nil)
      response = list_metrics_sum_async(service_name, metric_name, group_name, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_metrics_sum_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # Gets the service related metrics information.
    #
    # @param service_name [String] The name of the service.
    # @param filter [String] The metric metadata property filter to apply.
    # @param perf_counter [Boolean] Indicates if only performance counter metrics
    # are requested.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [MetricMetadataList] which provide lazy access to pages of the
    # response.
    #
    def list_metric_metadata_as_lazy(service_name, filter:nil, perf_counter:nil, custom_headers:nil)
      response = list_metric_metadata_async(service_name, filter:filter, perf_counter:perf_counter, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_metric_metadata_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # Gets the details of an alert for a given Active Directory Domain Controller
    # service and server combination.
    #
    # @param service_member_id The server Id for which the alert details needs to
    # be queried.
    # @param service_name [String] The name of the service.
    # @param filter [String] The alert property filter to apply.
    # @param state [String] The alert state to query for.
    # @param from [DateTime] The start date to query for.
    # @param to [DateTime] The end date till when to query for.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Alerts] which provide lazy access to pages of the response.
    #
    def list_server_alerts_as_lazy(service_member_id, service_name, filter:nil, state:nil, from:nil, to:nil, custom_headers:nil)
      response = list_server_alerts_async(service_member_id, service_name, filter:filter, state:state, from:from, to:to, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_server_alerts_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # Gets the details of Active Directory Domain Services for a tenant having
    # Azure AD Premium license and is onboarded to Azure Active Directory Connect
    # Health.
    #
    # @param filter [String] The service property filter to apply.
    # @param service_type [String] The service type for the services onboarded to
    # Azure Active Directory Connect Health. Depending on whether the service is
    # monitoring, ADFS, Sync or ADDS roles, the service type can either be
    # AdFederationService or AadSyncService or AdDomainService.
    # @param skip_count [Integer] The skip count, which specifies the number of
    # elements that can be bypassed from a sequence and then return the remaining
    # elements.
    # @param take_count [Integer] The take count , which specifies the number of
    # elements that can be returned from a sequence.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Services] which provide lazy access to pages of the response.
    #
    def list_premium_services_as_lazy(filter:nil, service_type:nil, skip_count:nil, take_count:nil, custom_headers:nil)
      response = list_premium_services_async(filter:filter, service_type:service_type, skip_count:skip_count, take_count:take_count, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_premium_services_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

  end
end
