# 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::EventGrid::Mgmt::V2019_02_01_preview
  #
  # Azure EventGrid Management Client
  #
  class EventSubscriptions
    include MsRestAzure

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

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

    #
    # Get an event subscription
    #
    # Get properties of an event subscription
    #
    # @param scope [String] The scope of the event subscription. The scope can be a
    # subscription, or a resource group, or a top level resource belonging to a
    # resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscription] operation results.
    #
    def get(scope, event_subscription_name, custom_headers:nil)
      response = get_async(scope, event_subscription_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get an event subscription
    #
    # Get properties of an event subscription
    #
    # @param scope [String] The scope of the event subscription. The scope can be a
    # subscription, or a resource group, or a top level resource belonging to a
    # resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription
    # @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(scope, event_subscription_name, custom_headers:nil)
      get_async(scope, event_subscription_name, custom_headers:custom_headers).value!
    end

    #
    # Get an event subscription
    #
    # Get properties of an event subscription
    #
    # @param scope [String] The scope of the event subscription. The scope can be a
    # subscription, or a resource group, or a top level resource belonging to a
    # resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription
    # @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(scope, event_subscription_name, custom_headers:nil)
      fail ArgumentError, 'scope is nil' if scope.nil?
      fail ArgumentError, 'event_subscription_name is nil' if event_subscription_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 = '{scope}/providers/Microsoft.EventGrid/eventSubscriptions/{eventSubscriptionName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'eventSubscriptionName' => event_subscription_name},
          skip_encoding_path_params: {'scope' => scope},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscription.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

    #
    # Create or update an event subscription
    #
    # Asynchronously creates a new event subscription or updates an existing event
    # subscription based on the specified scope.
    #
    # @param scope [String] The identifier of the resource to which the event
    # subscription needs to be created or updated. The scope can be a subscription,
    # or a resource group, or a top level resource belonging to a resource provider
    # namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription. Event
    # subscription names must be between 3 and 64 characters in length and should
    # use alphanumeric letters only.
    # @param event_subscription_info [EventSubscription] Event subscription
    # properties containing the destination and filter information
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscription] operation results.
    #
    def create_or_update(scope, event_subscription_name, event_subscription_info, custom_headers:nil)
      response = create_or_update_async(scope, event_subscription_name, event_subscription_info, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # @param scope [String] The identifier of the resource to which the event
    # subscription needs to be created or updated. The scope can be a subscription,
    # or a resource group, or a top level resource belonging to a resource provider
    # namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription. Event
    # subscription names must be between 3 and 64 characters in length and should
    # use alphanumeric letters only.
    # @param event_subscription_info [EventSubscription] Event subscription
    # properties containing the destination and filter information
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Concurrent::Promise] promise which provides async access to http
    # response.
    #
    def create_or_update_async(scope, event_subscription_name, event_subscription_info, custom_headers:nil)
      # Send request
      promise = begin_create_or_update_async(scope, event_subscription_name, event_subscription_info, custom_headers:custom_headers)

      promise = promise.then do |response|
        # Defining deserialization method.
        deserialize_method = lambda do |parsed_response|
          result_mapper = Azure::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscription.mapper()
          parsed_response = @client.deserialize(result_mapper, parsed_response)
        end

        # Waiting for response.
        @client.get_long_running_operation_result(response, deserialize_method)
      end

      promise
    end

    #
    # Delete an event subscription
    #
    # Delete an existing event subscription
    #
    # @param scope [String] The scope of the event subscription. The scope can be a
    # subscription, or a resource group, or a top level resource belonging to a
    # resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    def delete(scope, event_subscription_name, custom_headers:nil)
      response = delete_async(scope, event_subscription_name, custom_headers:custom_headers).value!
      nil
    end

    #
    # @param scope [String] The scope of the event subscription. The scope can be a
    # subscription, or a resource group, or a top level resource belonging to a
    # resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Concurrent::Promise] promise which provides async access to http
    # response.
    #
    def delete_async(scope, event_subscription_name, custom_headers:nil)
      # Send request
      promise = begin_delete_async(scope, event_subscription_name, custom_headers:custom_headers)

      promise = promise.then do |response|
        # Defining deserialization method.
        deserialize_method = lambda do |parsed_response|
        end

        # Waiting for response.
        @client.get_long_running_operation_result(response, deserialize_method)
      end

      promise
    end

    #
    # Update an event subscription
    #
    # Asynchronously updates an existing event subscription.
    #
    # @param scope [String] The scope of existing event subscription. The scope can
    # be a subscription, or a resource group, or a top level resource belonging to
    # a resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription to be
    # updated
    # @param event_subscription_update_parameters
    # [EventSubscriptionUpdateParameters] Updated event subscription information
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscription] operation results.
    #
    def update(scope, event_subscription_name, event_subscription_update_parameters, custom_headers:nil)
      response = update_async(scope, event_subscription_name, event_subscription_update_parameters, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # @param scope [String] The scope of existing event subscription. The scope can
    # be a subscription, or a resource group, or a top level resource belonging to
    # a resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription to be
    # updated
    # @param event_subscription_update_parameters
    # [EventSubscriptionUpdateParameters] Updated event subscription information
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Concurrent::Promise] promise which provides async access to http
    # response.
    #
    def update_async(scope, event_subscription_name, event_subscription_update_parameters, custom_headers:nil)
      # Send request
      promise = begin_update_async(scope, event_subscription_name, event_subscription_update_parameters, custom_headers:custom_headers)

      promise = promise.then do |response|
        # Defining deserialization method.
        deserialize_method = lambda do |parsed_response|
          result_mapper = Azure::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscription.mapper()
          parsed_response = @client.deserialize(result_mapper, parsed_response)
        end

        # Waiting for response.
        @client.get_long_running_operation_result(response, deserialize_method)
      end

      promise
    end

    #
    # Get full URL of an event subscription
    #
    # Get the full endpoint URL for an event subscription
    #
    # @param scope [String] The scope of the event subscription. The scope can be a
    # subscription, or a resource group, or a top level resource belonging to a
    # resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscriptionFullUrl] operation results.
    #
    def get_full_url(scope, event_subscription_name, custom_headers:nil)
      response = get_full_url_async(scope, event_subscription_name, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get full URL of an event subscription
    #
    # Get the full endpoint URL for an event subscription
    #
    # @param scope [String] The scope of the event subscription. The scope can be a
    # subscription, or a resource group, or a top level resource belonging to a
    # resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription
    # @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_full_url_with_http_info(scope, event_subscription_name, custom_headers:nil)
      get_full_url_async(scope, event_subscription_name, custom_headers:custom_headers).value!
    end

    #
    # Get full URL of an event subscription
    #
    # Get the full endpoint URL for an event subscription
    #
    # @param scope [String] The scope of the event subscription. The scope can be a
    # subscription, or a resource group, or a top level resource belonging to a
    # resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription
    # @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_full_url_async(scope, event_subscription_name, custom_headers:nil)
      fail ArgumentError, 'scope is nil' if scope.nil?
      fail ArgumentError, 'event_subscription_name is nil' if event_subscription_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 = '{scope}/providers/Microsoft.EventGrid/eventSubscriptions/{eventSubscriptionName}/getFullUrl'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'eventSubscriptionName' => event_subscription_name},
          skip_encoding_path_params: {'scope' => scope},
          query_params: {'api-version' => @client.api_version},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionFullUrl.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

    #
    # Get an aggregated list of all global event subscriptions under an Azure
    # subscription
    #
    # List all aggregated global event subscriptions under a specific Azure
    # subscription
    #
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<EventSubscription>] operation results.
    #
    def list_global_by_subscription(filter:nil, top:nil, label:nil, custom_headers:nil)
      first_page = list_global_by_subscription_as_lazy(filter:filter, top:top, label:label, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # Get an aggregated list of all global event subscriptions under an Azure
    # subscription
    #
    # List all aggregated global event subscriptions under a specific Azure
    # subscription
    #
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_global_by_subscription_with_http_info(filter:nil, top:nil, label:nil, custom_headers:nil)
      list_global_by_subscription_async(filter:filter, top:top, label:label, custom_headers:custom_headers).value!
    end

    #
    # Get an aggregated list of all global event subscriptions under an Azure
    # subscription
    #
    # List all aggregated global event subscriptions under a specific Azure
    # subscription
    #
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_global_by_subscription_async(filter:nil, top:nil, label:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.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 = 'subscriptions/{subscriptionId}/providers/Microsoft.EventGrid/eventSubscriptions'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top,'label' => label},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all global event subscriptions for a topic type
    #
    # List all global event subscriptions under an Azure subscription for a topic
    # type.
    #
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<EventSubscription>] operation results.
    #
    def list_global_by_subscription_for_topic_type(topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      first_page = list_global_by_subscription_for_topic_type_as_lazy(topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List all global event subscriptions for a topic type
    #
    # List all global event subscriptions under an Azure subscription for a topic
    # type.
    #
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_global_by_subscription_for_topic_type_with_http_info(topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      list_global_by_subscription_for_topic_type_async(topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
    end

    #
    # List all global event subscriptions for a topic type
    #
    # List all global event subscriptions under an Azure subscription for a topic
    # type.
    #
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_global_by_subscription_for_topic_type_async(topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'topic_type_name is nil' if topic_type_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 = 'subscriptions/{subscriptionId}/providers/Microsoft.EventGrid/topicTypes/{topicTypeName}/eventSubscriptions'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'topicTypeName' => topic_type_name},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top,'label' => label},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all global event subscriptions under an Azure subscription and resource
    # group
    #
    # List all global event subscriptions under a specific Azure subscription and
    # resource group
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<EventSubscription>] operation results.
    #
    def list_global_by_resource_group(resource_group_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      first_page = list_global_by_resource_group_as_lazy(resource_group_name, filter:filter, top:top, label:label, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List all global event subscriptions under an Azure subscription and resource
    # group
    #
    # List all global event subscriptions under a specific Azure subscription and
    # resource group
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_global_by_resource_group_with_http_info(resource_group_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      list_global_by_resource_group_async(resource_group_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
    end

    #
    # List all global event subscriptions under an Azure subscription and resource
    # group
    #
    # List all global event subscriptions under a specific Azure subscription and
    # resource group
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_global_by_resource_group_async(resource_group_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_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 = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/eventSubscriptions'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top,'label' => label},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all global event subscriptions under a resource group for a topic type
    #
    # List all global event subscriptions under a resource group for a specific
    # topic type.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<EventSubscription>] operation results.
    #
    def list_global_by_resource_group_for_topic_type(resource_group_name, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      first_page = list_global_by_resource_group_for_topic_type_as_lazy(resource_group_name, topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List all global event subscriptions under a resource group for a topic type
    #
    # List all global event subscriptions under a resource group for a specific
    # topic type.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_global_by_resource_group_for_topic_type_with_http_info(resource_group_name, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      list_global_by_resource_group_for_topic_type_async(resource_group_name, topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
    end

    #
    # List all global event subscriptions under a resource group for a topic type
    #
    # List all global event subscriptions under a resource group for a specific
    # topic type.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_global_by_resource_group_for_topic_type_async(resource_group_name, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'topic_type_name is nil' if topic_type_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 = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topicTypes/{topicTypeName}/eventSubscriptions'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'topicTypeName' => topic_type_name},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top,'label' => label},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all regional event subscriptions under an Azure subscription
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription
    #
    # @param location [String] Name of the location
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<EventSubscription>] operation results.
    #
    def list_regional_by_subscription(location, filter:nil, top:nil, label:nil, custom_headers:nil)
      first_page = list_regional_by_subscription_as_lazy(location, filter:filter, top:top, label:label, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List all regional event subscriptions under an Azure subscription
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription
    #
    # @param location [String] Name of the location
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_regional_by_subscription_with_http_info(location, filter:nil, top:nil, label:nil, custom_headers:nil)
      list_regional_by_subscription_async(location, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
    end

    #
    # List all regional event subscriptions under an Azure subscription
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription
    #
    # @param location [String] Name of the location
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_regional_by_subscription_async(location, filter:nil, top:nil, label:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'location is nil' if location.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 = 'subscriptions/{subscriptionId}/providers/Microsoft.EventGrid/locations/{location}/eventSubscriptions'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'location' => location},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top,'label' => label},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param location [String] Name of the location
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<EventSubscription>] operation results.
    #
    def list_regional_by_resource_group(resource_group_name, location, filter:nil, top:nil, label:nil, custom_headers:nil)
      first_page = list_regional_by_resource_group_as_lazy(resource_group_name, location, filter:filter, top:top, label:label, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param location [String] Name of the location
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_regional_by_resource_group_with_http_info(resource_group_name, location, filter:nil, top:nil, label:nil, custom_headers:nil)
      list_regional_by_resource_group_async(resource_group_name, location, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
    end

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param location [String] Name of the location
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_regional_by_resource_group_async(resource_group_name, location, filter:nil, top:nil, label:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'location is nil' if location.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 = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/locations/{location}/eventSubscriptions'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'location' => location},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top,'label' => label},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all regional event subscriptions under an Azure subscription for a topic
    # type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and topic type.
    #
    # @param location [String] Name of the location
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<EventSubscription>] operation results.
    #
    def list_regional_by_subscription_for_topic_type(location, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      first_page = list_regional_by_subscription_for_topic_type_as_lazy(location, topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List all regional event subscriptions under an Azure subscription for a topic
    # type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and topic type.
    #
    # @param location [String] Name of the location
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_regional_by_subscription_for_topic_type_with_http_info(location, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      list_regional_by_subscription_for_topic_type_async(location, topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
    end

    #
    # List all regional event subscriptions under an Azure subscription for a topic
    # type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and topic type.
    #
    # @param location [String] Name of the location
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_regional_by_subscription_for_topic_type_async(location, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'location is nil' if location.nil?
      fail ArgumentError, 'topic_type_name is nil' if topic_type_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 = 'subscriptions/{subscriptionId}/providers/Microsoft.EventGrid/locations/{location}/topicTypes/{topicTypeName}/eventSubscriptions'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'location' => location,'topicTypeName' => topic_type_name},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top,'label' => label},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group for a topic type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group and topic type
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param location [String] Name of the location
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<EventSubscription>] operation results.
    #
    def list_regional_by_resource_group_for_topic_type(resource_group_name, location, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      first_page = list_regional_by_resource_group_for_topic_type_as_lazy(resource_group_name, location, topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group for a topic type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group and topic type
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param location [String] Name of the location
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_regional_by_resource_group_for_topic_type_with_http_info(resource_group_name, location, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      list_regional_by_resource_group_for_topic_type_async(resource_group_name, location, topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
    end

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group for a topic type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group and topic type
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param location [String] Name of the location
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_regional_by_resource_group_for_topic_type_async(resource_group_name, location, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'location is nil' if location.nil?
      fail ArgumentError, 'topic_type_name is nil' if topic_type_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 = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/locations/{location}/topicTypes/{topicTypeName}/eventSubscriptions'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'location' => location,'topicTypeName' => topic_type_name},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top,'label' => label},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all event subscriptions for a specific topic
    #
    # List all event subscriptions that have been created for a specific topic
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param provider_namespace [String] Namespace of the provider of the topic
    # @param resource_type_name [String] Name of the resource type
    # @param resource_name [String] Name of the resource
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<EventSubscription>] operation results.
    #
    def list_by_resource(resource_group_name, provider_namespace, resource_type_name, resource_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      first_page = list_by_resource_as_lazy(resource_group_name, provider_namespace, resource_type_name, resource_name, filter:filter, top:top, label:label, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List all event subscriptions for a specific topic
    #
    # List all event subscriptions that have been created for a specific topic
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param provider_namespace [String] Namespace of the provider of the topic
    # @param resource_type_name [String] Name of the resource type
    # @param resource_name [String] Name of the resource
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_by_resource_with_http_info(resource_group_name, provider_namespace, resource_type_name, resource_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      list_by_resource_async(resource_group_name, provider_namespace, resource_type_name, resource_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
    end

    #
    # List all event subscriptions for a specific topic
    #
    # List all event subscriptions that have been created for a specific topic
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param provider_namespace [String] Namespace of the provider of the topic
    # @param resource_type_name [String] Name of the resource type
    # @param resource_name [String] Name of the resource
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_by_resource_async(resource_group_name, provider_namespace, resource_type_name, resource_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'provider_namespace is nil' if provider_namespace.nil?
      fail ArgumentError, 'resource_type_name is nil' if resource_type_name.nil?
      fail ArgumentError, 'resource_name is nil' if resource_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 = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerNamespace}/{resourceTypeName}/{resourceName}/providers/Microsoft.EventGrid/eventSubscriptions'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'providerNamespace' => provider_namespace,'resourceTypeName' => resource_type_name,'resourceName' => resource_name},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top,'label' => label},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all event subscriptions for a specific domain topic
    #
    # List all event subscriptions that have been created for a specific domain
    # topic
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the top level domain
    # @param topic_name [String] Name of the domain topic
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [Array<EventSubscription>] operation results.
    #
    def list_by_domain_topic(resource_group_name, domain_name, topic_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      first_page = list_by_domain_topic_as_lazy(resource_group_name, domain_name, topic_name, filter:filter, top:top, label:label, custom_headers:custom_headers)
      first_page.get_all_items
    end

    #
    # List all event subscriptions for a specific domain topic
    #
    # List all event subscriptions that have been created for a specific domain
    # topic
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the top level domain
    # @param topic_name [String] Name of the domain topic
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_by_domain_topic_with_http_info(resource_group_name, domain_name, topic_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      list_by_domain_topic_async(resource_group_name, domain_name, topic_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
    end

    #
    # List all event subscriptions for a specific domain topic
    #
    # List all event subscriptions that have been created for a specific domain
    # topic
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the top level domain
    # @param topic_name [String] Name of the domain topic
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @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_by_domain_topic_async(resource_group_name, domain_name, topic_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      fail ArgumentError, '@client.subscription_id is nil' if @client.subscription_id.nil?
      fail ArgumentError, 'resource_group_name is nil' if resource_group_name.nil?
      fail ArgumentError, 'domain_name is nil' if domain_name.nil?
      fail ArgumentError, 'topic_name is nil' if topic_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 = 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}/topics/{topicName}/providers/Microsoft.EventGrid/eventSubscriptions'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'subscriptionId' => @client.subscription_id,'resourceGroupName' => resource_group_name,'domainName' => domain_name,'topicName' => topic_name},
          query_params: {'api-version' => @client.api_version,'$filter' => filter,'$top' => top,'label' => label},
          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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # Create or update an event subscription
    #
    # Asynchronously creates a new event subscription or updates an existing event
    # subscription based on the specified scope.
    #
    # @param scope [String] The identifier of the resource to which the event
    # subscription needs to be created or updated. The scope can be a subscription,
    # or a resource group, or a top level resource belonging to a resource provider
    # namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription. Event
    # subscription names must be between 3 and 64 characters in length and should
    # use alphanumeric letters only.
    # @param event_subscription_info [EventSubscription] Event subscription
    # properties containing the destination and filter information
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscription] operation results.
    #
    def begin_create_or_update(scope, event_subscription_name, event_subscription_info, custom_headers:nil)
      response = begin_create_or_update_async(scope, event_subscription_name, event_subscription_info, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Create or update an event subscription
    #
    # Asynchronously creates a new event subscription or updates an existing event
    # subscription based on the specified scope.
    #
    # @param scope [String] The identifier of the resource to which the event
    # subscription needs to be created or updated. The scope can be a subscription,
    # or a resource group, or a top level resource belonging to a resource provider
    # namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription. Event
    # subscription names must be between 3 and 64 characters in length and should
    # use alphanumeric letters only.
    # @param event_subscription_info [EventSubscription] Event subscription
    # properties containing the destination and filter information
    # @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 begin_create_or_update_with_http_info(scope, event_subscription_name, event_subscription_info, custom_headers:nil)
      begin_create_or_update_async(scope, event_subscription_name, event_subscription_info, custom_headers:custom_headers).value!
    end

    #
    # Create or update an event subscription
    #
    # Asynchronously creates a new event subscription or updates an existing event
    # subscription based on the specified scope.
    #
    # @param scope [String] The identifier of the resource to which the event
    # subscription needs to be created or updated. The scope can be a subscription,
    # or a resource group, or a top level resource belonging to a resource provider
    # namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription. Event
    # subscription names must be between 3 and 64 characters in length and should
    # use alphanumeric letters only.
    # @param event_subscription_info [EventSubscription] Event subscription
    # properties containing the destination and filter information
    # @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 begin_create_or_update_async(scope, event_subscription_name, event_subscription_info, custom_headers:nil)
      fail ArgumentError, 'scope is nil' if scope.nil?
      fail ArgumentError, 'event_subscription_name is nil' if event_subscription_name.nil?
      fail ArgumentError, 'event_subscription_info is nil' if event_subscription_info.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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscription.mapper()
      request_content = @client.serialize(request_mapper,  event_subscription_info)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = '{scope}/providers/Microsoft.EventGrid/eventSubscriptions/{eventSubscriptionName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'eventSubscriptionName' => event_subscription_name},
          skip_encoding_path_params: {'scope' => scope},
          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(:put, 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 == 201
          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 == 201
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscription.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

    #
    # Delete an event subscription
    #
    # Delete an existing event subscription
    #
    # @param scope [String] The scope of the event subscription. The scope can be a
    # subscription, or a resource group, or a top level resource belonging to a
    # resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    #
    def begin_delete(scope, event_subscription_name, custom_headers:nil)
      response = begin_delete_async(scope, event_subscription_name, custom_headers:custom_headers).value!
      nil
    end

    #
    # Delete an event subscription
    #
    # Delete an existing event subscription
    #
    # @param scope [String] The scope of the event subscription. The scope can be a
    # subscription, or a resource group, or a top level resource belonging to a
    # resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription
    # @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 begin_delete_with_http_info(scope, event_subscription_name, custom_headers:nil)
      begin_delete_async(scope, event_subscription_name, custom_headers:custom_headers).value!
    end

    #
    # Delete an event subscription
    #
    # Delete an existing event subscription
    #
    # @param scope [String] The scope of the event subscription. The scope can be a
    # subscription, or a resource group, or a top level resource belonging to a
    # resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription
    # @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 begin_delete_async(scope, event_subscription_name, custom_headers:nil)
      fail ArgumentError, 'scope is nil' if scope.nil?
      fail ArgumentError, 'event_subscription_name is nil' if event_subscription_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 = '{scope}/providers/Microsoft.EventGrid/eventSubscriptions/{eventSubscriptionName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'eventSubscriptionName' => event_subscription_name},
          skip_encoding_path_params: {'scope' => scope},
          query_params: {'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 == 200 || status_code == 202 || 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

    #
    # Update an event subscription
    #
    # Asynchronously updates an existing event subscription.
    #
    # @param scope [String] The scope of existing event subscription. The scope can
    # be a subscription, or a resource group, or a top level resource belonging to
    # a resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription to be
    # updated
    # @param event_subscription_update_parameters
    # [EventSubscriptionUpdateParameters] Updated event subscription information
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscription] operation results.
    #
    def begin_update(scope, event_subscription_name, event_subscription_update_parameters, custom_headers:nil)
      response = begin_update_async(scope, event_subscription_name, event_subscription_update_parameters, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Update an event subscription
    #
    # Asynchronously updates an existing event subscription.
    #
    # @param scope [String] The scope of existing event subscription. The scope can
    # be a subscription, or a resource group, or a top level resource belonging to
    # a resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription to be
    # updated
    # @param event_subscription_update_parameters
    # [EventSubscriptionUpdateParameters] Updated event subscription information
    # @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 begin_update_with_http_info(scope, event_subscription_name, event_subscription_update_parameters, custom_headers:nil)
      begin_update_async(scope, event_subscription_name, event_subscription_update_parameters, custom_headers:custom_headers).value!
    end

    #
    # Update an event subscription
    #
    # Asynchronously updates an existing event subscription.
    #
    # @param scope [String] The scope of existing event subscription. The scope can
    # be a subscription, or a resource group, or a top level resource belonging to
    # a resource provider namespace, or an EventGrid topic. For example, use
    # '/subscriptions/{subscriptionId}/' for a subscription,
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for a
    # resource group, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{resourceType}/{resourceName}'
    # for a resource, and
    # '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topics/{topicName}'
    # for an EventGrid topic.
    # @param event_subscription_name [String] Name of the event subscription to be
    # updated
    # @param event_subscription_update_parameters
    # [EventSubscriptionUpdateParameters] Updated event subscription information
    # @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 begin_update_async(scope, event_subscription_name, event_subscription_update_parameters, custom_headers:nil)
      fail ArgumentError, 'scope is nil' if scope.nil?
      fail ArgumentError, 'event_subscription_name is nil' if event_subscription_name.nil?
      fail ArgumentError, 'event_subscription_update_parameters is nil' if event_subscription_update_parameters.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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionUpdateParameters.mapper()
      request_content = @client.serialize(request_mapper,  event_subscription_update_parameters)
      request_content = request_content != nil ? JSON.generate(request_content, quirks_mode: true) : nil

      path_template = '{scope}/providers/Microsoft.EventGrid/eventSubscriptions/{eventSubscriptionName}'

      request_url = @base_url || @client.base_url

      options = {
          middlewares: [[MsRest::RetryPolicyMiddleware, times: 3, retry: 0.02], [:cookie_jar]],
          path_params: {'eventSubscriptionName' => event_subscription_name},
          skip_encoding_path_params: {'scope' => scope},
          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 == 201
          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 == 201
          begin
            parsed_response = response_content.to_s.empty? ? nil : JSON.load(response_content)
            result_mapper = Azure::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscription.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

    #
    # Get an aggregated list of all global event subscriptions under an Azure
    # subscription
    #
    # List all aggregated global event subscriptions under a specific Azure
    # subscription
    #
    # @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 [EventSubscriptionsListResult] operation results.
    #
    def list_global_by_subscription_next(next_page_link, custom_headers:nil)
      response = list_global_by_subscription_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # Get an aggregated list of all global event subscriptions under an Azure
    # subscription
    #
    # List all aggregated global event subscriptions under a specific Azure
    # subscription
    #
    # @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_global_by_subscription_next_with_http_info(next_page_link, custom_headers:nil)
      list_global_by_subscription_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # Get an aggregated list of all global event subscriptions under an Azure
    # subscription
    #
    # List all aggregated global event subscriptions under a specific Azure
    # subscription
    #
    # @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_global_by_subscription_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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all global event subscriptions for a topic type
    #
    # List all global event subscriptions under an Azure subscription for a topic
    # type.
    #
    # @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 [EventSubscriptionsListResult] operation results.
    #
    def list_global_by_subscription_for_topic_type_next(next_page_link, custom_headers:nil)
      response = list_global_by_subscription_for_topic_type_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List all global event subscriptions for a topic type
    #
    # List all global event subscriptions under an Azure subscription for a topic
    # type.
    #
    # @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_global_by_subscription_for_topic_type_next_with_http_info(next_page_link, custom_headers:nil)
      list_global_by_subscription_for_topic_type_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List all global event subscriptions for a topic type
    #
    # List all global event subscriptions under an Azure subscription for a topic
    # type.
    #
    # @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_global_by_subscription_for_topic_type_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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all global event subscriptions under an Azure subscription and resource
    # group
    #
    # List all global event subscriptions under a specific Azure subscription and
    # resource group
    #
    # @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 [EventSubscriptionsListResult] operation results.
    #
    def list_global_by_resource_group_next(next_page_link, custom_headers:nil)
      response = list_global_by_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List all global event subscriptions under an Azure subscription and resource
    # group
    #
    # List all global event subscriptions under a specific Azure subscription and
    # resource group
    #
    # @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_global_by_resource_group_next_with_http_info(next_page_link, custom_headers:nil)
      list_global_by_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List all global event subscriptions under an Azure subscription and resource
    # group
    #
    # List all global event subscriptions under a specific Azure subscription and
    # resource group
    #
    # @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_global_by_resource_group_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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all global event subscriptions under a resource group for a topic type
    #
    # List all global event subscriptions under a resource group for a specific
    # topic type.
    #
    # @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 [EventSubscriptionsListResult] operation results.
    #
    def list_global_by_resource_group_for_topic_type_next(next_page_link, custom_headers:nil)
      response = list_global_by_resource_group_for_topic_type_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List all global event subscriptions under a resource group for a topic type
    #
    # List all global event subscriptions under a resource group for a specific
    # topic type.
    #
    # @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_global_by_resource_group_for_topic_type_next_with_http_info(next_page_link, custom_headers:nil)
      list_global_by_resource_group_for_topic_type_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List all global event subscriptions under a resource group for a topic type
    #
    # List all global event subscriptions under a resource group for a specific
    # topic type.
    #
    # @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_global_by_resource_group_for_topic_type_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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all regional event subscriptions under an Azure subscription
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription
    #
    # @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 [EventSubscriptionsListResult] operation results.
    #
    def list_regional_by_subscription_next(next_page_link, custom_headers:nil)
      response = list_regional_by_subscription_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List all regional event subscriptions under an Azure subscription
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription
    #
    # @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_regional_by_subscription_next_with_http_info(next_page_link, custom_headers:nil)
      list_regional_by_subscription_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List all regional event subscriptions under an Azure subscription
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription
    #
    # @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_regional_by_subscription_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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group
    #
    # @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 [EventSubscriptionsListResult] operation results.
    #
    def list_regional_by_resource_group_next(next_page_link, custom_headers:nil)
      response = list_regional_by_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group
    #
    # @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_regional_by_resource_group_next_with_http_info(next_page_link, custom_headers:nil)
      list_regional_by_resource_group_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group
    #
    # @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_regional_by_resource_group_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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all regional event subscriptions under an Azure subscription for a topic
    # type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and topic type.
    #
    # @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 [EventSubscriptionsListResult] operation results.
    #
    def list_regional_by_subscription_for_topic_type_next(next_page_link, custom_headers:nil)
      response = list_regional_by_subscription_for_topic_type_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List all regional event subscriptions under an Azure subscription for a topic
    # type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and topic type.
    #
    # @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_regional_by_subscription_for_topic_type_next_with_http_info(next_page_link, custom_headers:nil)
      list_regional_by_subscription_for_topic_type_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List all regional event subscriptions under an Azure subscription for a topic
    # type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and topic type.
    #
    # @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_regional_by_subscription_for_topic_type_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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group for a topic type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group and topic type
    #
    # @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 [EventSubscriptionsListResult] operation results.
    #
    def list_regional_by_resource_group_for_topic_type_next(next_page_link, custom_headers:nil)
      response = list_regional_by_resource_group_for_topic_type_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group for a topic type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group and topic type
    #
    # @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_regional_by_resource_group_for_topic_type_next_with_http_info(next_page_link, custom_headers:nil)
      list_regional_by_resource_group_for_topic_type_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group for a topic type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group and topic type
    #
    # @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_regional_by_resource_group_for_topic_type_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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all event subscriptions for a specific topic
    #
    # List all event subscriptions that have been created for a specific topic
    #
    # @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 [EventSubscriptionsListResult] operation results.
    #
    def list_by_resource_next(next_page_link, custom_headers:nil)
      response = list_by_resource_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List all event subscriptions for a specific topic
    #
    # List all event subscriptions that have been created for a specific topic
    #
    # @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_by_resource_next_with_http_info(next_page_link, custom_headers:nil)
      list_by_resource_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List all event subscriptions for a specific topic
    #
    # List all event subscriptions that have been created for a specific topic
    #
    # @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_by_resource_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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # List all event subscriptions for a specific domain topic
    #
    # List all event subscriptions that have been created for a specific domain
    # topic
    #
    # @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 [EventSubscriptionsListResult] operation results.
    #
    def list_by_domain_topic_next(next_page_link, custom_headers:nil)
      response = list_by_domain_topic_next_async(next_page_link, custom_headers:custom_headers).value!
      response.body unless response.nil?
    end

    #
    # List all event subscriptions for a specific domain topic
    #
    # List all event subscriptions that have been created for a specific domain
    # topic
    #
    # @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_by_domain_topic_next_with_http_info(next_page_link, custom_headers:nil)
      list_by_domain_topic_next_async(next_page_link, custom_headers:custom_headers).value!
    end

    #
    # List all event subscriptions for a specific domain topic
    #
    # List all event subscriptions that have been created for a specific domain
    # topic
    #
    # @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_by_domain_topic_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::EventGrid::Mgmt::V2019_02_01_preview::Models::EventSubscriptionsListResult.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

    #
    # Get an aggregated list of all global event subscriptions under an Azure
    # subscription
    #
    # List all aggregated global event subscriptions under a specific Azure
    # subscription
    #
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscriptionsListResult] which provide lazy access to pages of
    # the response.
    #
    def list_global_by_subscription_as_lazy(filter:nil, top:nil, label:nil, custom_headers:nil)
      response = list_global_by_subscription_async(filter:filter, top:top, label:label, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_global_by_subscription_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # List all global event subscriptions for a topic type
    #
    # List all global event subscriptions under an Azure subscription for a topic
    # type.
    #
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscriptionsListResult] which provide lazy access to pages of
    # the response.
    #
    def list_global_by_subscription_for_topic_type_as_lazy(topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      response = list_global_by_subscription_for_topic_type_async(topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_global_by_subscription_for_topic_type_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # List all global event subscriptions under an Azure subscription and resource
    # group
    #
    # List all global event subscriptions under a specific Azure subscription and
    # resource group
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscriptionsListResult] which provide lazy access to pages of
    # the response.
    #
    def list_global_by_resource_group_as_lazy(resource_group_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      response = list_global_by_resource_group_async(resource_group_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_global_by_resource_group_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # List all global event subscriptions under a resource group for a topic type
    #
    # List all global event subscriptions under a resource group for a specific
    # topic type.
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscriptionsListResult] which provide lazy access to pages of
    # the response.
    #
    def list_global_by_resource_group_for_topic_type_as_lazy(resource_group_name, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      response = list_global_by_resource_group_for_topic_type_async(resource_group_name, topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_global_by_resource_group_for_topic_type_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # List all regional event subscriptions under an Azure subscription
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription
    #
    # @param location [String] Name of the location
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscriptionsListResult] which provide lazy access to pages of
    # the response.
    #
    def list_regional_by_subscription_as_lazy(location, filter:nil, top:nil, label:nil, custom_headers:nil)
      response = list_regional_by_subscription_async(location, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_regional_by_subscription_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param location [String] Name of the location
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscriptionsListResult] which provide lazy access to pages of
    # the response.
    #
    def list_regional_by_resource_group_as_lazy(resource_group_name, location, filter:nil, top:nil, label:nil, custom_headers:nil)
      response = list_regional_by_resource_group_async(resource_group_name, location, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_regional_by_resource_group_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # List all regional event subscriptions under an Azure subscription for a topic
    # type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and topic type.
    #
    # @param location [String] Name of the location
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscriptionsListResult] which provide lazy access to pages of
    # the response.
    #
    def list_regional_by_subscription_for_topic_type_as_lazy(location, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      response = list_regional_by_subscription_for_topic_type_async(location, topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_regional_by_subscription_for_topic_type_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # List all regional event subscriptions under an Azure subscription and
    # resource group for a topic type
    #
    # List all event subscriptions from the given location under a specific Azure
    # subscription and resource group and topic type
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param location [String] Name of the location
    # @param topic_type_name [String] Name of the topic type
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscriptionsListResult] which provide lazy access to pages of
    # the response.
    #
    def list_regional_by_resource_group_for_topic_type_as_lazy(resource_group_name, location, topic_type_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      response = list_regional_by_resource_group_for_topic_type_async(resource_group_name, location, topic_type_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_regional_by_resource_group_for_topic_type_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # List all event subscriptions for a specific topic
    #
    # List all event subscriptions that have been created for a specific topic
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param provider_namespace [String] Namespace of the provider of the topic
    # @param resource_type_name [String] Name of the resource type
    # @param resource_name [String] Name of the resource
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscriptionsListResult] which provide lazy access to pages of
    # the response.
    #
    def list_by_resource_as_lazy(resource_group_name, provider_namespace, resource_type_name, resource_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      response = list_by_resource_async(resource_group_name, provider_namespace, resource_type_name, resource_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_by_resource_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

    #
    # List all event subscriptions for a specific domain topic
    #
    # List all event subscriptions that have been created for a specific domain
    # topic
    #
    # @param resource_group_name [String] The name of the resource group within the
    # user's subscription.
    # @param domain_name [String] Name of the top level domain
    # @param topic_name [String] Name of the domain topic
    # @param filter [String] Filter the results using OData syntax.
    # @param top [Integer] The number of results to return.
    # @param label [String] The label used to filter the results for event
    # subscriptions list.
    # @param custom_headers [Hash{String => String}] A hash of custom headers that
    # will be added to the HTTP request.
    #
    # @return [EventSubscriptionsListResult] which provide lazy access to pages of
    # the response.
    #
    def list_by_domain_topic_as_lazy(resource_group_name, domain_name, topic_name, filter:nil, top:nil, label:nil, custom_headers:nil)
      response = list_by_domain_topic_async(resource_group_name, domain_name, topic_name, filter:filter, top:top, label:label, custom_headers:custom_headers).value!
      unless response.nil?
        page = response.body
        page.next_method = Proc.new do |next_page_link|
          list_by_domain_topic_next_async(next_page_link, custom_headers:custom_headers)
        end
        page
      end
    end

  end
end
