/*
 * 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;


/**
 * Restores a backup of an API Management service created using the
 * ApiManagementService_Backup operation on the current service. This is a long
 * running operation and could take several minutes to complete.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @param {object} parameters Parameters supplied to the Restore API Management
 * service from backup operation.
 *
 * @param {string} parameters.storageAccount Azure Cloud Storage account (used
 * to place/retrieve the backup) name.
 *
 * @param {string} parameters.accessKey Azure Cloud Storage account (used to
 * place/retrieve the backup) access key.
 *
 * @param {string} parameters.containerName Azure Cloud Storage blob container
 * name used to place/retrieve the backup.
 *
 * @param {string} parameters.backupName The name of the backup file to create.
 *
 * @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 ApiManagementServiceResource} 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 _restore(resourceGroupName, serviceName, parameters, 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.beginRestore(resourceGroupName, serviceName, parameters, 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['ApiManagementServiceResource']().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);
    });
  });
}


/**
 * Creates a backup of the API Management service to the given Azure Storage
 * Account. This is long running operation and could take several minutes to
 * complete.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @param {object} parameters Parameters supplied to the
 * ApiManagementService_Backup operation.
 *
 * @param {string} parameters.storageAccount Azure Cloud Storage account (used
 * to place/retrieve the backup) name.
 *
 * @param {string} parameters.accessKey Azure Cloud Storage account (used to
 * place/retrieve the backup) access key.
 *
 * @param {string} parameters.containerName Azure Cloud Storage blob container
 * name used to place/retrieve the backup.
 *
 * @param {string} parameters.backupName The name of the backup file to create.
 *
 * @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 ApiManagementServiceResource} 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 _backup(resourceGroupName, serviceName, parameters, 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.beginBackup(resourceGroupName, serviceName, parameters, 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['ApiManagementServiceResource']().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);
    });
  });
}


/**
 * Creates or updates an API Management service. This is long running operation
 * and could take several minutes to complete.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @param {object} parameters Parameters supplied to the CreateOrUpdate API
 * Management service operation.
 *
 * @param {string} [parameters.notificationSenderEmail] Email address from
 * which the notification will be sent.
 *
 * @param {array} [parameters.hostnameConfigurations] Custom hostname
 * configuration of the API Management service.
 *
 * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
 * configuration of the API Management service.
 *
 * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
 * The full resource ID of a subnet in a virtual network to deploy the API
 * Management service in.
 *
 * @param {array} [parameters.additionalLocations] Additional datacenter
 * locations of the API Management service.
 *
 * @param {object} [parameters.customProperties] Custom properties of the API
 * Management service.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
 * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
 * and 1.2).</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
 * be used to disable just TLS 1.1.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
 * be used to disable TLS 1.0 on an API Management service.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
 * can be used to disable just TLS 1.1 for communications with
 * backends.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
 * can be used to disable TLS 1.0 for communications with backends.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
 * used to enable HTTP2 protocol on an API Management service.</br>Not
 * specifying any of these properties on PATCH operation will reset omitted
 * properties' values to their defaults. For all the settings except Http2 the
 * default value is `True` if the service was created on or before April 1st
 * 2018 and `False` otherwise. Http2 setting's default value is
 * `False`.</br></br>You can disable any of next ciphers by using settings
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
 * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
 * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
 * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
 * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
 * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
 * The default value is `true` for them.  Note: next ciphers can't be disabled
 * since they are required by Azure CloudService internal components:
 * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
 *
 * @param {array} [parameters.certificates] List of Certificates that need to
 * be installed in the API Management service. Max supported certificates that
 * can be installed is 10.
 *
 * @param {boolean} [parameters.enableClientCertificate] Property only meant to
 * be used for Consumption SKU Service. This enforces a client certificate to
 * be presented on each request to the gateway. This also enables the ability
 * to authenticate the certificate in the policy on the gateway.
 *
 * @param {boolean} [parameters.disableGateway] Property only valid for an Api
 * Management service deployed in multiple locations. This can be used to
 * disable the gateway in master region.
 *
 * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
 * Management service needs to be configured in. None (Default Value) means the
 * API Management service is not part of any Virtual Network, External means
 * the API Management deployment is set up inside a Virtual Network having an
 * Internet Facing Endpoint, and Internal means that API Management deployment
 * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
 * Possible values include: 'None', 'External', 'Internal'
 *
 * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
 * constraint for the API Management service.
 *
 * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
 * control plane API calls to API Management service with version equal to or
 * newer than this value.
 *
 * @param {string} parameters.publisherEmail Publisher email.
 *
 * @param {string} parameters.publisherName Publisher name.
 *
 * @param {object} parameters.sku SKU properties of the API Management service.
 *
 * @param {string} parameters.sku.name Name of the Sku. Possible values
 * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
 *
 * @param {number} parameters.sku.capacity Capacity of the SKU (number of
 * deployed units of the SKU). For Consumption SKU capacity must be specified
 * as 0.
 *
 * @param {object} [parameters.identity] Managed service identity of the Api
 * Management service.
 *
 * @param {string} parameters.identity.type The type of identity used for the
 * resource. The type 'SystemAssigned, UserAssigned' includes both an
 * implicitly created identity and a set of user assigned identities. The type
 * 'None' will remove any identities from the service. Possible values include:
 * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
 *
 * @param {object} [parameters.identity.userAssignedIdentities] The list of
 * user identities associated with the resource. The user identity
 * dictionary key references will be ARM resource ids in the form:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
 * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
 *
 * @param {string} parameters.location Resource location.
 *
 * @param {object} [parameters.tags] Resource tags.
 *
 * @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 ApiManagementServiceResource} 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(resourceGroupName, serviceName, parameters, 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(resourceGroupName, serviceName, parameters, 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['ApiManagementServiceResource']().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);
    });
  });
}


/**
 * Updates an existing API Management service.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @param {object} parameters Parameters supplied to the CreateOrUpdate API
 * Management service operation.
 *
 * @param {string} [parameters.notificationSenderEmail] Email address from
 * which the notification will be sent.
 *
 * @param {array} [parameters.hostnameConfigurations] Custom hostname
 * configuration of the API Management service.
 *
 * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
 * configuration of the API Management service.
 *
 * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
 * The full resource ID of a subnet in a virtual network to deploy the API
 * Management service in.
 *
 * @param {array} [parameters.additionalLocations] Additional datacenter
 * locations of the API Management service.
 *
 * @param {object} [parameters.customProperties] Custom properties of the API
 * Management service.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
 * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
 * and 1.2).</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
 * be used to disable just TLS 1.1.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
 * be used to disable TLS 1.0 on an API Management service.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
 * can be used to disable just TLS 1.1 for communications with
 * backends.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
 * can be used to disable TLS 1.0 for communications with backends.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
 * used to enable HTTP2 protocol on an API Management service.</br>Not
 * specifying any of these properties on PATCH operation will reset omitted
 * properties' values to their defaults. For all the settings except Http2 the
 * default value is `True` if the service was created on or before April 1st
 * 2018 and `False` otherwise. Http2 setting's default value is
 * `False`.</br></br>You can disable any of next ciphers by using settings
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
 * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
 * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
 * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
 * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
 * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
 * The default value is `true` for them.  Note: next ciphers can't be disabled
 * since they are required by Azure CloudService internal components:
 * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
 *
 * @param {array} [parameters.certificates] List of Certificates that need to
 * be installed in the API Management service. Max supported certificates that
 * can be installed is 10.
 *
 * @param {boolean} [parameters.enableClientCertificate] Property only meant to
 * be used for Consumption SKU Service. This enforces a client certificate to
 * be presented on each request to the gateway. This also enables the ability
 * to authenticate the certificate in the policy on the gateway.
 *
 * @param {boolean} [parameters.disableGateway] Property only valid for an Api
 * Management service deployed in multiple locations. This can be used to
 * disable the gateway in master region.
 *
 * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
 * Management service needs to be configured in. None (Default Value) means the
 * API Management service is not part of any Virtual Network, External means
 * the API Management deployment is set up inside a Virtual Network having an
 * Internet Facing Endpoint, and Internal means that API Management deployment
 * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
 * Possible values include: 'None', 'External', 'Internal'
 *
 * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
 * constraint for the API Management service.
 *
 * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
 * control plane API calls to API Management service with version equal to or
 * newer than this value.
 *
 * @param {string} [parameters.publisherEmail] Publisher email.
 *
 * @param {string} [parameters.publisherName] Publisher name.
 *
 * @param {object} [parameters.sku] SKU properties of the API Management
 * service.
 *
 * @param {string} parameters.sku.name Name of the Sku. Possible values
 * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
 *
 * @param {number} parameters.sku.capacity Capacity of the SKU (number of
 * deployed units of the SKU). For Consumption SKU capacity must be specified
 * as 0.
 *
 * @param {object} [parameters.identity] Managed service identity of the Api
 * Management service.
 *
 * @param {string} parameters.identity.type The type of identity used for the
 * resource. The type 'SystemAssigned, UserAssigned' includes both an
 * implicitly created identity and a set of user assigned identities. The type
 * 'None' will remove any identities from the service. Possible values include:
 * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
 *
 * @param {object} [parameters.identity.userAssignedIdentities] The list of
 * user identities associated with the resource. The user identity
 * dictionary key references will be ARM resource ids in the form:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
 * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
 *
 * @param {object} [parameters.tags] Resource tags.
 *
 * @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 ApiManagementServiceResource} 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(resourceGroupName, serviceName, parameters, 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(resourceGroupName, serviceName, parameters, 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['ApiManagementServiceResource']().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);
    });
  });
}

/**
 * Gets an API Management service resource description.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @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 ApiManagementServiceResource} 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(resourceGroupName, serviceName, 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 (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 (serviceName === null || serviceName === undefined || typeof serviceName.valueOf() !== 'string') {
      throw new Error('serviceName cannot be null or undefined and it must be of type string.');
    }
    if (serviceName !== null && serviceName !== undefined) {
      if (serviceName.length > 50)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MaxLength": 50');
      }
      if (serviceName.length < 1)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MinLength": 1');
      }
      if (serviceName.match(/^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/) === null)
      {
        throw new Error('"serviceName" should satisfy the constraint - "Pattern": /^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/');
      }
    }
    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.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.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.ApiManagement/service/{serviceName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serviceName}', encodeURIComponent(serviceName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ApiManagementServiceResource']().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);
  });
}


/**
 * Deletes an existing API Management service.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @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 ApiManagementServiceResource} 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 _deleteMethod(resourceGroupName, serviceName, 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(resourceGroupName, serviceName, 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['ApiManagementServiceResource']().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);
    });
  });
}

/**
 * List all API Management services within a resource group.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @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 ApiManagementServiceListResult} 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 _listByResourceGroup(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.');
  }
  // Validate
  try {
    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 (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.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.ApiManagement/service';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ApiManagementServiceListResult']().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);
  });
}

/**
 * Lists all API Management services within an Azure 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 ApiManagementServiceListResult} 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 _list(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 (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.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.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.ApiManagement/service';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  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['ApiManagementServiceListResult']().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);
  });
}

/**
 * Gets the Single-Sign-On token for the API Management Service which is valid
 * for 5 Minutes.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @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 ApiManagementServiceGetSsoTokenResult} 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 _getSsoToken(resourceGroupName, serviceName, 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 (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 (serviceName === null || serviceName === undefined || typeof serviceName.valueOf() !== 'string') {
      throw new Error('serviceName cannot be null or undefined and it must be of type string.');
    }
    if (serviceName !== null && serviceName !== undefined) {
      if (serviceName.length > 50)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MaxLength": 50');
      }
      if (serviceName.length < 1)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MinLength": 1');
      }
      if (serviceName.match(/^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/) === null)
      {
        throw new Error('"serviceName" should satisfy the constraint - "Pattern": /^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/');
      }
    }
    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.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.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.ApiManagement/service/{serviceName}/getssotoken';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serviceName}', encodeURIComponent(serviceName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ApiManagementServiceGetSsoTokenResult']().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);
  });
}

/**
 * Checks availability and correctness of a name for an API Management service.
 *
 * @param {object} parameters Parameters supplied to the CheckNameAvailability
 * operation.
 *
 * @param {string} parameters.name The name to check for availability.
 *
 * @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 ApiManagementServiceNameAvailabilityResult}
 *                      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 _checkNameAvailability(parameters, 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 (parameters === null || parameters === undefined) {
      throw new Error('parameters 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.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.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.ApiManagement/checkNameAvailability';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  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];
      }
    }
  }
  // Serialize Request
  let requestContent = null;
  let requestModel = null;
  try {
    if (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['ApiManagementServiceCheckNameAvailabilityParameters']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, 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 !== 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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ApiManagementServiceNameAvailabilityResult']().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);
  });
}


/**
 * Updates the Microsoft.ApiManagement resource running in the Virtual network
 * to pick the updated network settings.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.parameters] Parameters supplied to the Apply
 * Network Configuration operation. If the parameters are empty, all the
 * regions in which the Api Management service is deployed will be updated
 * sequentially without incurring downtime in the region.
 *
 * @param {string} [options.parameters.location] Location of the Api Management
 * service to update for a multi-region service. For a service deployed in a
 * single region, this parameter is not required.
 *
 * @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 ApiManagementServiceResource} 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 _applyNetworkConfigurationUpdates(resourceGroupName, serviceName, 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.beginApplyNetworkConfigurationUpdates(resourceGroupName, serviceName, 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['ApiManagementServiceResource']().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);
    });
  });
}

/**
 * Restores a backup of an API Management service created using the
 * ApiManagementService_Backup operation on the current service. This is a long
 * running operation and could take several minutes to complete.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @param {object} parameters Parameters supplied to the Restore API Management
 * service from backup operation.
 *
 * @param {string} parameters.storageAccount Azure Cloud Storage account (used
 * to place/retrieve the backup) name.
 *
 * @param {string} parameters.accessKey Azure Cloud Storage account (used to
 * place/retrieve the backup) access key.
 *
 * @param {string} parameters.containerName Azure Cloud Storage blob container
 * name used to place/retrieve the backup.
 *
 * @param {string} parameters.backupName The name of the backup file to create.
 *
 * @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 ApiManagementServiceResource} 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 _beginRestore(resourceGroupName, serviceName, parameters, 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 (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 (serviceName === null || serviceName === undefined || typeof serviceName.valueOf() !== 'string') {
      throw new Error('serviceName cannot be null or undefined and it must be of type string.');
    }
    if (serviceName !== null && serviceName !== undefined) {
      if (serviceName.length > 50)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MaxLength": 50');
      }
      if (serviceName.length < 1)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MinLength": 1');
      }
      if (serviceName.match(/^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/) === null)
      {
        throw new Error('"serviceName" should satisfy the constraint - "Pattern": /^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/');
      }
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters 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.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.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.ApiManagement/service/{serviceName}/restore';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serviceName}', encodeURIComponent(serviceName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  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];
      }
    }
  }
  // Serialize Request
  let requestContent = null;
  let requestModel = null;
  try {
    if (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['ApiManagementServiceBackupRestoreParameters']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, 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 !== 200 && statusCode !== 202) {
      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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ApiManagementServiceResource']().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);
  });
}

/**
 * Creates a backup of the API Management service to the given Azure Storage
 * Account. This is long running operation and could take several minutes to
 * complete.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @param {object} parameters Parameters supplied to the
 * ApiManagementService_Backup operation.
 *
 * @param {string} parameters.storageAccount Azure Cloud Storage account (used
 * to place/retrieve the backup) name.
 *
 * @param {string} parameters.accessKey Azure Cloud Storage account (used to
 * place/retrieve the backup) access key.
 *
 * @param {string} parameters.containerName Azure Cloud Storage blob container
 * name used to place/retrieve the backup.
 *
 * @param {string} parameters.backupName The name of the backup file to create.
 *
 * @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 ApiManagementServiceResource} 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 _beginBackup(resourceGroupName, serviceName, parameters, 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 (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 (serviceName === null || serviceName === undefined || typeof serviceName.valueOf() !== 'string') {
      throw new Error('serviceName cannot be null or undefined and it must be of type string.');
    }
    if (serviceName !== null && serviceName !== undefined) {
      if (serviceName.length > 50)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MaxLength": 50');
      }
      if (serviceName.length < 1)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MinLength": 1');
      }
      if (serviceName.match(/^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/) === null)
      {
        throw new Error('"serviceName" should satisfy the constraint - "Pattern": /^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/');
      }
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters 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.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.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.ApiManagement/service/{serviceName}/backup';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serviceName}', encodeURIComponent(serviceName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  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];
      }
    }
  }
  // Serialize Request
  let requestContent = null;
  let requestModel = null;
  try {
    if (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['ApiManagementServiceBackupRestoreParameters']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, 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 !== 200 && statusCode !== 202) {
      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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ApiManagementServiceResource']().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);
  });
}

/**
 * Creates or updates an API Management service. This is long running operation
 * and could take several minutes to complete.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @param {object} parameters Parameters supplied to the CreateOrUpdate API
 * Management service operation.
 *
 * @param {string} [parameters.notificationSenderEmail] Email address from
 * which the notification will be sent.
 *
 * @param {array} [parameters.hostnameConfigurations] Custom hostname
 * configuration of the API Management service.
 *
 * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
 * configuration of the API Management service.
 *
 * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
 * The full resource ID of a subnet in a virtual network to deploy the API
 * Management service in.
 *
 * @param {array} [parameters.additionalLocations] Additional datacenter
 * locations of the API Management service.
 *
 * @param {object} [parameters.customProperties] Custom properties of the API
 * Management service.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
 * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
 * and 1.2).</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
 * be used to disable just TLS 1.1.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
 * be used to disable TLS 1.0 on an API Management service.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
 * can be used to disable just TLS 1.1 for communications with
 * backends.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
 * can be used to disable TLS 1.0 for communications with backends.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
 * used to enable HTTP2 protocol on an API Management service.</br>Not
 * specifying any of these properties on PATCH operation will reset omitted
 * properties' values to their defaults. For all the settings except Http2 the
 * default value is `True` if the service was created on or before April 1st
 * 2018 and `False` otherwise. Http2 setting's default value is
 * `False`.</br></br>You can disable any of next ciphers by using settings
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
 * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
 * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
 * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
 * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
 * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
 * The default value is `true` for them.  Note: next ciphers can't be disabled
 * since they are required by Azure CloudService internal components:
 * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
 *
 * @param {array} [parameters.certificates] List of Certificates that need to
 * be installed in the API Management service. Max supported certificates that
 * can be installed is 10.
 *
 * @param {boolean} [parameters.enableClientCertificate] Property only meant to
 * be used for Consumption SKU Service. This enforces a client certificate to
 * be presented on each request to the gateway. This also enables the ability
 * to authenticate the certificate in the policy on the gateway.
 *
 * @param {boolean} [parameters.disableGateway] Property only valid for an Api
 * Management service deployed in multiple locations. This can be used to
 * disable the gateway in master region.
 *
 * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
 * Management service needs to be configured in. None (Default Value) means the
 * API Management service is not part of any Virtual Network, External means
 * the API Management deployment is set up inside a Virtual Network having an
 * Internet Facing Endpoint, and Internal means that API Management deployment
 * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
 * Possible values include: 'None', 'External', 'Internal'
 *
 * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
 * constraint for the API Management service.
 *
 * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
 * control plane API calls to API Management service with version equal to or
 * newer than this value.
 *
 * @param {string} parameters.publisherEmail Publisher email.
 *
 * @param {string} parameters.publisherName Publisher name.
 *
 * @param {object} parameters.sku SKU properties of the API Management service.
 *
 * @param {string} parameters.sku.name Name of the Sku. Possible values
 * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
 *
 * @param {number} parameters.sku.capacity Capacity of the SKU (number of
 * deployed units of the SKU). For Consumption SKU capacity must be specified
 * as 0.
 *
 * @param {object} [parameters.identity] Managed service identity of the Api
 * Management service.
 *
 * @param {string} parameters.identity.type The type of identity used for the
 * resource. The type 'SystemAssigned, UserAssigned' includes both an
 * implicitly created identity and a set of user assigned identities. The type
 * 'None' will remove any identities from the service. Possible values include:
 * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
 *
 * @param {object} [parameters.identity.userAssignedIdentities] The list of
 * user identities associated with the resource. The user identity
 * dictionary key references will be ARM resource ids in the form:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
 * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
 *
 * @param {string} parameters.location Resource location.
 *
 * @param {object} [parameters.tags] Resource tags.
 *
 * @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 ApiManagementServiceResource} 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(resourceGroupName, serviceName, parameters, 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 (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 (serviceName === null || serviceName === undefined || typeof serviceName.valueOf() !== 'string') {
      throw new Error('serviceName cannot be null or undefined and it must be of type string.');
    }
    if (serviceName !== null && serviceName !== undefined) {
      if (serviceName.length > 50)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MaxLength": 50');
      }
      if (serviceName.length < 1)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MinLength": 1');
      }
      if (serviceName.match(/^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/) === null)
      {
        throw new Error('"serviceName" should satisfy the constraint - "Pattern": /^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/');
      }
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters 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.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.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.ApiManagement/service/{serviceName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serviceName}', encodeURIComponent(serviceName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  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 (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['ApiManagementServiceResource']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, 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 !== 200 && statusCode !== 201 && statusCode !== 202) {
      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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ApiManagementServiceResource']().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);
      }
    }
    // 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['ApiManagementServiceResource']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError1 = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError1.request = msRest.stripRequest(httpRequest);
        deserializationError1.response = msRest.stripResponse(response);
        return callback(deserializationError1);
      }
    }

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

/**
 * Updates an existing API Management service.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @param {object} parameters Parameters supplied to the CreateOrUpdate API
 * Management service operation.
 *
 * @param {string} [parameters.notificationSenderEmail] Email address from
 * which the notification will be sent.
 *
 * @param {array} [parameters.hostnameConfigurations] Custom hostname
 * configuration of the API Management service.
 *
 * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
 * configuration of the API Management service.
 *
 * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
 * The full resource ID of a subnet in a virtual network to deploy the API
 * Management service in.
 *
 * @param {array} [parameters.additionalLocations] Additional datacenter
 * locations of the API Management service.
 *
 * @param {object} [parameters.customProperties] Custom properties of the API
 * Management service.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
 * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
 * and 1.2).</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
 * be used to disable just TLS 1.1.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
 * be used to disable TLS 1.0 on an API Management service.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
 * can be used to disable just TLS 1.1 for communications with
 * backends.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
 * can be used to disable TLS 1.0 for communications with backends.</br>Setting
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
 * used to enable HTTP2 protocol on an API Management service.</br>Not
 * specifying any of these properties on PATCH operation will reset omitted
 * properties' values to their defaults. For all the settings except Http2 the
 * default value is `True` if the service was created on or before April 1st
 * 2018 and `False` otherwise. Http2 setting's default value is
 * `False`.</br></br>You can disable any of next ciphers by using settings
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
 * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
 * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
 * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
 * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
 * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
 * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
 * The default value is `true` for them.  Note: next ciphers can't be disabled
 * since they are required by Azure CloudService internal components:
 * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
 *
 * @param {array} [parameters.certificates] List of Certificates that need to
 * be installed in the API Management service. Max supported certificates that
 * can be installed is 10.
 *
 * @param {boolean} [parameters.enableClientCertificate] Property only meant to
 * be used for Consumption SKU Service. This enforces a client certificate to
 * be presented on each request to the gateway. This also enables the ability
 * to authenticate the certificate in the policy on the gateway.
 *
 * @param {boolean} [parameters.disableGateway] Property only valid for an Api
 * Management service deployed in multiple locations. This can be used to
 * disable the gateway in master region.
 *
 * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
 * Management service needs to be configured in. None (Default Value) means the
 * API Management service is not part of any Virtual Network, External means
 * the API Management deployment is set up inside a Virtual Network having an
 * Internet Facing Endpoint, and Internal means that API Management deployment
 * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
 * Possible values include: 'None', 'External', 'Internal'
 *
 * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
 * constraint for the API Management service.
 *
 * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
 * control plane API calls to API Management service with version equal to or
 * newer than this value.
 *
 * @param {string} [parameters.publisherEmail] Publisher email.
 *
 * @param {string} [parameters.publisherName] Publisher name.
 *
 * @param {object} [parameters.sku] SKU properties of the API Management
 * service.
 *
 * @param {string} parameters.sku.name Name of the Sku. Possible values
 * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
 *
 * @param {number} parameters.sku.capacity Capacity of the SKU (number of
 * deployed units of the SKU). For Consumption SKU capacity must be specified
 * as 0.
 *
 * @param {object} [parameters.identity] Managed service identity of the Api
 * Management service.
 *
 * @param {string} parameters.identity.type The type of identity used for the
 * resource. The type 'SystemAssigned, UserAssigned' includes both an
 * implicitly created identity and a set of user assigned identities. The type
 * 'None' will remove any identities from the service. Possible values include:
 * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
 *
 * @param {object} [parameters.identity.userAssignedIdentities] The list of
 * user identities associated with the resource. The user identity
 * dictionary key references will be ARM resource ids in the form:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
 * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
 *
 * @param {object} [parameters.tags] Resource tags.
 *
 * @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 ApiManagementServiceResource} 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(resourceGroupName, serviceName, parameters, 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 (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 (serviceName === null || serviceName === undefined || typeof serviceName.valueOf() !== 'string') {
      throw new Error('serviceName cannot be null or undefined and it must be of type string.');
    }
    if (serviceName !== null && serviceName !== undefined) {
      if (serviceName.length > 50)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MaxLength": 50');
      }
      if (serviceName.length < 1)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MinLength": 1');
      }
      if (serviceName.match(/^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/) === null)
      {
        throw new Error('"serviceName" should satisfy the constraint - "Pattern": /^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/');
      }
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters 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.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.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.ApiManagement/service/{serviceName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serviceName}', encodeURIComponent(serviceName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  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 (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['ApiManagementServiceUpdateParameters']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, 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 !== 200 && statusCode !== 202) {
      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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ApiManagementServiceResource']().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);
  });
}

/**
 * Deletes an existing API Management service.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @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 ApiManagementServiceResource} 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 _beginDeleteMethod(resourceGroupName, serviceName, 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 (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 (serviceName === null || serviceName === undefined || typeof serviceName.valueOf() !== 'string') {
      throw new Error('serviceName cannot be null or undefined and it must be of type string.');
    }
    if (serviceName !== null && serviceName !== undefined) {
      if (serviceName.length > 50)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MaxLength": 50');
      }
      if (serviceName.length < 1)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MinLength": 1');
      }
      if (serviceName.match(/^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/) === null)
      {
        throw new Error('"serviceName" should satisfy the constraint - "Pattern": /^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/');
      }
    }
    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.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.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.ApiManagement/service/{serviceName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serviceName}', encodeURIComponent(serviceName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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 === 202) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['ApiManagementServiceResource']().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);
  });
}

/**
 * Updates the Microsoft.ApiManagement resource running in the Virtual network
 * to pick the updated network settings.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} serviceName The name of the API Management service.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.parameters] Parameters supplied to the Apply
 * Network Configuration operation. If the parameters are empty, all the
 * regions in which the Api Management service is deployed will be updated
 * sequentially without incurring downtime in the region.
 *
 * @param {string} [options.parameters.location] Location of the Api Management
 * service to update for a multi-region service. For a service deployed in a
 * single region, this parameter is not required.
 *
 * @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 ApiManagementServiceResource} 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 _beginApplyNetworkConfigurationUpdates(resourceGroupName, serviceName, 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 parameters = (options && options.parameters !== undefined) ? options.parameters : undefined;
  // Validate
  try {
    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 (serviceName === null || serviceName === undefined || typeof serviceName.valueOf() !== 'string') {
      throw new Error('serviceName cannot be null or undefined and it must be of type string.');
    }
    if (serviceName !== null && serviceName !== undefined) {
      if (serviceName.length > 50)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MaxLength": 50');
      }
      if (serviceName.length < 1)
      {
        throw new Error('"serviceName" should satisfy the constraint - "MinLength": 1');
      }
      if (serviceName.match(/^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/) === null)
      {
        throw new Error('"serviceName" should satisfy the constraint - "Pattern": /^[a-zA-Z](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?$/');
      }
    }
    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.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.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.ApiManagement/service/{serviceName}/applynetworkconfigurationupdates';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serviceName}', encodeURIComponent(serviceName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  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];
      }
    }
  }
  // Serialize Request
  let requestContent = null;
  let requestModel = null;
  try {
    if (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['ApiManagementServiceApplyNetworkConfigurationParameters']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, 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 !== 200 && statusCode !== 202) {
      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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ApiManagementServiceResource']().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);
  });
}

/**
 * List all API Management services within a 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 ApiManagementServiceListResult} 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 _listByResourceGroupNext(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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ApiManagementServiceListResult']().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);
  });
}

/**
 * Lists all API Management services within an 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 ApiManagementServiceListResult} 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 _listNext(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['ApiManagementServiceListResult']().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 ApiManagementService. */
class ApiManagementService {
  /**
   * Create a ApiManagementService.
   * @param {ApiManagementClient} client Reference to the service client.
   */
  constructor(client) {
    this.client = client;
    this._restore = _restore;
    this._backup = _backup;
    this._createOrUpdate = _createOrUpdate;
    this._update = _update;
    this._get = _get;
    this._deleteMethod = _deleteMethod;
    this._listByResourceGroup = _listByResourceGroup;
    this._list = _list;
    this._getSsoToken = _getSsoToken;
    this._checkNameAvailability = _checkNameAvailability;
    this._applyNetworkConfigurationUpdates = _applyNetworkConfigurationUpdates;
    this._beginRestore = _beginRestore;
    this._beginBackup = _beginBackup;
    this._beginCreateOrUpdate = _beginCreateOrUpdate;
    this._beginUpdate = _beginUpdate;
    this._beginDeleteMethod = _beginDeleteMethod;
    this._beginApplyNetworkConfigurationUpdates = _beginApplyNetworkConfigurationUpdates;
    this._listByResourceGroupNext = _listByResourceGroupNext;
    this._listNext = _listNext;
  }

  /**
   * Restores a backup of an API Management service created using the
   * ApiManagementService_Backup operation on the current service. This is a long
   * running operation and could take several minutes to complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the Restore API Management
   * service from backup operation.
   *
   * @param {string} parameters.storageAccount Azure Cloud Storage account (used
   * to place/retrieve the backup) name.
   *
   * @param {string} parameters.accessKey Azure Cloud Storage account (used to
   * place/retrieve the backup) access key.
   *
   * @param {string} parameters.containerName Azure Cloud Storage blob container
   * name used to place/retrieve the backup.
   *
   * @param {string} parameters.backupName The name of the backup file to create.
   *
   * @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<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  restoreWithHttpOperationResponse(resourceGroupName, serviceName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._restore(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Restores a backup of an API Management service created using the
   * ApiManagementService_Backup operation on the current service. This is a long
   * running operation and could take several minutes to complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the Restore API Management
   * service from backup operation.
   *
   * @param {string} parameters.storageAccount Azure Cloud Storage account (used
   * to place/retrieve the backup) name.
   *
   * @param {string} parameters.accessKey Azure Cloud Storage account (used to
   * place/retrieve the backup) access key.
   *
   * @param {string} parameters.containerName Azure Cloud Storage blob container
   * name used to place/retrieve the backup.
   *
   * @param {string} parameters.backupName The name of the backup file to create.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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.
   */
  restore(resourceGroupName, serviceName, parameters, 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._restore(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._restore(resourceGroupName, serviceName, parameters, options, optionalCallback);
    }
  }

  /**
   * Creates a backup of the API Management service to the given Azure Storage
   * Account. This is long running operation and could take several minutes to
   * complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the
   * ApiManagementService_Backup operation.
   *
   * @param {string} parameters.storageAccount Azure Cloud Storage account (used
   * to place/retrieve the backup) name.
   *
   * @param {string} parameters.accessKey Azure Cloud Storage account (used to
   * place/retrieve the backup) access key.
   *
   * @param {string} parameters.containerName Azure Cloud Storage blob container
   * name used to place/retrieve the backup.
   *
   * @param {string} parameters.backupName The name of the backup file to create.
   *
   * @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<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  backupWithHttpOperationResponse(resourceGroupName, serviceName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._backup(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates a backup of the API Management service to the given Azure Storage
   * Account. This is long running operation and could take several minutes to
   * complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the
   * ApiManagementService_Backup operation.
   *
   * @param {string} parameters.storageAccount Azure Cloud Storage account (used
   * to place/retrieve the backup) name.
   *
   * @param {string} parameters.accessKey Azure Cloud Storage account (used to
   * place/retrieve the backup) access key.
   *
   * @param {string} parameters.containerName Azure Cloud Storage blob container
   * name used to place/retrieve the backup.
   *
   * @param {string} parameters.backupName The name of the backup file to create.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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.
   */
  backup(resourceGroupName, serviceName, parameters, 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._backup(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._backup(resourceGroupName, serviceName, parameters, options, optionalCallback);
    }
  }

  /**
   * Creates or updates an API Management service. This is long running operation
   * and could take several minutes to complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the CreateOrUpdate API
   * Management service operation.
   *
   * @param {string} [parameters.notificationSenderEmail] Email address from
   * which the notification will be sent.
   *
   * @param {array} [parameters.hostnameConfigurations] Custom hostname
   * configuration of the API Management service.
   *
   * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
   * configuration of the API Management service.
   *
   * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
   * The full resource ID of a subnet in a virtual network to deploy the API
   * Management service in.
   *
   * @param {array} [parameters.additionalLocations] Additional datacenter
   * locations of the API Management service.
   *
   * @param {object} [parameters.customProperties] Custom properties of the API
   * Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
   * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
   * and 1.2).</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
   * be used to disable just TLS 1.1.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
   * be used to disable TLS 1.0 on an API Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
   * can be used to disable just TLS 1.1 for communications with
   * backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
   * can be used to disable TLS 1.0 for communications with backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
   * used to enable HTTP2 protocol on an API Management service.</br>Not
   * specifying any of these properties on PATCH operation will reset omitted
   * properties' values to their defaults. For all the settings except Http2 the
   * default value is `True` if the service was created on or before April 1st
   * 2018 and `False` otherwise. Http2 setting's default value is
   * `False`.</br></br>You can disable any of next ciphers by using settings
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
   * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
   * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
   * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
   * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
   * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
   * The default value is `true` for them.  Note: next ciphers can't be disabled
   * since they are required by Azure CloudService internal components:
   * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
   *
   * @param {array} [parameters.certificates] List of Certificates that need to
   * be installed in the API Management service. Max supported certificates that
   * can be installed is 10.
   *
   * @param {boolean} [parameters.enableClientCertificate] Property only meant to
   * be used for Consumption SKU Service. This enforces a client certificate to
   * be presented on each request to the gateway. This also enables the ability
   * to authenticate the certificate in the policy on the gateway.
   *
   * @param {boolean} [parameters.disableGateway] Property only valid for an Api
   * Management service deployed in multiple locations. This can be used to
   * disable the gateway in master region.
   *
   * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
   * Management service needs to be configured in. None (Default Value) means the
   * API Management service is not part of any Virtual Network, External means
   * the API Management deployment is set up inside a Virtual Network having an
   * Internet Facing Endpoint, and Internal means that API Management deployment
   * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
   * Possible values include: 'None', 'External', 'Internal'
   *
   * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
   * constraint for the API Management service.
   *
   * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
   * control plane API calls to API Management service with version equal to or
   * newer than this value.
   *
   * @param {string} parameters.publisherEmail Publisher email.
   *
   * @param {string} parameters.publisherName Publisher name.
   *
   * @param {object} parameters.sku SKU properties of the API Management service.
   *
   * @param {string} parameters.sku.name Name of the Sku. Possible values
   * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
   *
   * @param {number} parameters.sku.capacity Capacity of the SKU (number of
   * deployed units of the SKU). For Consumption SKU capacity must be specified
   * as 0.
   *
   * @param {object} [parameters.identity] Managed service identity of the Api
   * Management service.
   *
   * @param {string} parameters.identity.type The type of identity used for the
   * resource. The type 'SystemAssigned, UserAssigned' includes both an
   * implicitly created identity and a set of user assigned identities. The type
   * 'None' will remove any identities from the service. Possible values include:
   * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
   *
   * @param {object} [parameters.identity.userAssignedIdentities] The list of
   * user identities associated with the resource. The user identity
   * dictionary key references will be ARM resource ids in the form:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
   * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
   *
   * @param {string} parameters.location Resource location.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createOrUpdateWithHttpOperationResponse(resourceGroupName, serviceName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._createOrUpdate(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates or updates an API Management service. This is long running operation
   * and could take several minutes to complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the CreateOrUpdate API
   * Management service operation.
   *
   * @param {string} [parameters.notificationSenderEmail] Email address from
   * which the notification will be sent.
   *
   * @param {array} [parameters.hostnameConfigurations] Custom hostname
   * configuration of the API Management service.
   *
   * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
   * configuration of the API Management service.
   *
   * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
   * The full resource ID of a subnet in a virtual network to deploy the API
   * Management service in.
   *
   * @param {array} [parameters.additionalLocations] Additional datacenter
   * locations of the API Management service.
   *
   * @param {object} [parameters.customProperties] Custom properties of the API
   * Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
   * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
   * and 1.2).</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
   * be used to disable just TLS 1.1.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
   * be used to disable TLS 1.0 on an API Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
   * can be used to disable just TLS 1.1 for communications with
   * backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
   * can be used to disable TLS 1.0 for communications with backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
   * used to enable HTTP2 protocol on an API Management service.</br>Not
   * specifying any of these properties on PATCH operation will reset omitted
   * properties' values to their defaults. For all the settings except Http2 the
   * default value is `True` if the service was created on or before April 1st
   * 2018 and `False` otherwise. Http2 setting's default value is
   * `False`.</br></br>You can disable any of next ciphers by using settings
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
   * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
   * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
   * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
   * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
   * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
   * The default value is `true` for them.  Note: next ciphers can't be disabled
   * since they are required by Azure CloudService internal components:
   * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
   *
   * @param {array} [parameters.certificates] List of Certificates that need to
   * be installed in the API Management service. Max supported certificates that
   * can be installed is 10.
   *
   * @param {boolean} [parameters.enableClientCertificate] Property only meant to
   * be used for Consumption SKU Service. This enforces a client certificate to
   * be presented on each request to the gateway. This also enables the ability
   * to authenticate the certificate in the policy on the gateway.
   *
   * @param {boolean} [parameters.disableGateway] Property only valid for an Api
   * Management service deployed in multiple locations. This can be used to
   * disable the gateway in master region.
   *
   * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
   * Management service needs to be configured in. None (Default Value) means the
   * API Management service is not part of any Virtual Network, External means
   * the API Management deployment is set up inside a Virtual Network having an
   * Internet Facing Endpoint, and Internal means that API Management deployment
   * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
   * Possible values include: 'None', 'External', 'Internal'
   *
   * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
   * constraint for the API Management service.
   *
   * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
   * control plane API calls to API Management service with version equal to or
   * newer than this value.
   *
   * @param {string} parameters.publisherEmail Publisher email.
   *
   * @param {string} parameters.publisherName Publisher name.
   *
   * @param {object} parameters.sku SKU properties of the API Management service.
   *
   * @param {string} parameters.sku.name Name of the Sku. Possible values
   * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
   *
   * @param {number} parameters.sku.capacity Capacity of the SKU (number of
   * deployed units of the SKU). For Consumption SKU capacity must be specified
   * as 0.
   *
   * @param {object} [parameters.identity] Managed service identity of the Api
   * Management service.
   *
   * @param {string} parameters.identity.type The type of identity used for the
   * resource. The type 'SystemAssigned, UserAssigned' includes both an
   * implicitly created identity and a set of user assigned identities. The type
   * 'None' will remove any identities from the service. Possible values include:
   * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
   *
   * @param {object} [parameters.identity.userAssignedIdentities] The list of
   * user identities associated with the resource. The user identity
   * dictionary key references will be ARM resource ids in the form:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
   * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
   *
   * @param {string} parameters.location Resource location.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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(resourceGroupName, serviceName, parameters, 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(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._createOrUpdate(resourceGroupName, serviceName, parameters, options, optionalCallback);
    }
  }

  /**
   * Updates an existing API Management service.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the CreateOrUpdate API
   * Management service operation.
   *
   * @param {string} [parameters.notificationSenderEmail] Email address from
   * which the notification will be sent.
   *
   * @param {array} [parameters.hostnameConfigurations] Custom hostname
   * configuration of the API Management service.
   *
   * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
   * configuration of the API Management service.
   *
   * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
   * The full resource ID of a subnet in a virtual network to deploy the API
   * Management service in.
   *
   * @param {array} [parameters.additionalLocations] Additional datacenter
   * locations of the API Management service.
   *
   * @param {object} [parameters.customProperties] Custom properties of the API
   * Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
   * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
   * and 1.2).</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
   * be used to disable just TLS 1.1.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
   * be used to disable TLS 1.0 on an API Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
   * can be used to disable just TLS 1.1 for communications with
   * backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
   * can be used to disable TLS 1.0 for communications with backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
   * used to enable HTTP2 protocol on an API Management service.</br>Not
   * specifying any of these properties on PATCH operation will reset omitted
   * properties' values to their defaults. For all the settings except Http2 the
   * default value is `True` if the service was created on or before April 1st
   * 2018 and `False` otherwise. Http2 setting's default value is
   * `False`.</br></br>You can disable any of next ciphers by using settings
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
   * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
   * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
   * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
   * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
   * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
   * The default value is `true` for them.  Note: next ciphers can't be disabled
   * since they are required by Azure CloudService internal components:
   * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
   *
   * @param {array} [parameters.certificates] List of Certificates that need to
   * be installed in the API Management service. Max supported certificates that
   * can be installed is 10.
   *
   * @param {boolean} [parameters.enableClientCertificate] Property only meant to
   * be used for Consumption SKU Service. This enforces a client certificate to
   * be presented on each request to the gateway. This also enables the ability
   * to authenticate the certificate in the policy on the gateway.
   *
   * @param {boolean} [parameters.disableGateway] Property only valid for an Api
   * Management service deployed in multiple locations. This can be used to
   * disable the gateway in master region.
   *
   * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
   * Management service needs to be configured in. None (Default Value) means the
   * API Management service is not part of any Virtual Network, External means
   * the API Management deployment is set up inside a Virtual Network having an
   * Internet Facing Endpoint, and Internal means that API Management deployment
   * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
   * Possible values include: 'None', 'External', 'Internal'
   *
   * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
   * constraint for the API Management service.
   *
   * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
   * control plane API calls to API Management service with version equal to or
   * newer than this value.
   *
   * @param {string} [parameters.publisherEmail] Publisher email.
   *
   * @param {string} [parameters.publisherName] Publisher name.
   *
   * @param {object} [parameters.sku] SKU properties of the API Management
   * service.
   *
   * @param {string} parameters.sku.name Name of the Sku. Possible values
   * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
   *
   * @param {number} parameters.sku.capacity Capacity of the SKU (number of
   * deployed units of the SKU). For Consumption SKU capacity must be specified
   * as 0.
   *
   * @param {object} [parameters.identity] Managed service identity of the Api
   * Management service.
   *
   * @param {string} parameters.identity.type The type of identity used for the
   * resource. The type 'SystemAssigned, UserAssigned' includes both an
   * implicitly created identity and a set of user assigned identities. The type
   * 'None' will remove any identities from the service. Possible values include:
   * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
   *
   * @param {object} [parameters.identity.userAssignedIdentities] The list of
   * user identities associated with the resource. The user identity
   * dictionary key references will be ARM resource ids in the form:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
   * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  updateWithHttpOperationResponse(resourceGroupName, serviceName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._update(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Updates an existing API Management service.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the CreateOrUpdate API
   * Management service operation.
   *
   * @param {string} [parameters.notificationSenderEmail] Email address from
   * which the notification will be sent.
   *
   * @param {array} [parameters.hostnameConfigurations] Custom hostname
   * configuration of the API Management service.
   *
   * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
   * configuration of the API Management service.
   *
   * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
   * The full resource ID of a subnet in a virtual network to deploy the API
   * Management service in.
   *
   * @param {array} [parameters.additionalLocations] Additional datacenter
   * locations of the API Management service.
   *
   * @param {object} [parameters.customProperties] Custom properties of the API
   * Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
   * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
   * and 1.2).</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
   * be used to disable just TLS 1.1.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
   * be used to disable TLS 1.0 on an API Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
   * can be used to disable just TLS 1.1 for communications with
   * backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
   * can be used to disable TLS 1.0 for communications with backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
   * used to enable HTTP2 protocol on an API Management service.</br>Not
   * specifying any of these properties on PATCH operation will reset omitted
   * properties' values to their defaults. For all the settings except Http2 the
   * default value is `True` if the service was created on or before April 1st
   * 2018 and `False` otherwise. Http2 setting's default value is
   * `False`.</br></br>You can disable any of next ciphers by using settings
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
   * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
   * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
   * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
   * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
   * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
   * The default value is `true` for them.  Note: next ciphers can't be disabled
   * since they are required by Azure CloudService internal components:
   * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
   *
   * @param {array} [parameters.certificates] List of Certificates that need to
   * be installed in the API Management service. Max supported certificates that
   * can be installed is 10.
   *
   * @param {boolean} [parameters.enableClientCertificate] Property only meant to
   * be used for Consumption SKU Service. This enforces a client certificate to
   * be presented on each request to the gateway. This also enables the ability
   * to authenticate the certificate in the policy on the gateway.
   *
   * @param {boolean} [parameters.disableGateway] Property only valid for an Api
   * Management service deployed in multiple locations. This can be used to
   * disable the gateway in master region.
   *
   * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
   * Management service needs to be configured in. None (Default Value) means the
   * API Management service is not part of any Virtual Network, External means
   * the API Management deployment is set up inside a Virtual Network having an
   * Internet Facing Endpoint, and Internal means that API Management deployment
   * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
   * Possible values include: 'None', 'External', 'Internal'
   *
   * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
   * constraint for the API Management service.
   *
   * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
   * control plane API calls to API Management service with version equal to or
   * newer than this value.
   *
   * @param {string} [parameters.publisherEmail] Publisher email.
   *
   * @param {string} [parameters.publisherName] Publisher name.
   *
   * @param {object} [parameters.sku] SKU properties of the API Management
   * service.
   *
   * @param {string} parameters.sku.name Name of the Sku. Possible values
   * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
   *
   * @param {number} parameters.sku.capacity Capacity of the SKU (number of
   * deployed units of the SKU). For Consumption SKU capacity must be specified
   * as 0.
   *
   * @param {object} [parameters.identity] Managed service identity of the Api
   * Management service.
   *
   * @param {string} parameters.identity.type The type of identity used for the
   * resource. The type 'SystemAssigned, UserAssigned' includes both an
   * implicitly created identity and a set of user assigned identities. The type
   * 'None' will remove any identities from the service. Possible values include:
   * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
   *
   * @param {object} [parameters.identity.userAssignedIdentities] The list of
   * user identities associated with the resource. The user identity
   * dictionary key references will be ARM resource ids in the form:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
   * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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(resourceGroupName, serviceName, parameters, 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(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._update(resourceGroupName, serviceName, parameters, options, optionalCallback);
    }
  }

  /**
   * Gets an API Management service resource description.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @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<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getWithHttpOperationResponse(resourceGroupName, serviceName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._get(resourceGroupName, serviceName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets an API Management service resource description.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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(resourceGroupName, serviceName, 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(resourceGroupName, serviceName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._get(resourceGroupName, serviceName, options, optionalCallback);
    }
  }

  /**
   * Deletes an existing API Management service.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @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<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  deleteMethodWithHttpOperationResponse(resourceGroupName, serviceName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._deleteMethod(resourceGroupName, serviceName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Deletes an existing API Management service.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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.
   */
  deleteMethod(resourceGroupName, serviceName, 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(resourceGroupName, serviceName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._deleteMethod(resourceGroupName, serviceName, options, optionalCallback);
    }
  }

  /**
   * List all API Management services within a resource group.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @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<ApiManagementServiceListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByResourceGroupWithHttpOperationResponse(resourceGroupName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByResourceGroup(resourceGroupName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * List all API Management services within a resource group.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @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 {ApiManagementServiceListResult} - 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 ApiManagementServiceListResult} 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.
   */
  listByResourceGroup(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._listByResourceGroup(resourceGroupName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByResourceGroup(resourceGroupName, options, optionalCallback);
    }
  }

  /**
   * Lists all API Management services within an Azure 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<ApiManagementServiceListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listWithHttpOperationResponse(options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._list(options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Lists all API Management services within an Azure 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 {ApiManagementServiceListResult} - 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 ApiManagementServiceListResult} 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.
   */
  list(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._list(options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._list(options, optionalCallback);
    }
  }

  /**
   * Gets the Single-Sign-On token for the API Management Service which is valid
   * for 5 Minutes.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @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<ApiManagementServiceGetSsoTokenResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getSsoTokenWithHttpOperationResponse(resourceGroupName, serviceName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._getSsoToken(resourceGroupName, serviceName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets the Single-Sign-On token for the API Management Service which is valid
   * for 5 Minutes.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @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 {ApiManagementServiceGetSsoTokenResult} - 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 ApiManagementServiceGetSsoTokenResult} 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.
   */
  getSsoToken(resourceGroupName, serviceName, 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._getSsoToken(resourceGroupName, serviceName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._getSsoToken(resourceGroupName, serviceName, options, optionalCallback);
    }
  }

  /**
   * Checks availability and correctness of a name for an API Management service.
   *
   * @param {object} parameters Parameters supplied to the CheckNameAvailability
   * operation.
   *
   * @param {string} parameters.name The name to check for availability.
   *
   * @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<ApiManagementServiceNameAvailabilityResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  checkNameAvailabilityWithHttpOperationResponse(parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._checkNameAvailability(parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Checks availability and correctness of a name for an API Management service.
   *
   * @param {object} parameters Parameters supplied to the CheckNameAvailability
   * operation.
   *
   * @param {string} parameters.name The name to check for availability.
   *
   * @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 {ApiManagementServiceNameAvailabilityResult} - 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 ApiManagementServiceNameAvailabilityResult}
   *                      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.
   */
  checkNameAvailability(parameters, 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._checkNameAvailability(parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._checkNameAvailability(parameters, options, optionalCallback);
    }
  }

  /**
   * Updates the Microsoft.ApiManagement resource running in the Virtual network
   * to pick the updated network settings.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.parameters] Parameters supplied to the Apply
   * Network Configuration operation. If the parameters are empty, all the
   * regions in which the Api Management service is deployed will be updated
   * sequentially without incurring downtime in the region.
   *
   * @param {string} [options.parameters.location] Location of the Api Management
   * service to update for a multi-region service. For a service deployed in a
   * single region, this parameter is not required.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  applyNetworkConfigurationUpdatesWithHttpOperationResponse(resourceGroupName, serviceName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._applyNetworkConfigurationUpdates(resourceGroupName, serviceName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Updates the Microsoft.ApiManagement resource running in the Virtual network
   * to pick the updated network settings.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.parameters] Parameters supplied to the Apply
   * Network Configuration operation. If the parameters are empty, all the
   * regions in which the Api Management service is deployed will be updated
   * sequentially without incurring downtime in the region.
   *
   * @param {string} [options.parameters.location] Location of the Api Management
   * service to update for a multi-region service. For a service deployed in a
   * single region, this parameter is not required.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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.
   */
  applyNetworkConfigurationUpdates(resourceGroupName, serviceName, 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._applyNetworkConfigurationUpdates(resourceGroupName, serviceName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._applyNetworkConfigurationUpdates(resourceGroupName, serviceName, options, optionalCallback);
    }
  }

  /**
   * Restores a backup of an API Management service created using the
   * ApiManagementService_Backup operation on the current service. This is a long
   * running operation and could take several minutes to complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the Restore API Management
   * service from backup operation.
   *
   * @param {string} parameters.storageAccount Azure Cloud Storage account (used
   * to place/retrieve the backup) name.
   *
   * @param {string} parameters.accessKey Azure Cloud Storage account (used to
   * place/retrieve the backup) access key.
   *
   * @param {string} parameters.containerName Azure Cloud Storage blob container
   * name used to place/retrieve the backup.
   *
   * @param {string} parameters.backupName The name of the backup file to create.
   *
   * @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<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginRestoreWithHttpOperationResponse(resourceGroupName, serviceName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginRestore(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Restores a backup of an API Management service created using the
   * ApiManagementService_Backup operation on the current service. This is a long
   * running operation and could take several minutes to complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the Restore API Management
   * service from backup operation.
   *
   * @param {string} parameters.storageAccount Azure Cloud Storage account (used
   * to place/retrieve the backup) name.
   *
   * @param {string} parameters.accessKey Azure Cloud Storage account (used to
   * place/retrieve the backup) access key.
   *
   * @param {string} parameters.containerName Azure Cloud Storage blob container
   * name used to place/retrieve the backup.
   *
   * @param {string} parameters.backupName The name of the backup file to create.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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.
   */
  beginRestore(resourceGroupName, serviceName, parameters, 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._beginRestore(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginRestore(resourceGroupName, serviceName, parameters, options, optionalCallback);
    }
  }

  /**
   * Creates a backup of the API Management service to the given Azure Storage
   * Account. This is long running operation and could take several minutes to
   * complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the
   * ApiManagementService_Backup operation.
   *
   * @param {string} parameters.storageAccount Azure Cloud Storage account (used
   * to place/retrieve the backup) name.
   *
   * @param {string} parameters.accessKey Azure Cloud Storage account (used to
   * place/retrieve the backup) access key.
   *
   * @param {string} parameters.containerName Azure Cloud Storage blob container
   * name used to place/retrieve the backup.
   *
   * @param {string} parameters.backupName The name of the backup file to create.
   *
   * @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<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginBackupWithHttpOperationResponse(resourceGroupName, serviceName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginBackup(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates a backup of the API Management service to the given Azure Storage
   * Account. This is long running operation and could take several minutes to
   * complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the
   * ApiManagementService_Backup operation.
   *
   * @param {string} parameters.storageAccount Azure Cloud Storage account (used
   * to place/retrieve the backup) name.
   *
   * @param {string} parameters.accessKey Azure Cloud Storage account (used to
   * place/retrieve the backup) access key.
   *
   * @param {string} parameters.containerName Azure Cloud Storage blob container
   * name used to place/retrieve the backup.
   *
   * @param {string} parameters.backupName The name of the backup file to create.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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.
   */
  beginBackup(resourceGroupName, serviceName, parameters, 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._beginBackup(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginBackup(resourceGroupName, serviceName, parameters, options, optionalCallback);
    }
  }

  /**
   * Creates or updates an API Management service. This is long running operation
   * and could take several minutes to complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the CreateOrUpdate API
   * Management service operation.
   *
   * @param {string} [parameters.notificationSenderEmail] Email address from
   * which the notification will be sent.
   *
   * @param {array} [parameters.hostnameConfigurations] Custom hostname
   * configuration of the API Management service.
   *
   * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
   * configuration of the API Management service.
   *
   * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
   * The full resource ID of a subnet in a virtual network to deploy the API
   * Management service in.
   *
   * @param {array} [parameters.additionalLocations] Additional datacenter
   * locations of the API Management service.
   *
   * @param {object} [parameters.customProperties] Custom properties of the API
   * Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
   * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
   * and 1.2).</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
   * be used to disable just TLS 1.1.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
   * be used to disable TLS 1.0 on an API Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
   * can be used to disable just TLS 1.1 for communications with
   * backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
   * can be used to disable TLS 1.0 for communications with backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
   * used to enable HTTP2 protocol on an API Management service.</br>Not
   * specifying any of these properties on PATCH operation will reset omitted
   * properties' values to their defaults. For all the settings except Http2 the
   * default value is `True` if the service was created on or before April 1st
   * 2018 and `False` otherwise. Http2 setting's default value is
   * `False`.</br></br>You can disable any of next ciphers by using settings
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
   * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
   * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
   * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
   * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
   * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
   * The default value is `true` for them.  Note: next ciphers can't be disabled
   * since they are required by Azure CloudService internal components:
   * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
   *
   * @param {array} [parameters.certificates] List of Certificates that need to
   * be installed in the API Management service. Max supported certificates that
   * can be installed is 10.
   *
   * @param {boolean} [parameters.enableClientCertificate] Property only meant to
   * be used for Consumption SKU Service. This enforces a client certificate to
   * be presented on each request to the gateway. This also enables the ability
   * to authenticate the certificate in the policy on the gateway.
   *
   * @param {boolean} [parameters.disableGateway] Property only valid for an Api
   * Management service deployed in multiple locations. This can be used to
   * disable the gateway in master region.
   *
   * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
   * Management service needs to be configured in. None (Default Value) means the
   * API Management service is not part of any Virtual Network, External means
   * the API Management deployment is set up inside a Virtual Network having an
   * Internet Facing Endpoint, and Internal means that API Management deployment
   * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
   * Possible values include: 'None', 'External', 'Internal'
   *
   * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
   * constraint for the API Management service.
   *
   * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
   * control plane API calls to API Management service with version equal to or
   * newer than this value.
   *
   * @param {string} parameters.publisherEmail Publisher email.
   *
   * @param {string} parameters.publisherName Publisher name.
   *
   * @param {object} parameters.sku SKU properties of the API Management service.
   *
   * @param {string} parameters.sku.name Name of the Sku. Possible values
   * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
   *
   * @param {number} parameters.sku.capacity Capacity of the SKU (number of
   * deployed units of the SKU). For Consumption SKU capacity must be specified
   * as 0.
   *
   * @param {object} [parameters.identity] Managed service identity of the Api
   * Management service.
   *
   * @param {string} parameters.identity.type The type of identity used for the
   * resource. The type 'SystemAssigned, UserAssigned' includes both an
   * implicitly created identity and a set of user assigned identities. The type
   * 'None' will remove any identities from the service. Possible values include:
   * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
   *
   * @param {object} [parameters.identity.userAssignedIdentities] The list of
   * user identities associated with the resource. The user identity
   * dictionary key references will be ARM resource ids in the form:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
   * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
   *
   * @param {string} parameters.location Resource location.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginCreateOrUpdateWithHttpOperationResponse(resourceGroupName, serviceName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginCreateOrUpdate(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates or updates an API Management service. This is long running operation
   * and could take several minutes to complete.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the CreateOrUpdate API
   * Management service operation.
   *
   * @param {string} [parameters.notificationSenderEmail] Email address from
   * which the notification will be sent.
   *
   * @param {array} [parameters.hostnameConfigurations] Custom hostname
   * configuration of the API Management service.
   *
   * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
   * configuration of the API Management service.
   *
   * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
   * The full resource ID of a subnet in a virtual network to deploy the API
   * Management service in.
   *
   * @param {array} [parameters.additionalLocations] Additional datacenter
   * locations of the API Management service.
   *
   * @param {object} [parameters.customProperties] Custom properties of the API
   * Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
   * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
   * and 1.2).</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
   * be used to disable just TLS 1.1.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
   * be used to disable TLS 1.0 on an API Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
   * can be used to disable just TLS 1.1 for communications with
   * backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
   * can be used to disable TLS 1.0 for communications with backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
   * used to enable HTTP2 protocol on an API Management service.</br>Not
   * specifying any of these properties on PATCH operation will reset omitted
   * properties' values to their defaults. For all the settings except Http2 the
   * default value is `True` if the service was created on or before April 1st
   * 2018 and `False` otherwise. Http2 setting's default value is
   * `False`.</br></br>You can disable any of next ciphers by using settings
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
   * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
   * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
   * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
   * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
   * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
   * The default value is `true` for them.  Note: next ciphers can't be disabled
   * since they are required by Azure CloudService internal components:
   * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
   *
   * @param {array} [parameters.certificates] List of Certificates that need to
   * be installed in the API Management service. Max supported certificates that
   * can be installed is 10.
   *
   * @param {boolean} [parameters.enableClientCertificate] Property only meant to
   * be used for Consumption SKU Service. This enforces a client certificate to
   * be presented on each request to the gateway. This also enables the ability
   * to authenticate the certificate in the policy on the gateway.
   *
   * @param {boolean} [parameters.disableGateway] Property only valid for an Api
   * Management service deployed in multiple locations. This can be used to
   * disable the gateway in master region.
   *
   * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
   * Management service needs to be configured in. None (Default Value) means the
   * API Management service is not part of any Virtual Network, External means
   * the API Management deployment is set up inside a Virtual Network having an
   * Internet Facing Endpoint, and Internal means that API Management deployment
   * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
   * Possible values include: 'None', 'External', 'Internal'
   *
   * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
   * constraint for the API Management service.
   *
   * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
   * control plane API calls to API Management service with version equal to or
   * newer than this value.
   *
   * @param {string} parameters.publisherEmail Publisher email.
   *
   * @param {string} parameters.publisherName Publisher name.
   *
   * @param {object} parameters.sku SKU properties of the API Management service.
   *
   * @param {string} parameters.sku.name Name of the Sku. Possible values
   * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
   *
   * @param {number} parameters.sku.capacity Capacity of the SKU (number of
   * deployed units of the SKU). For Consumption SKU capacity must be specified
   * as 0.
   *
   * @param {object} [parameters.identity] Managed service identity of the Api
   * Management service.
   *
   * @param {string} parameters.identity.type The type of identity used for the
   * resource. The type 'SystemAssigned, UserAssigned' includes both an
   * implicitly created identity and a set of user assigned identities. The type
   * 'None' will remove any identities from the service. Possible values include:
   * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
   *
   * @param {object} [parameters.identity.userAssignedIdentities] The list of
   * user identities associated with the resource. The user identity
   * dictionary key references will be ARM resource ids in the form:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
   * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
   *
   * @param {string} parameters.location Resource location.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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(resourceGroupName, serviceName, parameters, 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(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginCreateOrUpdate(resourceGroupName, serviceName, parameters, options, optionalCallback);
    }
  }

  /**
   * Updates an existing API Management service.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the CreateOrUpdate API
   * Management service operation.
   *
   * @param {string} [parameters.notificationSenderEmail] Email address from
   * which the notification will be sent.
   *
   * @param {array} [parameters.hostnameConfigurations] Custom hostname
   * configuration of the API Management service.
   *
   * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
   * configuration of the API Management service.
   *
   * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
   * The full resource ID of a subnet in a virtual network to deploy the API
   * Management service in.
   *
   * @param {array} [parameters.additionalLocations] Additional datacenter
   * locations of the API Management service.
   *
   * @param {object} [parameters.customProperties] Custom properties of the API
   * Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
   * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
   * and 1.2).</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
   * be used to disable just TLS 1.1.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
   * be used to disable TLS 1.0 on an API Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
   * can be used to disable just TLS 1.1 for communications with
   * backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
   * can be used to disable TLS 1.0 for communications with backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
   * used to enable HTTP2 protocol on an API Management service.</br>Not
   * specifying any of these properties on PATCH operation will reset omitted
   * properties' values to their defaults. For all the settings except Http2 the
   * default value is `True` if the service was created on or before April 1st
   * 2018 and `False` otherwise. Http2 setting's default value is
   * `False`.</br></br>You can disable any of next ciphers by using settings
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
   * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
   * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
   * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
   * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
   * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
   * The default value is `true` for them.  Note: next ciphers can't be disabled
   * since they are required by Azure CloudService internal components:
   * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
   *
   * @param {array} [parameters.certificates] List of Certificates that need to
   * be installed in the API Management service. Max supported certificates that
   * can be installed is 10.
   *
   * @param {boolean} [parameters.enableClientCertificate] Property only meant to
   * be used for Consumption SKU Service. This enforces a client certificate to
   * be presented on each request to the gateway. This also enables the ability
   * to authenticate the certificate in the policy on the gateway.
   *
   * @param {boolean} [parameters.disableGateway] Property only valid for an Api
   * Management service deployed in multiple locations. This can be used to
   * disable the gateway in master region.
   *
   * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
   * Management service needs to be configured in. None (Default Value) means the
   * API Management service is not part of any Virtual Network, External means
   * the API Management deployment is set up inside a Virtual Network having an
   * Internet Facing Endpoint, and Internal means that API Management deployment
   * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
   * Possible values include: 'None', 'External', 'Internal'
   *
   * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
   * constraint for the API Management service.
   *
   * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
   * control plane API calls to API Management service with version equal to or
   * newer than this value.
   *
   * @param {string} [parameters.publisherEmail] Publisher email.
   *
   * @param {string} [parameters.publisherName] Publisher name.
   *
   * @param {object} [parameters.sku] SKU properties of the API Management
   * service.
   *
   * @param {string} parameters.sku.name Name of the Sku. Possible values
   * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
   *
   * @param {number} parameters.sku.capacity Capacity of the SKU (number of
   * deployed units of the SKU). For Consumption SKU capacity must be specified
   * as 0.
   *
   * @param {object} [parameters.identity] Managed service identity of the Api
   * Management service.
   *
   * @param {string} parameters.identity.type The type of identity used for the
   * resource. The type 'SystemAssigned, UserAssigned' includes both an
   * implicitly created identity and a set of user assigned identities. The type
   * 'None' will remove any identities from the service. Possible values include:
   * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
   *
   * @param {object} [parameters.identity.userAssignedIdentities] The list of
   * user identities associated with the resource. The user identity
   * dictionary key references will be ARM resource ids in the form:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
   * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginUpdateWithHttpOperationResponse(resourceGroupName, serviceName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginUpdate(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Updates an existing API Management service.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} parameters Parameters supplied to the CreateOrUpdate API
   * Management service operation.
   *
   * @param {string} [parameters.notificationSenderEmail] Email address from
   * which the notification will be sent.
   *
   * @param {array} [parameters.hostnameConfigurations] Custom hostname
   * configuration of the API Management service.
   *
   * @param {object} [parameters.virtualNetworkConfiguration] Virtual network
   * configuration of the API Management service.
   *
   * @param {string} [parameters.virtualNetworkConfiguration.subnetResourceId]
   * The full resource ID of a subnet in a virtual network to deploy the API
   * Management service in.
   *
   * @param {array} [parameters.additionalLocations] Additional datacenter
   * locations of the API Management service.
   *
   * @param {object} [parameters.customProperties] Custom properties of the API
   * Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TripleDes168`
   * will disable the cipher TLS_RSA_WITH_3DES_EDE_CBC_SHA for all TLS(1.0, 1.1
   * and 1.2).</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls11` can
   * be used to disable just TLS 1.1.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Protocols.Tls10` can
   * be used to disable TLS 1.0 on an API Management service.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls11`
   * can be used to disable just TLS 1.1 for communications with
   * backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Backend.Protocols.Tls10`
   * can be used to disable TLS 1.0 for communications with backends.</br>Setting
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Protocols.Server.Http2` can be
   * used to enable HTTP2 protocol on an API Management service.</br>Not
   * specifying any of these properties on PATCH operation will reset omitted
   * properties' values to their defaults. For all the settings except Http2 the
   * default value is `True` if the service was created on or before April 1st
   * 2018 and `False` otherwise. Http2 setting's default value is
   * `False`.</br></br>You can disable any of next ciphers by using settings
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.[cipher_name]`:
   * TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
   * TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
   * TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA256,
   * TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_256_CBC_SHA,
   * TLS_RSA_WITH_AES_128_CBC_SHA. For example,
   * `Microsoft.WindowsAzure.ApiManagement.Gateway.Security.Ciphers.TLS_RSA_WITH_AES_128_CBC_SHA256`:`false`.
   * The default value is `true` for them.  Note: next ciphers can't be disabled
   * since they are required by Azure CloudService internal components:
   * TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256,TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384,TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256,TLS_RSA_WITH_AES_256_GCM_SHA384
   *
   * @param {array} [parameters.certificates] List of Certificates that need to
   * be installed in the API Management service. Max supported certificates that
   * can be installed is 10.
   *
   * @param {boolean} [parameters.enableClientCertificate] Property only meant to
   * be used for Consumption SKU Service. This enforces a client certificate to
   * be presented on each request to the gateway. This also enables the ability
   * to authenticate the certificate in the policy on the gateway.
   *
   * @param {boolean} [parameters.disableGateway] Property only valid for an Api
   * Management service deployed in multiple locations. This can be used to
   * disable the gateway in master region.
   *
   * @param {string} [parameters.virtualNetworkType] The type of VPN in which API
   * Management service needs to be configured in. None (Default Value) means the
   * API Management service is not part of any Virtual Network, External means
   * the API Management deployment is set up inside a Virtual Network having an
   * Internet Facing Endpoint, and Internal means that API Management deployment
   * is setup inside a Virtual Network having an Intranet Facing Endpoint only.
   * Possible values include: 'None', 'External', 'Internal'
   *
   * @param {object} [parameters.apiVersionConstraint] Control Plane Apis version
   * constraint for the API Management service.
   *
   * @param {string} [parameters.apiVersionConstraint.minApiVersion] Limit
   * control plane API calls to API Management service with version equal to or
   * newer than this value.
   *
   * @param {string} [parameters.publisherEmail] Publisher email.
   *
   * @param {string} [parameters.publisherName] Publisher name.
   *
   * @param {object} [parameters.sku] SKU properties of the API Management
   * service.
   *
   * @param {string} parameters.sku.name Name of the Sku. Possible values
   * include: 'Developer', 'Standard', 'Premium', 'Basic', 'Consumption'
   *
   * @param {number} parameters.sku.capacity Capacity of the SKU (number of
   * deployed units of the SKU). For Consumption SKU capacity must be specified
   * as 0.
   *
   * @param {object} [parameters.identity] Managed service identity of the Api
   * Management service.
   *
   * @param {string} parameters.identity.type The type of identity used for the
   * resource. The type 'SystemAssigned, UserAssigned' includes both an
   * implicitly created identity and a set of user assigned identities. The type
   * 'None' will remove any identities from the service. Possible values include:
   * 'SystemAssigned', 'UserAssigned', 'SystemAssigned, UserAssigned', 'None'
   *
   * @param {object} [parameters.identity.userAssignedIdentities] The list of
   * user identities associated with the resource. The user identity
   * dictionary key references will be ARM resource ids in the form:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/
   * providers/Microsoft.ManagedIdentity/userAssignedIdentities/{identityName}'.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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(resourceGroupName, serviceName, parameters, 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(resourceGroupName, serviceName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginUpdate(resourceGroupName, serviceName, parameters, options, optionalCallback);
    }
  }

  /**
   * Deletes an existing API Management service.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @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<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginDeleteMethodWithHttpOperationResponse(resourceGroupName, serviceName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginDeleteMethod(resourceGroupName, serviceName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Deletes an existing API Management service.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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.
   */
  beginDeleteMethod(resourceGroupName, serviceName, 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(resourceGroupName, serviceName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginDeleteMethod(resourceGroupName, serviceName, options, optionalCallback);
    }
  }

  /**
   * Updates the Microsoft.ApiManagement resource running in the Virtual network
   * to pick the updated network settings.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.parameters] Parameters supplied to the Apply
   * Network Configuration operation. If the parameters are empty, all the
   * regions in which the Api Management service is deployed will be updated
   * sequentially without incurring downtime in the region.
   *
   * @param {string} [options.parameters.location] Location of the Api Management
   * service to update for a multi-region service. For a service deployed in a
   * single region, this parameter is not required.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ApiManagementServiceResource>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginApplyNetworkConfigurationUpdatesWithHttpOperationResponse(resourceGroupName, serviceName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginApplyNetworkConfigurationUpdates(resourceGroupName, serviceName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Updates the Microsoft.ApiManagement resource running in the Virtual network
   * to pick the updated network settings.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} serviceName The name of the API Management service.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.parameters] Parameters supplied to the Apply
   * Network Configuration operation. If the parameters are empty, all the
   * regions in which the Api Management service is deployed will be updated
   * sequentially without incurring downtime in the region.
   *
   * @param {string} [options.parameters.location] Location of the Api Management
   * service to update for a multi-region service. For a service deployed in a
   * single region, this parameter is not required.
   *
   * @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 {ApiManagementServiceResource} - 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 ApiManagementServiceResource} 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.
   */
  beginApplyNetworkConfigurationUpdates(resourceGroupName, serviceName, 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._beginApplyNetworkConfigurationUpdates(resourceGroupName, serviceName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginApplyNetworkConfigurationUpdates(resourceGroupName, serviceName, options, optionalCallback);
    }
  }

  /**
   * List all API Management services within a 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<ApiManagementServiceListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByResourceGroupNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * List all API Management services within a 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 {ApiManagementServiceListResult} - 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 ApiManagementServiceListResult} 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.
   */
  listByResourceGroupNext(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._listByResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByResourceGroupNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * Lists all API Management services within an 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<ApiManagementServiceListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Lists all API Management services within an 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 {ApiManagementServiceListResult} - 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 ApiManagementServiceListResult} 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.
   */
  listNext(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._listNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listNext(nextPageLink, options, optionalCallback);
    }
  }

}

module.exports = ApiManagementService;
