/*
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 *
 * Code generated by Microsoft (R) AutoRest Code Generator.
 * Changes may cause incorrect behavior and will be lost if the code is
 * regenerated.
 */

'use strict';

const msRest = require('ms-rest');
const msRestAzure = require('ms-rest-azure');
const WebResource = msRest.WebResource;

/**
 * @summary Get an event subscription
 *
 * Get properties of an event subscription
 *
 * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscription} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _get(scope, eventSubscriptionName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (scope === null || scope === undefined || typeof scope.valueOf() !== 'string') {
      throw new Error('scope cannot be null or undefined and it must be of type string.');
    }
    if (eventSubscriptionName === null || eventSubscriptionName === undefined || typeof eventSubscriptionName.valueOf() !== 'string') {
      throw new Error('eventSubscriptionName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{scope}/providers/Microsoft.EventGrid/eventSubscriptions/{eventSubscriptionName}';
  requestUrl = requestUrl.replace('{scope}', scope);
  requestUrl = requestUrl.replace('{eventSubscriptionName}', encodeURIComponent(eventSubscriptionName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscription']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}


/**
 * @summary Create or update an event subscription
 *
 * Asynchronously creates a new event subscription or updates an existing event
 * subscription based on the specified scope.
 *
 * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription. Event
 * subscription names must be between 3 and 64 characters in length and should
 * use alphanumeric letters only.
 *
 * @param {object} eventSubscriptionInfo Event subscription properties
 * containing the destination and filter information
 *
 * @param {object} [eventSubscriptionInfo.destination] Information about the
 * destination where events have to be delivered for the event subscription.
 *
 * @param {string} eventSubscriptionInfo.destination.endpointType Polymorphic
 * Discriminator
 *
 * @param {object} [eventSubscriptionInfo.filter] Information about the filter
 * for the event subscription.
 *
 * @param {string} [eventSubscriptionInfo.filter.subjectBeginsWith] An optional
 * string to filter events for an event subscription based on a resource path
 * prefix.
 * The format of this depends on the publisher of the events.
 * Wildcard characters are not supported in this path.
 *
 * @param {string} [eventSubscriptionInfo.filter.subjectEndsWith] An optional
 * string to filter events for an event subscription based on a resource path
 * suffix.
 * Wildcard characters are not supported in this path.
 *
 * @param {array} [eventSubscriptionInfo.filter.includedEventTypes] A list of
 * applicable event types that need to be part of the event subscription. If it
 * is desired to subscribe to all default event types, set the
 * IncludedEventTypes to null.
 *
 * @param {boolean} [eventSubscriptionInfo.filter.isSubjectCaseSensitive]
 * Specifies if the SubjectBeginsWith and SubjectEndsWith properties of the
 * filter
 * should be compared in a case sensitive manner.
 *
 * @param {array} [eventSubscriptionInfo.filter.advancedFilters] An array of
 * advanced filters that are used for filtering event subscriptions.
 *
 * @param {array} [eventSubscriptionInfo.labels] List of user defined labels.
 *
 * @param {date} [eventSubscriptionInfo.expirationTimeUtc] Expiration time of
 * the event subscription.
 *
 * @param {string} [eventSubscriptionInfo.eventDeliverySchema] The event
 * delivery schema for the event subscription. Possible values include:
 * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
 *
 * @param {object} [eventSubscriptionInfo.retryPolicy] The retry policy for
 * events. This can be used to configure maximum number of delivery attempts
 * and time to live for events.
 *
 * @param {number} [eventSubscriptionInfo.retryPolicy.maxDeliveryAttempts]
 * Maximum number of delivery retry attempts for events.
 *
 * @param {number} [eventSubscriptionInfo.retryPolicy.eventTimeToLiveInMinutes]
 * Time To Live (in minutes) for events.
 *
 * @param {object} [eventSubscriptionInfo.deadLetterDestination] The DeadLetter
 * destination of the event subscription.
 *
 * @param {string} eventSubscriptionInfo.deadLetterDestination.endpointType
 * Polymorphic Discriminator
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscription} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _createOrUpdate(scope, eventSubscriptionName, eventSubscriptionInfo, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }

  if (!callback) {
    throw new Error('callback cannot be null.');
  }

  // Send request
  this.beginCreateOrUpdate(scope, eventSubscriptionName, eventSubscriptionInfo, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscription']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }

      return callback(null, result, httpRequest, response);
    });
  });
}


/**
 * @summary Delete an event subscription
 *
 * Delete an existing event subscription
 *
 * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _deleteMethod(scope, eventSubscriptionName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }

  if (!callback) {
    throw new Error('callback cannot be null.');
  }

  // Send request
  this.beginDeleteMethod(scope, eventSubscriptionName, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response

      return callback(null, result, httpRequest, response);
    });
  });
}


/**
 * @summary Update an event subscription
 *
 * Asynchronously updates an existing event subscription.
 *
 * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription to be
 * updated
 *
 * @param {object} eventSubscriptionUpdateParameters Updated event subscription
 * information
 *
 * @param {object} [eventSubscriptionUpdateParameters.destination] Information
 * about the destination where events have to be delivered for the event
 * subscription.
 *
 * @param {string} eventSubscriptionUpdateParameters.destination.endpointType
 * Polymorphic Discriminator
 *
 * @param {object} [eventSubscriptionUpdateParameters.filter] Information about
 * the filter for the event subscription.
 *
 * @param {string} [eventSubscriptionUpdateParameters.filter.subjectBeginsWith]
 * An optional string to filter events for an event subscription based on a
 * resource path prefix.
 * The format of this depends on the publisher of the events.
 * Wildcard characters are not supported in this path.
 *
 * @param {string} [eventSubscriptionUpdateParameters.filter.subjectEndsWith]
 * An optional string to filter events for an event subscription based on a
 * resource path suffix.
 * Wildcard characters are not supported in this path.
 *
 * @param {array} [eventSubscriptionUpdateParameters.filter.includedEventTypes]
 * A list of applicable event types that need to be part of the event
 * subscription. If it is desired to subscribe to all default event types, set
 * the IncludedEventTypes to null.
 *
 * @param {boolean}
 * [eventSubscriptionUpdateParameters.filter.isSubjectCaseSensitive] Specifies
 * if the SubjectBeginsWith and SubjectEndsWith properties of the filter
 * should be compared in a case sensitive manner.
 *
 * @param {array} [eventSubscriptionUpdateParameters.filter.advancedFilters] An
 * array of advanced filters that are used for filtering event subscriptions.
 *
 * @param {array} [eventSubscriptionUpdateParameters.labels] List of user
 * defined labels.
 *
 * @param {date} [eventSubscriptionUpdateParameters.expirationTimeUtc]
 * Information about the expiration time for the event subscription.
 *
 * @param {string} [eventSubscriptionUpdateParameters.eventDeliverySchema] The
 * event delivery schema for the event subscription. Possible values include:
 * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
 *
 * @param {object} [eventSubscriptionUpdateParameters.retryPolicy] The retry
 * policy for events. This can be used to configure maximum number of delivery
 * attempts and time to live for events.
 *
 * @param {number}
 * [eventSubscriptionUpdateParameters.retryPolicy.maxDeliveryAttempts] Maximum
 * number of delivery retry attempts for events.
 *
 * @param {number}
 * [eventSubscriptionUpdateParameters.retryPolicy.eventTimeToLiveInMinutes]
 * Time To Live (in minutes) for events.
 *
 * @param {object} [eventSubscriptionUpdateParameters.deadLetterDestination]
 * The DeadLetter destination of the event subscription.
 *
 * @param {string}
 * eventSubscriptionUpdateParameters.deadLetterDestination.endpointType
 * Polymorphic Discriminator
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscription} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _update(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }

  if (!callback) {
    throw new Error('callback cannot be null.');
  }

  // Send request
  this.beginUpdate(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscription']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }

      return callback(null, result, httpRequest, response);
    });
  });
}

/**
 * @summary Get full URL of an event subscription
 *
 * Get the full endpoint URL for an event subscription
 *
 * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionFullUrl} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _getFullUrl(scope, eventSubscriptionName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (scope === null || scope === undefined || typeof scope.valueOf() !== 'string') {
      throw new Error('scope cannot be null or undefined and it must be of type string.');
    }
    if (eventSubscriptionName === null || eventSubscriptionName === undefined || typeof eventSubscriptionName.valueOf() !== 'string') {
      throw new Error('eventSubscriptionName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{scope}/providers/Microsoft.EventGrid/eventSubscriptions/{eventSubscriptionName}/getFullUrl';
  requestUrl = requestUrl.replace('{scope}', scope);
  requestUrl = requestUrl.replace('{eventSubscriptionName}', encodeURIComponent(eventSubscriptionName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'POST';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionFullUrl']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] Filter the results using OData syntax.
 *
 * @param {number} [options.top] The number of results to return.
 *
 * @param {string} [options.label] The label used to filter the results for
 * event subscriptions list.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listGlobalBySubscription(options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  let label = (options && options.label !== undefined) ? options.label : undefined;
  // Validate
  try {
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') {
      throw new Error('label must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.EventGrid/eventSubscriptions';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (label !== null && label !== undefined) {
    queryParameters.push('label=' + encodeURIComponent(label));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary List all global event subscriptions for a topic type
 *
 * List all global event subscriptions under an Azure subscription for a topic
 * type.
 *
 * @param {string} topicTypeName Name of the topic type
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] Filter the results using OData syntax.
 *
 * @param {number} [options.top] The number of results to return.
 *
 * @param {string} [options.label] The label used to filter the results for
 * event subscriptions list.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listGlobalBySubscriptionForTopicType(topicTypeName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  let label = (options && options.label !== undefined) ? options.label : undefined;
  // Validate
  try {
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (topicTypeName === null || topicTypeName === undefined || typeof topicTypeName.valueOf() !== 'string') {
      throw new Error('topicTypeName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') {
      throw new Error('label must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.EventGrid/topicTypes/{topicTypeName}/eventSubscriptions';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{topicTypeName}', encodeURIComponent(topicTypeName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (label !== null && label !== undefined) {
    queryParameters.push('label=' + encodeURIComponent(label));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {string} resourceGroupName The name of the resource group within the
 * user's subscription.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] Filter the results using OData syntax.
 *
 * @param {number} [options.top] The number of results to return.
 *
 * @param {string} [options.label] The label used to filter the results for
 * event subscriptions list.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listGlobalByResourceGroup(resourceGroupName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  let label = (options && options.label !== undefined) ? options.label : undefined;
  // Validate
  try {
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') {
      throw new Error('label must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/eventSubscriptions';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (label !== null && label !== undefined) {
    queryParameters.push('label=' + encodeURIComponent(label));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {string} resourceGroupName The name of the resource group within the
 * user's subscription.
 *
 * @param {string} topicTypeName Name of the topic type
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] Filter the results using OData syntax.
 *
 * @param {number} [options.top] The number of results to return.
 *
 * @param {string} [options.label] The label used to filter the results for
 * event subscriptions list.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listGlobalByResourceGroupForTopicType(resourceGroupName, topicTypeName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  let label = (options && options.label !== undefined) ? options.label : undefined;
  // Validate
  try {
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (topicTypeName === null || topicTypeName === undefined || typeof topicTypeName.valueOf() !== 'string') {
      throw new Error('topicTypeName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') {
      throw new Error('label must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/topicTypes/{topicTypeName}/eventSubscriptions';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{topicTypeName}', encodeURIComponent(topicTypeName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (label !== null && label !== undefined) {
    queryParameters.push('label=' + encodeURIComponent(label));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary List all regional event subscriptions under an Azure subscription
 *
 * List all event subscriptions from the given location under a specific Azure
 * subscription
 *
 * @param {string} location Name of the location
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] Filter the results using OData syntax.
 *
 * @param {number} [options.top] The number of results to return.
 *
 * @param {string} [options.label] The label used to filter the results for
 * event subscriptions list.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listRegionalBySubscription(location, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  let label = (options && options.label !== undefined) ? options.label : undefined;
  // Validate
  try {
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (location === null || location === undefined || typeof location.valueOf() !== 'string') {
      throw new Error('location cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') {
      throw new Error('label must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.EventGrid/locations/{location}/eventSubscriptions';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{location}', encodeURIComponent(location));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (label !== null && label !== undefined) {
    queryParameters.push('label=' + encodeURIComponent(label));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {string} resourceGroupName The name of the resource group within the
 * user's subscription.
 *
 * @param {string} location Name of the location
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] Filter the results using OData syntax.
 *
 * @param {number} [options.top] The number of results to return.
 *
 * @param {string} [options.label] The label used to filter the results for
 * event subscriptions list.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listRegionalByResourceGroup(resourceGroupName, location, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  let label = (options && options.label !== undefined) ? options.label : undefined;
  // Validate
  try {
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (location === null || location === undefined || typeof location.valueOf() !== 'string') {
      throw new Error('location cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') {
      throw new Error('label must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/locations/{location}/eventSubscriptions';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{location}', encodeURIComponent(location));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (label !== null && label !== undefined) {
    queryParameters.push('label=' + encodeURIComponent(label));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {string} location Name of the location
 *
 * @param {string} topicTypeName Name of the topic type
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] Filter the results using OData syntax.
 *
 * @param {number} [options.top] The number of results to return.
 *
 * @param {string} [options.label] The label used to filter the results for
 * event subscriptions list.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listRegionalBySubscriptionForTopicType(location, topicTypeName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  let label = (options && options.label !== undefined) ? options.label : undefined;
  // Validate
  try {
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (location === null || location === undefined || typeof location.valueOf() !== 'string') {
      throw new Error('location cannot be null or undefined and it must be of type string.');
    }
    if (topicTypeName === null || topicTypeName === undefined || typeof topicTypeName.valueOf() !== 'string') {
      throw new Error('topicTypeName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') {
      throw new Error('label must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.EventGrid/locations/{location}/topicTypes/{topicTypeName}/eventSubscriptions';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{location}', encodeURIComponent(location));
  requestUrl = requestUrl.replace('{topicTypeName}', encodeURIComponent(topicTypeName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (label !== null && label !== undefined) {
    queryParameters.push('label=' + encodeURIComponent(label));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {string} resourceGroupName The name of the resource group within the
 * user's subscription.
 *
 * @param {string} location Name of the location
 *
 * @param {string} topicTypeName Name of the topic type
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] Filter the results using OData syntax.
 *
 * @param {number} [options.top] The number of results to return.
 *
 * @param {string} [options.label] The label used to filter the results for
 * event subscriptions list.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listRegionalByResourceGroupForTopicType(resourceGroupName, location, topicTypeName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  let label = (options && options.label !== undefined) ? options.label : undefined;
  // Validate
  try {
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (location === null || location === undefined || typeof location.valueOf() !== 'string') {
      throw new Error('location cannot be null or undefined and it must be of type string.');
    }
    if (topicTypeName === null || topicTypeName === undefined || typeof topicTypeName.valueOf() !== 'string') {
      throw new Error('topicTypeName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') {
      throw new Error('label must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/locations/{location}/topicTypes/{topicTypeName}/eventSubscriptions';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{location}', encodeURIComponent(location));
  requestUrl = requestUrl.replace('{topicTypeName}', encodeURIComponent(topicTypeName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (label !== null && label !== undefined) {
    queryParameters.push('label=' + encodeURIComponent(label));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary List all event subscriptions for a specific topic
 *
 * List all event subscriptions that have been created for a specific topic
 *
 * @param {string} resourceGroupName The name of the resource group within the
 * user's subscription.
 *
 * @param {string} providerNamespace Namespace of the provider of the topic
 *
 * @param {string} resourceTypeName Name of the resource type
 *
 * @param {string} resourceName Name of the resource
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] Filter the results using OData syntax.
 *
 * @param {number} [options.top] The number of results to return.
 *
 * @param {string} [options.label] The label used to filter the results for
 * event subscriptions list.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listByResource(resourceGroupName, providerNamespace, resourceTypeName, resourceName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  let label = (options && options.label !== undefined) ? options.label : undefined;
  // Validate
  try {
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (providerNamespace === null || providerNamespace === undefined || typeof providerNamespace.valueOf() !== 'string') {
      throw new Error('providerNamespace cannot be null or undefined and it must be of type string.');
    }
    if (resourceTypeName === null || resourceTypeName === undefined || typeof resourceTypeName.valueOf() !== 'string') {
      throw new Error('resourceTypeName cannot be null or undefined and it must be of type string.');
    }
    if (resourceName === null || resourceName === undefined || typeof resourceName.valueOf() !== 'string') {
      throw new Error('resourceName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') {
      throw new Error('label must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{providerNamespace}/{resourceTypeName}/{resourceName}/providers/Microsoft.EventGrid/eventSubscriptions';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{providerNamespace}', encodeURIComponent(providerNamespace));
  requestUrl = requestUrl.replace('{resourceTypeName}', encodeURIComponent(resourceTypeName));
  requestUrl = requestUrl.replace('{resourceName}', encodeURIComponent(resourceName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (label !== null && label !== undefined) {
    queryParameters.push('label=' + encodeURIComponent(label));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary List all event subscriptions for a specific domain topic
 *
 * List all event subscriptions that have been created for a specific domain
 * topic
 *
 * @param {string} resourceGroupName The name of the resource group within the
 * user's subscription.
 *
 * @param {string} domainName Name of the top level domain
 *
 * @param {string} topicName Name of the domain topic
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] Filter the results using OData syntax.
 *
 * @param {number} [options.top] The number of results to return.
 *
 * @param {string} [options.label] The label used to filter the results for
 * event subscriptions list.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listByDomainTopic(resourceGroupName, domainName, topicName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  let label = (options && options.label !== undefined) ? options.label : undefined;
  // Validate
  try {
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (domainName === null || domainName === undefined || typeof domainName.valueOf() !== 'string') {
      throw new Error('domainName cannot be null or undefined and it must be of type string.');
    }
    if (topicName === null || topicName === undefined || typeof topicName.valueOf() !== 'string') {
      throw new Error('topicName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') {
      throw new Error('label must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.EventGrid/domains/{domainName}/topics/{topicName}/providers/Microsoft.EventGrid/eventSubscriptions';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{domainName}', encodeURIComponent(domainName));
  requestUrl = requestUrl.replace('{topicName}', encodeURIComponent(topicName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (label !== null && label !== undefined) {
    queryParameters.push('label=' + encodeURIComponent(label));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary Create or update an event subscription
 *
 * Asynchronously creates a new event subscription or updates an existing event
 * subscription based on the specified scope.
 *
 * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription. Event
 * subscription names must be between 3 and 64 characters in length and should
 * use alphanumeric letters only.
 *
 * @param {object} eventSubscriptionInfo Event subscription properties
 * containing the destination and filter information
 *
 * @param {object} [eventSubscriptionInfo.destination] Information about the
 * destination where events have to be delivered for the event subscription.
 *
 * @param {string} eventSubscriptionInfo.destination.endpointType Polymorphic
 * Discriminator
 *
 * @param {object} [eventSubscriptionInfo.filter] Information about the filter
 * for the event subscription.
 *
 * @param {string} [eventSubscriptionInfo.filter.subjectBeginsWith] An optional
 * string to filter events for an event subscription based on a resource path
 * prefix.
 * The format of this depends on the publisher of the events.
 * Wildcard characters are not supported in this path.
 *
 * @param {string} [eventSubscriptionInfo.filter.subjectEndsWith] An optional
 * string to filter events for an event subscription based on a resource path
 * suffix.
 * Wildcard characters are not supported in this path.
 *
 * @param {array} [eventSubscriptionInfo.filter.includedEventTypes] A list of
 * applicable event types that need to be part of the event subscription. If it
 * is desired to subscribe to all default event types, set the
 * IncludedEventTypes to null.
 *
 * @param {boolean} [eventSubscriptionInfo.filter.isSubjectCaseSensitive]
 * Specifies if the SubjectBeginsWith and SubjectEndsWith properties of the
 * filter
 * should be compared in a case sensitive manner.
 *
 * @param {array} [eventSubscriptionInfo.filter.advancedFilters] An array of
 * advanced filters that are used for filtering event subscriptions.
 *
 * @param {array} [eventSubscriptionInfo.labels] List of user defined labels.
 *
 * @param {date} [eventSubscriptionInfo.expirationTimeUtc] Expiration time of
 * the event subscription.
 *
 * @param {string} [eventSubscriptionInfo.eventDeliverySchema] The event
 * delivery schema for the event subscription. Possible values include:
 * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
 *
 * @param {object} [eventSubscriptionInfo.retryPolicy] The retry policy for
 * events. This can be used to configure maximum number of delivery attempts
 * and time to live for events.
 *
 * @param {number} [eventSubscriptionInfo.retryPolicy.maxDeliveryAttempts]
 * Maximum number of delivery retry attempts for events.
 *
 * @param {number} [eventSubscriptionInfo.retryPolicy.eventTimeToLiveInMinutes]
 * Time To Live (in minutes) for events.
 *
 * @param {object} [eventSubscriptionInfo.deadLetterDestination] The DeadLetter
 * destination of the event subscription.
 *
 * @param {string} eventSubscriptionInfo.deadLetterDestination.endpointType
 * Polymorphic Discriminator
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscription} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _beginCreateOrUpdate(scope, eventSubscriptionName, eventSubscriptionInfo, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (scope === null || scope === undefined || typeof scope.valueOf() !== 'string') {
      throw new Error('scope cannot be null or undefined and it must be of type string.');
    }
    if (eventSubscriptionName === null || eventSubscriptionName === undefined || typeof eventSubscriptionName.valueOf() !== 'string') {
      throw new Error('eventSubscriptionName cannot be null or undefined and it must be of type string.');
    }
    if (eventSubscriptionInfo === null || eventSubscriptionInfo === undefined) {
      throw new Error('eventSubscriptionInfo cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{scope}/providers/Microsoft.EventGrid/eventSubscriptions/{eventSubscriptionName}';
  requestUrl = requestUrl.replace('{scope}', scope);
  requestUrl = requestUrl.replace('{eventSubscriptionName}', encodeURIComponent(eventSubscriptionName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'PUT';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  // Serialize Request
  let requestContent = null;
  let requestModel = null;
  try {
    if (eventSubscriptionInfo !== null && eventSubscriptionInfo !== undefined) {
      let requestModelMapper = new client.models['EventSubscription']().mapper();
      requestModel = client.serialize(requestModelMapper, eventSubscriptionInfo, 'eventSubscriptionInfo');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(eventSubscriptionInfo, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 201) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 201) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscription']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary Delete an event subscription
 *
 * Delete an existing event subscription
 *
 * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _beginDeleteMethod(scope, eventSubscriptionName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (scope === null || scope === undefined || typeof scope.valueOf() !== 'string') {
      throw new Error('scope cannot be null or undefined and it must be of type string.');
    }
    if (eventSubscriptionName === null || eventSubscriptionName === undefined || typeof eventSubscriptionName.valueOf() !== 'string') {
      throw new Error('eventSubscriptionName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{scope}/providers/Microsoft.EventGrid/eventSubscriptions/{eventSubscriptionName}';
  requestUrl = requestUrl.replace('{scope}', scope);
  requestUrl = requestUrl.replace('{eventSubscriptionName}', encodeURIComponent(eventSubscriptionName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'DELETE';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200 && statusCode !== 202 && statusCode !== 204) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary Update an event subscription
 *
 * Asynchronously updates an existing event subscription.
 *
 * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription to be
 * updated
 *
 * @param {object} eventSubscriptionUpdateParameters Updated event subscription
 * information
 *
 * @param {object} [eventSubscriptionUpdateParameters.destination] Information
 * about the destination where events have to be delivered for the event
 * subscription.
 *
 * @param {string} eventSubscriptionUpdateParameters.destination.endpointType
 * Polymorphic Discriminator
 *
 * @param {object} [eventSubscriptionUpdateParameters.filter] Information about
 * the filter for the event subscription.
 *
 * @param {string} [eventSubscriptionUpdateParameters.filter.subjectBeginsWith]
 * An optional string to filter events for an event subscription based on a
 * resource path prefix.
 * The format of this depends on the publisher of the events.
 * Wildcard characters are not supported in this path.
 *
 * @param {string} [eventSubscriptionUpdateParameters.filter.subjectEndsWith]
 * An optional string to filter events for an event subscription based on a
 * resource path suffix.
 * Wildcard characters are not supported in this path.
 *
 * @param {array} [eventSubscriptionUpdateParameters.filter.includedEventTypes]
 * A list of applicable event types that need to be part of the event
 * subscription. If it is desired to subscribe to all default event types, set
 * the IncludedEventTypes to null.
 *
 * @param {boolean}
 * [eventSubscriptionUpdateParameters.filter.isSubjectCaseSensitive] Specifies
 * if the SubjectBeginsWith and SubjectEndsWith properties of the filter
 * should be compared in a case sensitive manner.
 *
 * @param {array} [eventSubscriptionUpdateParameters.filter.advancedFilters] An
 * array of advanced filters that are used for filtering event subscriptions.
 *
 * @param {array} [eventSubscriptionUpdateParameters.labels] List of user
 * defined labels.
 *
 * @param {date} [eventSubscriptionUpdateParameters.expirationTimeUtc]
 * Information about the expiration time for the event subscription.
 *
 * @param {string} [eventSubscriptionUpdateParameters.eventDeliverySchema] The
 * event delivery schema for the event subscription. Possible values include:
 * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
 *
 * @param {object} [eventSubscriptionUpdateParameters.retryPolicy] The retry
 * policy for events. This can be used to configure maximum number of delivery
 * attempts and time to live for events.
 *
 * @param {number}
 * [eventSubscriptionUpdateParameters.retryPolicy.maxDeliveryAttempts] Maximum
 * number of delivery retry attempts for events.
 *
 * @param {number}
 * [eventSubscriptionUpdateParameters.retryPolicy.eventTimeToLiveInMinutes]
 * Time To Live (in minutes) for events.
 *
 * @param {object} [eventSubscriptionUpdateParameters.deadLetterDestination]
 * The DeadLetter destination of the event subscription.
 *
 * @param {string}
 * eventSubscriptionUpdateParameters.deadLetterDestination.endpointType
 * Polymorphic Discriminator
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscription} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _beginUpdate(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (scope === null || scope === undefined || typeof scope.valueOf() !== 'string') {
      throw new Error('scope cannot be null or undefined and it must be of type string.');
    }
    if (eventSubscriptionName === null || eventSubscriptionName === undefined || typeof eventSubscriptionName.valueOf() !== 'string') {
      throw new Error('eventSubscriptionName cannot be null or undefined and it must be of type string.');
    }
    if (eventSubscriptionUpdateParameters === null || eventSubscriptionUpdateParameters === undefined) {
      throw new Error('eventSubscriptionUpdateParameters cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{scope}/providers/Microsoft.EventGrid/eventSubscriptions/{eventSubscriptionName}';
  requestUrl = requestUrl.replace('{scope}', scope);
  requestUrl = requestUrl.replace('{eventSubscriptionName}', encodeURIComponent(eventSubscriptionName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'PATCH';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  // Serialize Request
  let requestContent = null;
  let requestModel = null;
  try {
    if (eventSubscriptionUpdateParameters !== null && eventSubscriptionUpdateParameters !== undefined) {
      let requestModelMapper = new client.models['EventSubscriptionUpdateParameters']().mapper();
      requestModel = client.serialize(requestModelMapper, eventSubscriptionUpdateParameters, 'eventSubscriptionUpdateParameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(eventSubscriptionUpdateParameters, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 201) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 201) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscription']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listGlobalBySubscriptionNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary List all global event subscriptions for a topic type
 *
 * List all global event subscriptions under an Azure subscription for a topic
 * type.
 *
 * @param {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listGlobalBySubscriptionForTopicTypeNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listGlobalByResourceGroupNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listGlobalByResourceGroupForTopicTypeNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary List all regional event subscriptions under an Azure subscription
 *
 * List all event subscriptions from the given location under a specific Azure
 * subscription
 *
 * @param {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listRegionalBySubscriptionNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listRegionalByResourceGroupNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listRegionalBySubscriptionForTopicTypeNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary 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 {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listRegionalByResourceGroupForTopicTypeNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary List all event subscriptions for a specific topic
 *
 * List all event subscriptions that have been created for a specific topic
 *
 * @param {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listByResourceNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * @summary List all event subscriptions for a specific domain topic
 *
 * List all event subscriptions that have been created for a specific domain
 * topic
 *
 * @param {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link EventSubscriptionsListResult} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listByDomainTopicNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['EventSubscriptionsListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/** Class representing a EventSubscriptions. */
class EventSubscriptions {
  /**
   * Create a EventSubscriptions.
   * @param {EventGridManagementClient} client Reference to the service client.
   */
  constructor(client) {
    this.client = client;
    this._get = _get;
    this._createOrUpdate = _createOrUpdate;
    this._deleteMethod = _deleteMethod;
    this._update = _update;
    this._getFullUrl = _getFullUrl;
    this._listGlobalBySubscription = _listGlobalBySubscription;
    this._listGlobalBySubscriptionForTopicType = _listGlobalBySubscriptionForTopicType;
    this._listGlobalByResourceGroup = _listGlobalByResourceGroup;
    this._listGlobalByResourceGroupForTopicType = _listGlobalByResourceGroupForTopicType;
    this._listRegionalBySubscription = _listRegionalBySubscription;
    this._listRegionalByResourceGroup = _listRegionalByResourceGroup;
    this._listRegionalBySubscriptionForTopicType = _listRegionalBySubscriptionForTopicType;
    this._listRegionalByResourceGroupForTopicType = _listRegionalByResourceGroupForTopicType;
    this._listByResource = _listByResource;
    this._listByDomainTopic = _listByDomainTopic;
    this._beginCreateOrUpdate = _beginCreateOrUpdate;
    this._beginDeleteMethod = _beginDeleteMethod;
    this._beginUpdate = _beginUpdate;
    this._listGlobalBySubscriptionNext = _listGlobalBySubscriptionNext;
    this._listGlobalBySubscriptionForTopicTypeNext = _listGlobalBySubscriptionForTopicTypeNext;
    this._listGlobalByResourceGroupNext = _listGlobalByResourceGroupNext;
    this._listGlobalByResourceGroupForTopicTypeNext = _listGlobalByResourceGroupForTopicTypeNext;
    this._listRegionalBySubscriptionNext = _listRegionalBySubscriptionNext;
    this._listRegionalByResourceGroupNext = _listRegionalByResourceGroupNext;
    this._listRegionalBySubscriptionForTopicTypeNext = _listRegionalBySubscriptionForTopicTypeNext;
    this._listRegionalByResourceGroupForTopicTypeNext = _listRegionalByResourceGroupForTopicTypeNext;
    this._listByResourceNext = _listByResourceNext;
    this._listByDomainTopicNext = _listByDomainTopicNext;
  }

  /**
   * @summary Get an event subscription
   *
   * Get properties of an event subscription
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscription>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getWithHttpOperationResponse(scope, eventSubscriptionName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._get(scope, eventSubscriptionName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Get an event subscription
   *
   * Get properties of an event subscription
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscription} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscription} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  get(scope, eventSubscriptionName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._get(scope, eventSubscriptionName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._get(scope, eventSubscriptionName, options, optionalCallback);
    }
  }

  /**
   * @summary Create or update an event subscription
   *
   * Asynchronously creates a new event subscription or updates an existing event
   * subscription based on the specified scope.
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription. Event
   * subscription names must be between 3 and 64 characters in length and should
   * use alphanumeric letters only.
   *
   * @param {object} eventSubscriptionInfo Event subscription properties
   * containing the destination and filter information
   *
   * @param {object} [eventSubscriptionInfo.destination] Information about the
   * destination where events have to be delivered for the event subscription.
   *
   * @param {string} eventSubscriptionInfo.destination.endpointType Polymorphic
   * Discriminator
   *
   * @param {object} [eventSubscriptionInfo.filter] Information about the filter
   * for the event subscription.
   *
   * @param {string} [eventSubscriptionInfo.filter.subjectBeginsWith] An optional
   * string to filter events for an event subscription based on a resource path
   * prefix.
   * The format of this depends on the publisher of the events.
   * Wildcard characters are not supported in this path.
   *
   * @param {string} [eventSubscriptionInfo.filter.subjectEndsWith] An optional
   * string to filter events for an event subscription based on a resource path
   * suffix.
   * Wildcard characters are not supported in this path.
   *
   * @param {array} [eventSubscriptionInfo.filter.includedEventTypes] A list of
   * applicable event types that need to be part of the event subscription. If it
   * is desired to subscribe to all default event types, set the
   * IncludedEventTypes to null.
   *
   * @param {boolean} [eventSubscriptionInfo.filter.isSubjectCaseSensitive]
   * Specifies if the SubjectBeginsWith and SubjectEndsWith properties of the
   * filter
   * should be compared in a case sensitive manner.
   *
   * @param {array} [eventSubscriptionInfo.filter.advancedFilters] An array of
   * advanced filters that are used for filtering event subscriptions.
   *
   * @param {array} [eventSubscriptionInfo.labels] List of user defined labels.
   *
   * @param {date} [eventSubscriptionInfo.expirationTimeUtc] Expiration time of
   * the event subscription.
   *
   * @param {string} [eventSubscriptionInfo.eventDeliverySchema] The event
   * delivery schema for the event subscription. Possible values include:
   * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
   *
   * @param {object} [eventSubscriptionInfo.retryPolicy] The retry policy for
   * events. This can be used to configure maximum number of delivery attempts
   * and time to live for events.
   *
   * @param {number} [eventSubscriptionInfo.retryPolicy.maxDeliveryAttempts]
   * Maximum number of delivery retry attempts for events.
   *
   * @param {number} [eventSubscriptionInfo.retryPolicy.eventTimeToLiveInMinutes]
   * Time To Live (in minutes) for events.
   *
   * @param {object} [eventSubscriptionInfo.deadLetterDestination] The DeadLetter
   * destination of the event subscription.
   *
   * @param {string} eventSubscriptionInfo.deadLetterDestination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscription>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createOrUpdateWithHttpOperationResponse(scope, eventSubscriptionName, eventSubscriptionInfo, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._createOrUpdate(scope, eventSubscriptionName, eventSubscriptionInfo, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Create or update an event subscription
   *
   * Asynchronously creates a new event subscription or updates an existing event
   * subscription based on the specified scope.
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription. Event
   * subscription names must be between 3 and 64 characters in length and should
   * use alphanumeric letters only.
   *
   * @param {object} eventSubscriptionInfo Event subscription properties
   * containing the destination and filter information
   *
   * @param {object} [eventSubscriptionInfo.destination] Information about the
   * destination where events have to be delivered for the event subscription.
   *
   * @param {string} eventSubscriptionInfo.destination.endpointType Polymorphic
   * Discriminator
   *
   * @param {object} [eventSubscriptionInfo.filter] Information about the filter
   * for the event subscription.
   *
   * @param {string} [eventSubscriptionInfo.filter.subjectBeginsWith] An optional
   * string to filter events for an event subscription based on a resource path
   * prefix.
   * The format of this depends on the publisher of the events.
   * Wildcard characters are not supported in this path.
   *
   * @param {string} [eventSubscriptionInfo.filter.subjectEndsWith] An optional
   * string to filter events for an event subscription based on a resource path
   * suffix.
   * Wildcard characters are not supported in this path.
   *
   * @param {array} [eventSubscriptionInfo.filter.includedEventTypes] A list of
   * applicable event types that need to be part of the event subscription. If it
   * is desired to subscribe to all default event types, set the
   * IncludedEventTypes to null.
   *
   * @param {boolean} [eventSubscriptionInfo.filter.isSubjectCaseSensitive]
   * Specifies if the SubjectBeginsWith and SubjectEndsWith properties of the
   * filter
   * should be compared in a case sensitive manner.
   *
   * @param {array} [eventSubscriptionInfo.filter.advancedFilters] An array of
   * advanced filters that are used for filtering event subscriptions.
   *
   * @param {array} [eventSubscriptionInfo.labels] List of user defined labels.
   *
   * @param {date} [eventSubscriptionInfo.expirationTimeUtc] Expiration time of
   * the event subscription.
   *
   * @param {string} [eventSubscriptionInfo.eventDeliverySchema] The event
   * delivery schema for the event subscription. Possible values include:
   * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
   *
   * @param {object} [eventSubscriptionInfo.retryPolicy] The retry policy for
   * events. This can be used to configure maximum number of delivery attempts
   * and time to live for events.
   *
   * @param {number} [eventSubscriptionInfo.retryPolicy.maxDeliveryAttempts]
   * Maximum number of delivery retry attempts for events.
   *
   * @param {number} [eventSubscriptionInfo.retryPolicy.eventTimeToLiveInMinutes]
   * Time To Live (in minutes) for events.
   *
   * @param {object} [eventSubscriptionInfo.deadLetterDestination] The DeadLetter
   * destination of the event subscription.
   *
   * @param {string} eventSubscriptionInfo.deadLetterDestination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscription} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscription} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  createOrUpdate(scope, eventSubscriptionName, eventSubscriptionInfo, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._createOrUpdate(scope, eventSubscriptionName, eventSubscriptionInfo, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._createOrUpdate(scope, eventSubscriptionName, eventSubscriptionInfo, options, optionalCallback);
    }
  }

  /**
   * @summary Delete an event subscription
   *
   * Delete an existing event subscription
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  deleteMethodWithHttpOperationResponse(scope, eventSubscriptionName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._deleteMethod(scope, eventSubscriptionName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Delete an event subscription
   *
   * Delete an existing event subscription
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {null} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  deleteMethod(scope, eventSubscriptionName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._deleteMethod(scope, eventSubscriptionName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._deleteMethod(scope, eventSubscriptionName, options, optionalCallback);
    }
  }

  /**
   * @summary Update an event subscription
   *
   * Asynchronously updates an existing event subscription.
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription to be
   * updated
   *
   * @param {object} eventSubscriptionUpdateParameters Updated event subscription
   * information
   *
   * @param {object} [eventSubscriptionUpdateParameters.destination] Information
   * about the destination where events have to be delivered for the event
   * subscription.
   *
   * @param {string} eventSubscriptionUpdateParameters.destination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [eventSubscriptionUpdateParameters.filter] Information about
   * the filter for the event subscription.
   *
   * @param {string} [eventSubscriptionUpdateParameters.filter.subjectBeginsWith]
   * An optional string to filter events for an event subscription based on a
   * resource path prefix.
   * The format of this depends on the publisher of the events.
   * Wildcard characters are not supported in this path.
   *
   * @param {string} [eventSubscriptionUpdateParameters.filter.subjectEndsWith]
   * An optional string to filter events for an event subscription based on a
   * resource path suffix.
   * Wildcard characters are not supported in this path.
   *
   * @param {array} [eventSubscriptionUpdateParameters.filter.includedEventTypes]
   * A list of applicable event types that need to be part of the event
   * subscription. If it is desired to subscribe to all default event types, set
   * the IncludedEventTypes to null.
   *
   * @param {boolean}
   * [eventSubscriptionUpdateParameters.filter.isSubjectCaseSensitive] Specifies
   * if the SubjectBeginsWith and SubjectEndsWith properties of the filter
   * should be compared in a case sensitive manner.
   *
   * @param {array} [eventSubscriptionUpdateParameters.filter.advancedFilters] An
   * array of advanced filters that are used for filtering event subscriptions.
   *
   * @param {array} [eventSubscriptionUpdateParameters.labels] List of user
   * defined labels.
   *
   * @param {date} [eventSubscriptionUpdateParameters.expirationTimeUtc]
   * Information about the expiration time for the event subscription.
   *
   * @param {string} [eventSubscriptionUpdateParameters.eventDeliverySchema] The
   * event delivery schema for the event subscription. Possible values include:
   * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
   *
   * @param {object} [eventSubscriptionUpdateParameters.retryPolicy] The retry
   * policy for events. This can be used to configure maximum number of delivery
   * attempts and time to live for events.
   *
   * @param {number}
   * [eventSubscriptionUpdateParameters.retryPolicy.maxDeliveryAttempts] Maximum
   * number of delivery retry attempts for events.
   *
   * @param {number}
   * [eventSubscriptionUpdateParameters.retryPolicy.eventTimeToLiveInMinutes]
   * Time To Live (in minutes) for events.
   *
   * @param {object} [eventSubscriptionUpdateParameters.deadLetterDestination]
   * The DeadLetter destination of the event subscription.
   *
   * @param {string}
   * eventSubscriptionUpdateParameters.deadLetterDestination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscription>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  updateWithHttpOperationResponse(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._update(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Update an event subscription
   *
   * Asynchronously updates an existing event subscription.
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription to be
   * updated
   *
   * @param {object} eventSubscriptionUpdateParameters Updated event subscription
   * information
   *
   * @param {object} [eventSubscriptionUpdateParameters.destination] Information
   * about the destination where events have to be delivered for the event
   * subscription.
   *
   * @param {string} eventSubscriptionUpdateParameters.destination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [eventSubscriptionUpdateParameters.filter] Information about
   * the filter for the event subscription.
   *
   * @param {string} [eventSubscriptionUpdateParameters.filter.subjectBeginsWith]
   * An optional string to filter events for an event subscription based on a
   * resource path prefix.
   * The format of this depends on the publisher of the events.
   * Wildcard characters are not supported in this path.
   *
   * @param {string} [eventSubscriptionUpdateParameters.filter.subjectEndsWith]
   * An optional string to filter events for an event subscription based on a
   * resource path suffix.
   * Wildcard characters are not supported in this path.
   *
   * @param {array} [eventSubscriptionUpdateParameters.filter.includedEventTypes]
   * A list of applicable event types that need to be part of the event
   * subscription. If it is desired to subscribe to all default event types, set
   * the IncludedEventTypes to null.
   *
   * @param {boolean}
   * [eventSubscriptionUpdateParameters.filter.isSubjectCaseSensitive] Specifies
   * if the SubjectBeginsWith and SubjectEndsWith properties of the filter
   * should be compared in a case sensitive manner.
   *
   * @param {array} [eventSubscriptionUpdateParameters.filter.advancedFilters] An
   * array of advanced filters that are used for filtering event subscriptions.
   *
   * @param {array} [eventSubscriptionUpdateParameters.labels] List of user
   * defined labels.
   *
   * @param {date} [eventSubscriptionUpdateParameters.expirationTimeUtc]
   * Information about the expiration time for the event subscription.
   *
   * @param {string} [eventSubscriptionUpdateParameters.eventDeliverySchema] The
   * event delivery schema for the event subscription. Possible values include:
   * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
   *
   * @param {object} [eventSubscriptionUpdateParameters.retryPolicy] The retry
   * policy for events. This can be used to configure maximum number of delivery
   * attempts and time to live for events.
   *
   * @param {number}
   * [eventSubscriptionUpdateParameters.retryPolicy.maxDeliveryAttempts] Maximum
   * number of delivery retry attempts for events.
   *
   * @param {number}
   * [eventSubscriptionUpdateParameters.retryPolicy.eventTimeToLiveInMinutes]
   * Time To Live (in minutes) for events.
   *
   * @param {object} [eventSubscriptionUpdateParameters.deadLetterDestination]
   * The DeadLetter destination of the event subscription.
   *
   * @param {string}
   * eventSubscriptionUpdateParameters.deadLetterDestination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscription} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscription} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  update(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._update(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._update(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options, optionalCallback);
    }
  }

  /**
   * @summary Get full URL of an event subscription
   *
   * Get the full endpoint URL for an event subscription
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionFullUrl>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getFullUrlWithHttpOperationResponse(scope, eventSubscriptionName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._getFullUrl(scope, eventSubscriptionName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Get full URL of an event subscription
   *
   * Get the full endpoint URL for an event subscription
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionFullUrl} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionFullUrl} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  getFullUrl(scope, eventSubscriptionName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._getFullUrl(scope, eventSubscriptionName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._getFullUrl(scope, eventSubscriptionName, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listGlobalBySubscriptionWithHttpOperationResponse(options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listGlobalBySubscription(options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listGlobalBySubscription(options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listGlobalBySubscription(options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listGlobalBySubscription(options, optionalCallback);
    }
  }

  /**
   * @summary List all global event subscriptions for a topic type
   *
   * List all global event subscriptions under an Azure subscription for a topic
   * type.
   *
   * @param {string} topicTypeName Name of the topic type
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listGlobalBySubscriptionForTopicTypeWithHttpOperationResponse(topicTypeName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listGlobalBySubscriptionForTopicType(topicTypeName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary List all global event subscriptions for a topic type
   *
   * List all global event subscriptions under an Azure subscription for a topic
   * type.
   *
   * @param {string} topicTypeName Name of the topic type
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listGlobalBySubscriptionForTopicType(topicTypeName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listGlobalBySubscriptionForTopicType(topicTypeName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listGlobalBySubscriptionForTopicType(topicTypeName, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listGlobalByResourceGroupWithHttpOperationResponse(resourceGroupName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listGlobalByResourceGroup(resourceGroupName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listGlobalByResourceGroup(resourceGroupName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listGlobalByResourceGroup(resourceGroupName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listGlobalByResourceGroup(resourceGroupName, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {string} topicTypeName Name of the topic type
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listGlobalByResourceGroupForTopicTypeWithHttpOperationResponse(resourceGroupName, topicTypeName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listGlobalByResourceGroupForTopicType(resourceGroupName, topicTypeName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {string} topicTypeName Name of the topic type
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listGlobalByResourceGroupForTopicType(resourceGroupName, topicTypeName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listGlobalByResourceGroupForTopicType(resourceGroupName, topicTypeName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listGlobalByResourceGroupForTopicType(resourceGroupName, topicTypeName, options, optionalCallback);
    }
  }

  /**
   * @summary List all regional event subscriptions under an Azure subscription
   *
   * List all event subscriptions from the given location under a specific Azure
   * subscription
   *
   * @param {string} location Name of the location
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listRegionalBySubscriptionWithHttpOperationResponse(location, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listRegionalBySubscription(location, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary List all regional event subscriptions under an Azure subscription
   *
   * List all event subscriptions from the given location under a specific Azure
   * subscription
   *
   * @param {string} location Name of the location
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listRegionalBySubscription(location, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listRegionalBySubscription(location, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listRegionalBySubscription(location, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {string} location Name of the location
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listRegionalByResourceGroupWithHttpOperationResponse(resourceGroupName, location, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listRegionalByResourceGroup(resourceGroupName, location, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {string} location Name of the location
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listRegionalByResourceGroup(resourceGroupName, location, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listRegionalByResourceGroup(resourceGroupName, location, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listRegionalByResourceGroup(resourceGroupName, location, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {string} location Name of the location
   *
   * @param {string} topicTypeName Name of the topic type
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listRegionalBySubscriptionForTopicTypeWithHttpOperationResponse(location, topicTypeName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listRegionalBySubscriptionForTopicType(location, topicTypeName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {string} location Name of the location
   *
   * @param {string} topicTypeName Name of the topic type
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listRegionalBySubscriptionForTopicType(location, topicTypeName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listRegionalBySubscriptionForTopicType(location, topicTypeName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listRegionalBySubscriptionForTopicType(location, topicTypeName, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {string} location Name of the location
   *
   * @param {string} topicTypeName Name of the topic type
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listRegionalByResourceGroupForTopicTypeWithHttpOperationResponse(resourceGroupName, location, topicTypeName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listRegionalByResourceGroupForTopicType(resourceGroupName, location, topicTypeName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {string} location Name of the location
   *
   * @param {string} topicTypeName Name of the topic type
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listRegionalByResourceGroupForTopicType(resourceGroupName, location, topicTypeName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listRegionalByResourceGroupForTopicType(resourceGroupName, location, topicTypeName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listRegionalByResourceGroupForTopicType(resourceGroupName, location, topicTypeName, options, optionalCallback);
    }
  }

  /**
   * @summary List all event subscriptions for a specific topic
   *
   * List all event subscriptions that have been created for a specific topic
   *
   * @param {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {string} providerNamespace Namespace of the provider of the topic
   *
   * @param {string} resourceTypeName Name of the resource type
   *
   * @param {string} resourceName Name of the resource
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByResourceWithHttpOperationResponse(resourceGroupName, providerNamespace, resourceTypeName, resourceName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByResource(resourceGroupName, providerNamespace, resourceTypeName, resourceName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary List all event subscriptions for a specific topic
   *
   * List all event subscriptions that have been created for a specific topic
   *
   * @param {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {string} providerNamespace Namespace of the provider of the topic
   *
   * @param {string} resourceTypeName Name of the resource type
   *
   * @param {string} resourceName Name of the resource
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listByResource(resourceGroupName, providerNamespace, resourceTypeName, resourceName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listByResource(resourceGroupName, providerNamespace, resourceTypeName, resourceName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByResource(resourceGroupName, providerNamespace, resourceTypeName, resourceName, options, optionalCallback);
    }
  }

  /**
   * @summary List all event subscriptions for a specific domain topic
   *
   * List all event subscriptions that have been created for a specific domain
   * topic
   *
   * @param {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {string} domainName Name of the top level domain
   *
   * @param {string} topicName Name of the domain topic
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByDomainTopicWithHttpOperationResponse(resourceGroupName, domainName, topicName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByDomainTopic(resourceGroupName, domainName, topicName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary List all event subscriptions for a specific domain topic
   *
   * List all event subscriptions that have been created for a specific domain
   * topic
   *
   * @param {string} resourceGroupName The name of the resource group within the
   * user's subscription.
   *
   * @param {string} domainName Name of the top level domain
   *
   * @param {string} topicName Name of the domain topic
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] Filter the results using OData syntax.
   *
   * @param {number} [options.top] The number of results to return.
   *
   * @param {string} [options.label] The label used to filter the results for
   * event subscriptions list.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listByDomainTopic(resourceGroupName, domainName, topicName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listByDomainTopic(resourceGroupName, domainName, topicName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByDomainTopic(resourceGroupName, domainName, topicName, options, optionalCallback);
    }
  }

  /**
   * @summary Create or update an event subscription
   *
   * Asynchronously creates a new event subscription or updates an existing event
   * subscription based on the specified scope.
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription. Event
   * subscription names must be between 3 and 64 characters in length and should
   * use alphanumeric letters only.
   *
   * @param {object} eventSubscriptionInfo Event subscription properties
   * containing the destination and filter information
   *
   * @param {object} [eventSubscriptionInfo.destination] Information about the
   * destination where events have to be delivered for the event subscription.
   *
   * @param {string} eventSubscriptionInfo.destination.endpointType Polymorphic
   * Discriminator
   *
   * @param {object} [eventSubscriptionInfo.filter] Information about the filter
   * for the event subscription.
   *
   * @param {string} [eventSubscriptionInfo.filter.subjectBeginsWith] An optional
   * string to filter events for an event subscription based on a resource path
   * prefix.
   * The format of this depends on the publisher of the events.
   * Wildcard characters are not supported in this path.
   *
   * @param {string} [eventSubscriptionInfo.filter.subjectEndsWith] An optional
   * string to filter events for an event subscription based on a resource path
   * suffix.
   * Wildcard characters are not supported in this path.
   *
   * @param {array} [eventSubscriptionInfo.filter.includedEventTypes] A list of
   * applicable event types that need to be part of the event subscription. If it
   * is desired to subscribe to all default event types, set the
   * IncludedEventTypes to null.
   *
   * @param {boolean} [eventSubscriptionInfo.filter.isSubjectCaseSensitive]
   * Specifies if the SubjectBeginsWith and SubjectEndsWith properties of the
   * filter
   * should be compared in a case sensitive manner.
   *
   * @param {array} [eventSubscriptionInfo.filter.advancedFilters] An array of
   * advanced filters that are used for filtering event subscriptions.
   *
   * @param {array} [eventSubscriptionInfo.labels] List of user defined labels.
   *
   * @param {date} [eventSubscriptionInfo.expirationTimeUtc] Expiration time of
   * the event subscription.
   *
   * @param {string} [eventSubscriptionInfo.eventDeliverySchema] The event
   * delivery schema for the event subscription. Possible values include:
   * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
   *
   * @param {object} [eventSubscriptionInfo.retryPolicy] The retry policy for
   * events. This can be used to configure maximum number of delivery attempts
   * and time to live for events.
   *
   * @param {number} [eventSubscriptionInfo.retryPolicy.maxDeliveryAttempts]
   * Maximum number of delivery retry attempts for events.
   *
   * @param {number} [eventSubscriptionInfo.retryPolicy.eventTimeToLiveInMinutes]
   * Time To Live (in minutes) for events.
   *
   * @param {object} [eventSubscriptionInfo.deadLetterDestination] The DeadLetter
   * destination of the event subscription.
   *
   * @param {string} eventSubscriptionInfo.deadLetterDestination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscription>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginCreateOrUpdateWithHttpOperationResponse(scope, eventSubscriptionName, eventSubscriptionInfo, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginCreateOrUpdate(scope, eventSubscriptionName, eventSubscriptionInfo, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Create or update an event subscription
   *
   * Asynchronously creates a new event subscription or updates an existing event
   * subscription based on the specified scope.
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription. Event
   * subscription names must be between 3 and 64 characters in length and should
   * use alphanumeric letters only.
   *
   * @param {object} eventSubscriptionInfo Event subscription properties
   * containing the destination and filter information
   *
   * @param {object} [eventSubscriptionInfo.destination] Information about the
   * destination where events have to be delivered for the event subscription.
   *
   * @param {string} eventSubscriptionInfo.destination.endpointType Polymorphic
   * Discriminator
   *
   * @param {object} [eventSubscriptionInfo.filter] Information about the filter
   * for the event subscription.
   *
   * @param {string} [eventSubscriptionInfo.filter.subjectBeginsWith] An optional
   * string to filter events for an event subscription based on a resource path
   * prefix.
   * The format of this depends on the publisher of the events.
   * Wildcard characters are not supported in this path.
   *
   * @param {string} [eventSubscriptionInfo.filter.subjectEndsWith] An optional
   * string to filter events for an event subscription based on a resource path
   * suffix.
   * Wildcard characters are not supported in this path.
   *
   * @param {array} [eventSubscriptionInfo.filter.includedEventTypes] A list of
   * applicable event types that need to be part of the event subscription. If it
   * is desired to subscribe to all default event types, set the
   * IncludedEventTypes to null.
   *
   * @param {boolean} [eventSubscriptionInfo.filter.isSubjectCaseSensitive]
   * Specifies if the SubjectBeginsWith and SubjectEndsWith properties of the
   * filter
   * should be compared in a case sensitive manner.
   *
   * @param {array} [eventSubscriptionInfo.filter.advancedFilters] An array of
   * advanced filters that are used for filtering event subscriptions.
   *
   * @param {array} [eventSubscriptionInfo.labels] List of user defined labels.
   *
   * @param {date} [eventSubscriptionInfo.expirationTimeUtc] Expiration time of
   * the event subscription.
   *
   * @param {string} [eventSubscriptionInfo.eventDeliverySchema] The event
   * delivery schema for the event subscription. Possible values include:
   * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
   *
   * @param {object} [eventSubscriptionInfo.retryPolicy] The retry policy for
   * events. This can be used to configure maximum number of delivery attempts
   * and time to live for events.
   *
   * @param {number} [eventSubscriptionInfo.retryPolicy.maxDeliveryAttempts]
   * Maximum number of delivery retry attempts for events.
   *
   * @param {number} [eventSubscriptionInfo.retryPolicy.eventTimeToLiveInMinutes]
   * Time To Live (in minutes) for events.
   *
   * @param {object} [eventSubscriptionInfo.deadLetterDestination] The DeadLetter
   * destination of the event subscription.
   *
   * @param {string} eventSubscriptionInfo.deadLetterDestination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscription} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscription} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  beginCreateOrUpdate(scope, eventSubscriptionName, eventSubscriptionInfo, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._beginCreateOrUpdate(scope, eventSubscriptionName, eventSubscriptionInfo, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginCreateOrUpdate(scope, eventSubscriptionName, eventSubscriptionInfo, options, optionalCallback);
    }
  }

  /**
   * @summary Delete an event subscription
   *
   * Delete an existing event subscription
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginDeleteMethodWithHttpOperationResponse(scope, eventSubscriptionName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginDeleteMethod(scope, eventSubscriptionName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Delete an event subscription
   *
   * Delete an existing event subscription
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {null} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  beginDeleteMethod(scope, eventSubscriptionName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._beginDeleteMethod(scope, eventSubscriptionName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginDeleteMethod(scope, eventSubscriptionName, options, optionalCallback);
    }
  }

  /**
   * @summary Update an event subscription
   *
   * Asynchronously updates an existing event subscription.
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription to be
   * updated
   *
   * @param {object} eventSubscriptionUpdateParameters Updated event subscription
   * information
   *
   * @param {object} [eventSubscriptionUpdateParameters.destination] Information
   * about the destination where events have to be delivered for the event
   * subscription.
   *
   * @param {string} eventSubscriptionUpdateParameters.destination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [eventSubscriptionUpdateParameters.filter] Information about
   * the filter for the event subscription.
   *
   * @param {string} [eventSubscriptionUpdateParameters.filter.subjectBeginsWith]
   * An optional string to filter events for an event subscription based on a
   * resource path prefix.
   * The format of this depends on the publisher of the events.
   * Wildcard characters are not supported in this path.
   *
   * @param {string} [eventSubscriptionUpdateParameters.filter.subjectEndsWith]
   * An optional string to filter events for an event subscription based on a
   * resource path suffix.
   * Wildcard characters are not supported in this path.
   *
   * @param {array} [eventSubscriptionUpdateParameters.filter.includedEventTypes]
   * A list of applicable event types that need to be part of the event
   * subscription. If it is desired to subscribe to all default event types, set
   * the IncludedEventTypes to null.
   *
   * @param {boolean}
   * [eventSubscriptionUpdateParameters.filter.isSubjectCaseSensitive] Specifies
   * if the SubjectBeginsWith and SubjectEndsWith properties of the filter
   * should be compared in a case sensitive manner.
   *
   * @param {array} [eventSubscriptionUpdateParameters.filter.advancedFilters] An
   * array of advanced filters that are used for filtering event subscriptions.
   *
   * @param {array} [eventSubscriptionUpdateParameters.labels] List of user
   * defined labels.
   *
   * @param {date} [eventSubscriptionUpdateParameters.expirationTimeUtc]
   * Information about the expiration time for the event subscription.
   *
   * @param {string} [eventSubscriptionUpdateParameters.eventDeliverySchema] The
   * event delivery schema for the event subscription. Possible values include:
   * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
   *
   * @param {object} [eventSubscriptionUpdateParameters.retryPolicy] The retry
   * policy for events. This can be used to configure maximum number of delivery
   * attempts and time to live for events.
   *
   * @param {number}
   * [eventSubscriptionUpdateParameters.retryPolicy.maxDeliveryAttempts] Maximum
   * number of delivery retry attempts for events.
   *
   * @param {number}
   * [eventSubscriptionUpdateParameters.retryPolicy.eventTimeToLiveInMinutes]
   * Time To Live (in minutes) for events.
   *
   * @param {object} [eventSubscriptionUpdateParameters.deadLetterDestination]
   * The DeadLetter destination of the event subscription.
   *
   * @param {string}
   * eventSubscriptionUpdateParameters.deadLetterDestination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscription>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginUpdateWithHttpOperationResponse(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginUpdate(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Update an event subscription
   *
   * Asynchronously updates an existing event subscription.
   *
   * @param {string} scope 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 {string} eventSubscriptionName Name of the event subscription to be
   * updated
   *
   * @param {object} eventSubscriptionUpdateParameters Updated event subscription
   * information
   *
   * @param {object} [eventSubscriptionUpdateParameters.destination] Information
   * about the destination where events have to be delivered for the event
   * subscription.
   *
   * @param {string} eventSubscriptionUpdateParameters.destination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [eventSubscriptionUpdateParameters.filter] Information about
   * the filter for the event subscription.
   *
   * @param {string} [eventSubscriptionUpdateParameters.filter.subjectBeginsWith]
   * An optional string to filter events for an event subscription based on a
   * resource path prefix.
   * The format of this depends on the publisher of the events.
   * Wildcard characters are not supported in this path.
   *
   * @param {string} [eventSubscriptionUpdateParameters.filter.subjectEndsWith]
   * An optional string to filter events for an event subscription based on a
   * resource path suffix.
   * Wildcard characters are not supported in this path.
   *
   * @param {array} [eventSubscriptionUpdateParameters.filter.includedEventTypes]
   * A list of applicable event types that need to be part of the event
   * subscription. If it is desired to subscribe to all default event types, set
   * the IncludedEventTypes to null.
   *
   * @param {boolean}
   * [eventSubscriptionUpdateParameters.filter.isSubjectCaseSensitive] Specifies
   * if the SubjectBeginsWith and SubjectEndsWith properties of the filter
   * should be compared in a case sensitive manner.
   *
   * @param {array} [eventSubscriptionUpdateParameters.filter.advancedFilters] An
   * array of advanced filters that are used for filtering event subscriptions.
   *
   * @param {array} [eventSubscriptionUpdateParameters.labels] List of user
   * defined labels.
   *
   * @param {date} [eventSubscriptionUpdateParameters.expirationTimeUtc]
   * Information about the expiration time for the event subscription.
   *
   * @param {string} [eventSubscriptionUpdateParameters.eventDeliverySchema] The
   * event delivery schema for the event subscription. Possible values include:
   * 'EventGridSchema', 'CloudEventV01Schema', 'CustomInputSchema'
   *
   * @param {object} [eventSubscriptionUpdateParameters.retryPolicy] The retry
   * policy for events. This can be used to configure maximum number of delivery
   * attempts and time to live for events.
   *
   * @param {number}
   * [eventSubscriptionUpdateParameters.retryPolicy.maxDeliveryAttempts] Maximum
   * number of delivery retry attempts for events.
   *
   * @param {number}
   * [eventSubscriptionUpdateParameters.retryPolicy.eventTimeToLiveInMinutes]
   * Time To Live (in minutes) for events.
   *
   * @param {object} [eventSubscriptionUpdateParameters.deadLetterDestination]
   * The DeadLetter destination of the event subscription.
   *
   * @param {string}
   * eventSubscriptionUpdateParameters.deadLetterDestination.endpointType
   * Polymorphic Discriminator
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscription} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscription} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  beginUpdate(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._beginUpdate(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginUpdate(scope, eventSubscriptionName, eventSubscriptionUpdateParameters, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listGlobalBySubscriptionNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listGlobalBySubscriptionNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listGlobalBySubscriptionNext(nextPageLink, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listGlobalBySubscriptionNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listGlobalBySubscriptionNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * @summary List all global event subscriptions for a topic type
   *
   * List all global event subscriptions under an Azure subscription for a topic
   * type.
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listGlobalBySubscriptionForTopicTypeNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listGlobalBySubscriptionForTopicTypeNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary List all global event subscriptions for a topic type
   *
   * List all global event subscriptions under an Azure subscription for a topic
   * type.
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listGlobalBySubscriptionForTopicTypeNext(nextPageLink, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listGlobalBySubscriptionForTopicTypeNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listGlobalBySubscriptionForTopicTypeNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listGlobalByResourceGroupNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listGlobalByResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listGlobalByResourceGroupNext(nextPageLink, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listGlobalByResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listGlobalByResourceGroupNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listGlobalByResourceGroupForTopicTypeNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listGlobalByResourceGroupForTopicTypeNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listGlobalByResourceGroupForTopicTypeNext(nextPageLink, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listGlobalByResourceGroupForTopicTypeNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listGlobalByResourceGroupForTopicTypeNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * @summary List all regional event subscriptions under an Azure subscription
   *
   * List all event subscriptions from the given location under a specific Azure
   * subscription
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listRegionalBySubscriptionNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listRegionalBySubscriptionNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary List all regional event subscriptions under an Azure subscription
   *
   * List all event subscriptions from the given location under a specific Azure
   * subscription
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listRegionalBySubscriptionNext(nextPageLink, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listRegionalBySubscriptionNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listRegionalBySubscriptionNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listRegionalByResourceGroupNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listRegionalByResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listRegionalByResourceGroupNext(nextPageLink, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listRegionalByResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listRegionalByResourceGroupNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listRegionalBySubscriptionForTopicTypeNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listRegionalBySubscriptionForTopicTypeNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listRegionalBySubscriptionForTopicTypeNext(nextPageLink, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listRegionalBySubscriptionForTopicTypeNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listRegionalBySubscriptionForTopicTypeNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listRegionalByResourceGroupForTopicTypeNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listRegionalByResourceGroupForTopicTypeNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary 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 {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listRegionalByResourceGroupForTopicTypeNext(nextPageLink, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listRegionalByResourceGroupForTopicTypeNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listRegionalByResourceGroupForTopicTypeNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * @summary List all event subscriptions for a specific topic
   *
   * List all event subscriptions that have been created for a specific topic
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByResourceNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByResourceNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary List all event subscriptions for a specific topic
   *
   * List all event subscriptions that have been created for a specific topic
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listByResourceNext(nextPageLink, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listByResourceNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByResourceNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * @summary List all event subscriptions for a specific domain topic
   *
   * List all event subscriptions that have been created for a specific domain
   * topic
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<EventSubscriptionsListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByDomainTopicNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByDomainTopicNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary List all event subscriptions for a specific domain topic
   *
   * List all event subscriptions that have been created for a specific domain
   * topic
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {EventSubscriptionsListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link EventSubscriptionsListResult} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listByDomainTopicNext(nextPageLink, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listByDomainTopicNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByDomainTopicNext(nextPageLink, options, optionalCallback);
    }
  }

}

module.exports = EventSubscriptions;
