text: /*
   * 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 0.16.0.0
   * Changes may cause incorrect behavior and will be lost if the code is
   * regenerated.
   */
  
  'use strict';
  
  var util = require('util');
  var msRest = require('ms-rest');
  var msRestAzure = require('ms-rest-azure');
  var WebResource = msRest.WebResource;
  
  /**
   * @class
   * VirtualNetworkGatewayConnections
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the NetworkManagementClient.
   * Initializes a new instance of the VirtualNetworkGatewayConnections class.
   * @constructor
   *
   * @param {NetworkManagementClient} client Reference to the service client.
   */
  function VirtualNetworkGatewayConnections(client) {
    this.client = client;
  }
  
  /**
   *
   * The Put VirtualNetworkGatewayConnection operation creates/updates a virtual
   * network gateway connection in the specified resource group through Network
   * resource provider.
   *
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} virtualNetworkGatewayConnectionName The name of the virtual
   * network gateway conenction.
   * 
   * @param {object} parameters Parameters supplied to the Begin Create or
   * update Virtual Network Gateway connection operation through Network
   * resource provider.
   * 
   * @param {string} [parameters.authorizationKey] The authorizationKey.
   * 
   * @param {object} [parameters.virtualNetworkGateway1]
   * 
   * @param {object} [parameters.virtualNetworkGateway2]
   * 
   * @param {array} [parameters.virtualNetworkGateway2.ipConfigurations]
   * IpConfigurations for Virtual network gateway.
   * 
   * @param {string} [parameters.virtualNetworkGateway2.gatewayType] The type of
   * this virtual network gateway. Possible values include: 'Vpn',
   * 'ExpressRoute'
   * 
   * @param {string} [parameters.virtualNetworkGateway2.vpnType] The type of
   * this virtual network gateway. Possible values include: 'PolicyBased',
   * 'RouteBased'
   * 
   * @param {boolean} [parameters.virtualNetworkGateway2.enableBgp] EnableBgp
   * Flag
   * 
   * @param {object} [parameters.virtualNetworkGateway2.gatewayDefaultSite] Gets
   * or sets the reference of the LocalNetworkGateway resource which represents
   * Local network site having default routes. Assign Null value in case of
   * removing existing default site setting.
   * 
   * @param {object} [parameters.virtualNetworkGateway2.sku] Gets or sets the
   * reference of the VirtualNetworkGatewaySku resource which represents the
   * sku selected for Virtual network gateway.
   * 
   * @param {string} [parameters.virtualNetworkGateway2.sku.name] Gateway sku
   * name -Basic/HighPerformance/Standard. Possible values include: 'Basic',
   * 'HighPerformance', 'Standard'
   * 
   * @param {string} [parameters.virtualNetworkGateway2.sku.tier] Gateway sku
   * tier -Basic/HighPerformance/Standard. Possible values include: 'Basic',
   * 'HighPerformance', 'Standard'
   * 
   * @param {number} [parameters.virtualNetworkGateway2.sku.capacity] The
   * capacity
   * 
   * @param {object} [parameters.virtualNetworkGateway2.vpnClientConfiguration]
   * Gets or sets the reference of the VpnClientConfiguration resource which
   * represents the P2S VpnClient configurations.
   * 
   * @param {object}
   * [parameters.virtualNetworkGateway2.vpnClientConfiguration.vpnClientAddressPool]
   * Gets or sets the reference of the Address space resource which represents
   * Address space for P2S VpnClient.
   * 
   * @param {array}
   * [parameters.virtualNetworkGateway2.vpnClientConfiguration.vpnClientRootCertificates]
   * VpnClientRootCertificate for Virtual network gateway.
   * 
   * @param {array}
   * [parameters.virtualNetworkGateway2.vpnClientConfiguration.vpnClientRevokedCertificates]
   * VpnClientRevokedCertificate for Virtual network gateway.
   * 
   * @param {object} [parameters.virtualNetworkGateway2.bgpSettings] Virtual
   * network gateway's BGP speaker settings
   * 
   * @param {string} [parameters.virtualNetworkGateway2.resourceGuid] Gets or
   * sets resource guid property of the VirtualNetworkGateway resource
   * 
   * @param {string} [parameters.virtualNetworkGateway2.provisioningState] Gets
   * or sets Provisioning state of the VirtualNetworkGateway resource
   * Updating/Deleting/Failed
   * 
   * @param {string} [parameters.virtualNetworkGateway2.etag] Gets a unique
   * read-only string that changes whenever the resource is updated
   * 
   * @param {string} [parameters.virtualNetworkGateway2.id] Resource Id
   * 
   * @param {string} [parameters.virtualNetworkGateway2.location] Resource
   * location
   * 
   * @param {object} [parameters.virtualNetworkGateway2.tags] Resource tags
   * 
   * @param {object} [parameters.localNetworkGateway2]
   * 
   * @param {object} [parameters.localNetworkGateway2.localNetworkAddressSpace]
   * Local network site Address space
   * 
   * @param {array}
   * [parameters.localNetworkGateway2.localNetworkAddressSpace.addressPrefixes]
   * Gets or sets List of address blocks reserved for this virtual network in
   * CIDR notation
   * 
   * @param {string} [parameters.localNetworkGateway2.gatewayIpAddress] IP
   * address of local network gateway.
   * 
   * @param {object} [parameters.localNetworkGateway2.bgpSettings] Local network
   * gateway's BGP speaker settings
   * 
   * @param {number} [parameters.localNetworkGateway2.bgpSettings.asn] Gets or
   * sets this BGP speaker's ASN
   * 
   * @param {string}
   * [parameters.localNetworkGateway2.bgpSettings.bgpPeeringAddress] Gets or
   * sets the BGP peering address and BGP identifier of this BGP speaker
   * 
   * @param {number} [parameters.localNetworkGateway2.bgpSettings.peerWeight]
   * Gets or sets the weight added to routes learned from this BGP speaker
   * 
   * @param {string} [parameters.localNetworkGateway2.resourceGuid] Gets or sets
   * resource guid property of the LocalNetworkGateway resource
   * 
   * @param {string} [parameters.localNetworkGateway2.provisioningState] Gets or
   * sets Provisioning state of the LocalNetworkGateway resource
   * Updating/Deleting/Failed
   * 
   * @param {string} [parameters.localNetworkGateway2.etag] Gets a unique
   * read-only string that changes whenever the resource is updated
   * 
   * @param {string} [parameters.localNetworkGateway2.id] Resource Id
   * 
   * @param {string} [parameters.localNetworkGateway2.location] Resource location
   * 
   * @param {object} [parameters.localNetworkGateway2.tags] Resource tags
   * 
   * @param {string} [parameters.connectionType] Gateway connection type
   * -Ipsec/Dedicated/VpnClient/Vnet2Vnet. Possible values include: 'IPsec',
   * 'Vnet2Vnet', 'ExpressRoute', 'VPNClient'
   * 
   * @param {number} [parameters.routingWeight] The Routing weight.
   * 
   * @param {string} [parameters.sharedKey] The Ipsec share key.
   * 
   * @param {string} [parameters.connectionStatus] Virtual network Gateway
   * connection status. Possible values include: 'Unknown', 'Connecting',
   * 'Connected', 'NotConnected'
   * 
   * @param {number} [parameters.egressBytesTransferred] The Egress Bytes
   * Transferred in this connection
   * 
   * @param {number} [parameters.ingressBytesTransferred] The Ingress Bytes
   * Transferred in this connection
   * 
   * @param {object} [parameters.peer] The reference to peerings resource.
   * 
   * @param {string} [parameters.peer.id] Resource Id
   * 
   * @param {boolean} [parameters.enableBgp] EnableBgp Flag
   * 
   * @param {string} [parameters.resourceGuid] Gets or sets resource guid
   * property of the VirtualNetworkGatewayConnection resource
   * 
   * @param {string} [parameters.provisioningState] Gets or sets Provisioning
   * state of the VirtualNetworkGatewayConnection resource
   * Updating/Deleting/Failed
   * 
   * @param {string} [parameters.etag] Gets a unique read-only string that
   * changes whenever the resource is updated
   * 
   * @param {string} [parameters.id] Resource Id
   * 
   * @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
   *
   * @returns {function} callback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object.
   *                      See {@link VirtualNetworkGatewayConnection} 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.
   */
  VirtualNetworkGatewayConnections.prototype.createOrUpdate = function (resourceGroupName, virtualNetworkGatewayConnectionName, parameters, options, callback) {
    var 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, virtualNetworkGatewayConnectionName, parameters, options, function (err, parsedResult, httpRequest, response){
      if (err) return callback(err);
  
      var initialResult = new msRest.HttpOperationResponse();
      initialResult.request = httpRequest;
      initialResult.response = response;
      initialResult.body = response.body;
      client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) {
        if (err) return callback(err);
  
        // Create Result
        var result = null;
        httpRequest = pollingResult.request;
        response = pollingResult.response;
        var responseBody = pollingResult.body;
        if (responseBody === '') responseBody = null;
  
        // Deserialize Response
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['VirtualNetworkGatewayConnection']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
  
        return callback(null, result, httpRequest, response);
      });
    });
  };
  
  /**
   * The Put VirtualNetworkGatewayConnection operation creates/updates a virtual
   * network gateway connection in the specified resource group through Network
   * resource provider.
   *
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} virtualNetworkGatewayConnectionName The name of the virtual
   * network gateway conenction.
   * 
   * @param {object} parameters Parameters supplied to the Begin Create or
   * update Virtual Network Gateway connection operation through Network
   * resource provider.
   * 
   * @param {string} [parameters.authorizationKey] The authorizationKey.
   * 
   * @param {object} [parameters.virtualNetworkGateway1]
   * 
   * @param {object} [parameters.virtualNetworkGateway2]
   * 
   * @param {array} [parameters.virtualNetworkGateway2.ipConfigurations]
   * IpConfigurations for Virtual network gateway.
   * 
   * @param {string} [parameters.virtualNetworkGateway2.gatewayType] The type of
   * this virtual network gateway. Possible values include: 'Vpn',
   * 'ExpressRoute'
   * 
   * @param {string} [parameters.virtualNetworkGateway2.vpnType] The type of
   * this virtual network gateway. Possible values include: 'PolicyBased',
   * 'RouteBased'
   * 
   * @param {boolean} [parameters.virtualNetworkGateway2.enableBgp] EnableBgp
   * Flag
   * 
   * @param {object} [parameters.virtualNetworkGateway2.gatewayDefaultSite] Gets
   * or sets the reference of the LocalNetworkGateway resource which represents
   * Local network site having default routes. Assign Null value in case of
   * removing existing default site setting.
   * 
   * @param {object} [parameters.virtualNetworkGateway2.sku] Gets or sets the
   * reference of the VirtualNetworkGatewaySku resource which represents the
   * sku selected for Virtual network gateway.
   * 
   * @param {string} [parameters.virtualNetworkGateway2.sku.name] Gateway sku
   * name -Basic/HighPerformance/Standard. Possible values include: 'Basic',
   * 'HighPerformance', 'Standard'
   * 
   * @param {string} [parameters.virtualNetworkGateway2.sku.tier] Gateway sku
   * tier -Basic/HighPerformance/Standard. Possible values include: 'Basic',
   * 'HighPerformance', 'Standard'
   * 
   * @param {number} [parameters.virtualNetworkGateway2.sku.capacity] The
   * capacity
   * 
   * @param {object} [parameters.virtualNetworkGateway2.vpnClientConfiguration]
   * Gets or sets the reference of the VpnClientConfiguration resource which
   * represents the P2S VpnClient configurations.
   * 
   * @param {object}
   * [parameters.virtualNetworkGateway2.vpnClientConfiguration.vpnClientAddressPool]
   * Gets or sets the reference of the Address space resource which represents
   * Address space for P2S VpnClient.
   * 
   * @param {array}
   * [parameters.virtualNetworkGateway2.vpnClientConfiguration.vpnClientRootCertificates]
   * VpnClientRootCertificate for Virtual network gateway.
   * 
   * @param {array}
   * [parameters.virtualNetworkGateway2.vpnClientConfiguration.vpnClientRevokedCertificates]
   * VpnClientRevokedCertificate for Virtual network gateway.
   * 
   * @param {object} [parameters.virtualNetworkGateway2.bgpSettings] Virtual
   * network gateway's BGP speaker settings
   * 
   * @param {string} [parameters.virtualNetworkGateway2.resourceGuid] Gets or
   * sets resource guid property of the VirtualNetworkGateway resource
   * 
   * @param {string} [parameters.virtualNetworkGateway2.provisioningState] Gets
   * or sets Provisioning state of the VirtualNetworkGateway resource
   * Updating/Deleting/Failed
   * 
   * @param {string} [parameters.virtualNetworkGateway2.etag] Gets a unique
   * read-only string that changes whenever the resource is updated
   * 
   * @param {string} [parameters.virtualNetworkGateway2.id] Resource Id
   * 
   * @param {string} [parameters.virtualNetworkGateway2.location] Resource
   * location
   * 
   * @param {object} [parameters.virtualNetworkGateway2.tags] Resource tags
   * 
   * @param {object} [parameters.localNetworkGateway2]
   * 
   * @param {object} [parameters.localNetworkGateway2.localNetworkAddressSpace]
   * Local network site Address space
   * 
   * @param {array}
   * [parameters.localNetworkGateway2.localNetworkAddressSpace.addressPrefixes]
   * Gets or sets List of address blocks reserved for this virtual network in
   * CIDR notation
   * 
   * @param {string} [parameters.localNetworkGateway2.gatewayIpAddress] IP
   * address of local network gateway.
   * 
   * @param {object} [parameters.localNetworkGateway2.bgpSettings] Local network
   * gateway's BGP speaker settings
   * 
   * @param {number} [parameters.localNetworkGateway2.bgpSettings.asn] Gets or
   * sets this BGP speaker's ASN
   * 
   * @param {string}
   * [parameters.localNetworkGateway2.bgpSettings.bgpPeeringAddress] Gets or
   * sets the BGP peering address and BGP identifier of this BGP speaker
   * 
   * @param {number} [parameters.localNetworkGateway2.bgpSettings.peerWeight]
   * Gets or sets the weight added to routes learned from this BGP speaker
   * 
   * @param {string} [parameters.localNetworkGateway2.resourceGuid] Gets or sets
   * resource guid property of the LocalNetworkGateway resource
   * 
   * @param {string} [parameters.localNetworkGateway2.provisioningState] Gets or
   * sets Provisioning state of the LocalNetworkGateway resource
   * Updating/Deleting/Failed
   * 
   * @param {string} [parameters.localNetworkGateway2.etag] Gets a unique
   * read-only string that changes whenever the resource is updated
   * 
   * @param {string} [parameters.localNetworkGateway2.id] Resource Id
   * 
   * @param {string} [parameters.localNetworkGateway2.location] Resource location
   * 
   * @param {object} [parameters.localNetworkGateway2.tags] Resource tags
   * 
   * @param {string} [parameters.connectionType] Gateway connection type
   * -Ipsec/Dedicated/VpnClient/Vnet2Vnet. Possible values include: 'IPsec',
   * 'Vnet2Vnet', 'ExpressRoute', 'VPNClient'
   * 
   * @param {number} [parameters.routingWeight] The Routing weight.
   * 
   * @param {string} [parameters.sharedKey] The Ipsec share key.
   * 
   * @param {string} [parameters.connectionStatus] Virtual network Gateway
   * connection status. Possible values include: 'Unknown', 'Connecting',
   * 'Connected', 'NotConnected'
   * 
   * @param {number} [parameters.egressBytesTransferred] The Egress Bytes
   * Transferred in this connection
   * 
   * @param {number} [parameters.ingressBytesTransferred] The Ingress Bytes
   * Transferred in this connection
   * 
   * @param {object} [parameters.peer] The reference to peerings resource.
   * 
   * @param {string} [parameters.peer.id] Resource Id
   * 
   * @param {boolean} [parameters.enableBgp] EnableBgp Flag
   * 
   * @param {string} [parameters.resourceGuid] Gets or sets resource guid
   * property of the VirtualNetworkGatewayConnection resource
   * 
   * @param {string} [parameters.provisioningState] Gets or sets Provisioning
   * state of the VirtualNetworkGatewayConnection resource
   * Updating/Deleting/Failed
   * 
   * @param {string} [parameters.etag] Gets a unique read-only string that
   * changes whenever the resource is updated
   * 
   * @param {string} [parameters.id] Resource Id
   * 
   * @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
   *
   * @returns {function} callback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object.
   *                      See {@link VirtualNetworkGatewayConnection} 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.
   */
  VirtualNetworkGatewayConnections.prototype.beginCreateOrUpdate = function (resourceGroupName, virtualNetworkGatewayConnectionName, parameters, options, callback) {
    var 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 (virtualNetworkGatewayConnectionName === null || virtualNetworkGatewayConnectionName === undefined || typeof virtualNetworkGatewayConnectionName.valueOf() !== 'string') {
        throw new Error('virtualNetworkGatewayConnectionName cannot be null or undefined and it must be of type string.');
      }
      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
    var requestUrl = this.client.baseUri +
                     '//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/connections/{virtualNetworkGatewayConnectionName}';
    requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
    requestUrl = requestUrl.replace('{virtualNetworkGatewayConnectionName}', encodeURIComponent(virtualNetworkGatewayConnectionName));
    requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
    if (queryParameters.length > 0) {
      requestUrl += '?' + queryParameters.join('&');
    }
    // trim all duplicate forward slashes in the url
    var regex = /([^:]\/)\/+/gi;
    requestUrl = requestUrl.replace(regex, '$1');
  
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = requestUrl;
    // Set Headers
    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(var headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    // Serialize Request
    var requestContent = null;
    var requestModel = null;
    try {
      if (parameters !== null && parameters !== undefined) {
        var requestModelMapper = new client.models['VirtualNetworkGatewayConnection']().mapper();
        requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
        requestContent = JSON.stringify(requestModel);
      }
    } catch (error) {
      var serializationError = new Error(util.format('Error "%s" occurred in serializing the ' + 
          'payload - "%s"', error.message, util.inspect(parameters, {depth: null})));
      return callback(serializationError);
    }
    httpRequest.body = requestContent;
    // Send Request
    return client.pipeline(httpRequest, function (err, response, responseBody) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 201) {
        var error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        var 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) {
            var resultMapper = new client.models['CloudError']().mapper();
            error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
          }
        } catch (defaultError) {
          error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 
                           '- "%s" for the default response.', defaultError.message, responseBody);
          return callback(error);
        }
        return callback(error);
      }
      // Create Result
      var result = null;
      if (responseBody === '') responseBody = null;
      // Deserialize Response
      if (statusCode === 200) {
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['VirtualNetworkGatewayConnection']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
      }
      // Deserialize Response
      if (statusCode === 201) {
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['VirtualNetworkGatewayConnection']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError1 = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError1.request = msRest.stripRequest(httpRequest);
          deserializationError1.response = msRest.stripResponse(response);
          return callback(deserializationError1);
        }
      }
  
      return callback(null, result, httpRequest, response);
    });
  };
  
  /**
   * The Get VirtualNetworkGatewayConnection operation retrieves information
   * about the specified virtual network gateway connection through Network
   * resource provider.
   *
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} virtualNetworkGatewayConnectionName The name of the virtual
   * network gateway connection.
   * 
   * @param {object} [options] Optional Parameters.
   * 
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   * 
   * @param {function} 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.
   *                      See {@link VirtualNetworkGatewayConnection} 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.
   */
  VirtualNetworkGatewayConnections.prototype.get = function (resourceGroupName, virtualNetworkGatewayConnectionName, options, callback) {
    var 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 (virtualNetworkGatewayConnectionName === null || virtualNetworkGatewayConnectionName === undefined || typeof virtualNetworkGatewayConnectionName.valueOf() !== 'string') {
        throw new Error('virtualNetworkGatewayConnectionName 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
    var requestUrl = this.client.baseUri +
                     '//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/connections/{virtualNetworkGatewayConnectionName}';
    requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
    requestUrl = requestUrl.replace('{virtualNetworkGatewayConnectionName}', encodeURIComponent(virtualNetworkGatewayConnectionName));
    requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
    if (queryParameters.length > 0) {
      requestUrl += '?' + queryParameters.join('&');
    }
    // trim all duplicate forward slashes in the url
    var regex = /([^:]\/)\/+/gi;
    requestUrl = requestUrl.replace(regex, '$1');
  
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = requestUrl;
    // Set Headers
    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(var headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    httpRequest.body = null;
    // Send Request
    return client.pipeline(httpRequest, function (err, response, responseBody) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        var 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) {
            var resultMapper = new client.models['CloudError']().mapper();
            error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
          }
        } catch (defaultError) {
          error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 
                           '- "%s" for the default response.', defaultError.message, responseBody);
          return callback(error);
        }
        return callback(error);
      }
      // Create Result
      var result = null;
      if (responseBody === '') responseBody = null;
      // Deserialize Response
      if (statusCode === 200) {
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['VirtualNetworkGatewayConnection']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
      }
  
      return callback(null, result, httpRequest, response);
    });
  };
  
  /**
   *
   * The Delete VirtualNetworkGatewayConnection operation deletes the specifed
   * virtual network Gateway connection through Network resource provider.
   *
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} virtualNetworkGatewayConnectionName The name of the virtual
   * network gateway connection.
   * 
   * @param {object} [options] Optional Parameters.
   * 
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   * 
   * @param {function} callback
   *
   * @returns {function} callback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {null} [result]   - The deserialized result object.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  VirtualNetworkGatewayConnections.prototype.deleteMethod = function (resourceGroupName, virtualNetworkGatewayConnectionName, options, callback) {
    var 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, virtualNetworkGatewayConnectionName, options, function (err, parsedResult, httpRequest, response){
      if (err) return callback(err);
  
      var initialResult = new msRest.HttpOperationResponse();
      initialResult.request = httpRequest;
      initialResult.response = response;
      initialResult.body = response.body;
      client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) {
        if (err) return callback(err);
  
        // Create Result
        var result = null;
        httpRequest = pollingResult.request;
        response = pollingResult.response;
        var responseBody = pollingResult.body;
        if (responseBody === '') responseBody = null;
  
        // Deserialize Response
  
        return callback(null, result, httpRequest, response);
      });
    });
  };
  
  /**
   * The Delete VirtualNetworkGatewayConnection operation deletes the specifed
   * virtual network Gateway connection through Network resource provider.
   *
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} virtualNetworkGatewayConnectionName The name of the virtual
   * network gateway connection.
   * 
   * @param {object} [options] Optional Parameters.
   * 
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   * 
   * @param {function} callback
   *
   * @returns {function} callback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {null} [result]   - The deserialized result object.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  VirtualNetworkGatewayConnections.prototype.beginDeleteMethod = function (resourceGroupName, virtualNetworkGatewayConnectionName, options, callback) {
    var 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 (virtualNetworkGatewayConnectionName === null || virtualNetworkGatewayConnectionName === undefined || typeof virtualNetworkGatewayConnectionName.valueOf() !== 'string') {
        throw new Error('virtualNetworkGatewayConnectionName 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
    var requestUrl = this.client.baseUri +
                     '//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/connections/{virtualNetworkGatewayConnectionName}';
    requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
    requestUrl = requestUrl.replace('{virtualNetworkGatewayConnectionName}', encodeURIComponent(virtualNetworkGatewayConnectionName));
    requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
    if (queryParameters.length > 0) {
      requestUrl += '?' + queryParameters.join('&');
    }
    // trim all duplicate forward slashes in the url
    var regex = /([^:]\/)\/+/gi;
    requestUrl = requestUrl.replace(regex, '$1');
  
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = requestUrl;
    // Set Headers
    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(var headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    httpRequest.body = null;
    // Send Request
    return client.pipeline(httpRequest, function (err, response, responseBody) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 202 && statusCode !== 204) {
        var error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        var 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;
          }
        } catch (defaultError) {
          error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 
                           '- "%s" for the default response.', defaultError.message, responseBody);
          return callback(error);
        }
        return callback(error);
      }
      // Create Result
      var result = null;
      if (responseBody === '') responseBody = null;
  
      return callback(null, result, httpRequest, response);
    });
  };
  
  /**
   * The Get VirtualNetworkGatewayConnectionSharedKey operation retrieves
   * information about the specified virtual network gateway connection shared
   * key through Network resource provider.
   *
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} connectionSharedKeyName The virtual network gateway
   * connection shared key name.
   * 
   * @param {object} [options] Optional Parameters.
   * 
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   * 
   * @param {function} 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.
   *                      See {@link ConnectionSharedKeyResult} 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.
   */
  VirtualNetworkGatewayConnections.prototype.getSharedKey = function (resourceGroupName, connectionSharedKeyName, options, callback) {
    var 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 (connectionSharedKeyName === null || connectionSharedKeyName === undefined || typeof connectionSharedKeyName.valueOf() !== 'string') {
        throw new Error('connectionSharedKeyName 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
    var requestUrl = this.client.baseUri +
                     '//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/connections/{connectionSharedKeyName}/sharedkey';
    requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
    requestUrl = requestUrl.replace('{connectionSharedKeyName}', encodeURIComponent(connectionSharedKeyName));
    requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
    if (queryParameters.length > 0) {
      requestUrl += '?' + queryParameters.join('&');
    }
    // trim all duplicate forward slashes in the url
    var regex = /([^:]\/)\/+/gi;
    requestUrl = requestUrl.replace(regex, '$1');
  
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = requestUrl;
    // Set Headers
    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(var headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    httpRequest.body = null;
    // Send Request
    return client.pipeline(httpRequest, function (err, response, responseBody) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        var 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) {
            var resultMapper = new client.models['CloudError']().mapper();
            error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
          }
        } catch (defaultError) {
          error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 
                           '- "%s" for the default response.', defaultError.message, responseBody);
          return callback(error);
        }
        return callback(error);
      }
      // Create Result
      var result = null;
      if (responseBody === '') responseBody = null;
      // Deserialize Response
      if (statusCode === 200) {
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['ConnectionSharedKeyResult']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
      }
  
      return callback(null, result, httpRequest, response);
    });
  };
  
  /**
   * The List VirtualNetworkGatewayConnections operation retrieves all the
   * virtual network gateways connections created.
   *
   * @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
   *
   * @returns {function} callback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object.
   *                      See {@link VirtualNetworkGatewayConnectionListResult}
   *                      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.
   */
  VirtualNetworkGatewayConnections.prototype.list = function (resourceGroupName, options, callback) {
    var 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
    var requestUrl = this.client.baseUri +
                     '//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/connections';
    requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
    requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
    if (queryParameters.length > 0) {
      requestUrl += '?' + queryParameters.join('&');
    }
    // trim all duplicate forward slashes in the url
    var regex = /([^:]\/)\/+/gi;
    requestUrl = requestUrl.replace(regex, '$1');
  
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = requestUrl;
    // Set Headers
    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(var headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    httpRequest.body = null;
    // Send Request
    return client.pipeline(httpRequest, function (err, response, responseBody) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        var 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) {
            var resultMapper = new client.models['CloudError']().mapper();
            error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
          }
        } catch (defaultError) {
          error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 
                           '- "%s" for the default response.', defaultError.message, responseBody);
          return callback(error);
        }
        return callback(error);
      }
      // Create Result
      var result = null;
      if (responseBody === '') responseBody = null;
      // Deserialize Response
      if (statusCode === 200) {
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['VirtualNetworkGatewayConnectionListResult']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
      }
  
      return callback(null, result, httpRequest, response);
    });
  };
  
  /**
   *
   * The VirtualNetworkGatewayConnectionResetSharedKey operation resets the
   * virtual network gateway connection shared key for passed virtual network
   * gateway connection in the specified resource group through Network
   * resource provider.
   *
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} virtualNetworkGatewayConnectionName The virtual network
   * gateway connection reset shared key Name.
   * 
   * @param {object} [options] Optional Parameters.
   * 
   * @param {number} [options.keyLength] The virtual network connection reset
   * shared key length
   * 
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   * 
   * @param {function} 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.
   *                      See {@link ConnectionResetSharedKey} 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.
   */
  VirtualNetworkGatewayConnections.prototype.resetSharedKey = function (resourceGroupName, virtualNetworkGatewayConnectionName, options, callback) {
    var client = this.client;
    if(!callback && typeof options === 'function') {
      callback = options;
      options = null;
    }
  
    if (!callback) {
      throw new Error('callback cannot be null.');
    }
  
    // Send request
    this.beginResetSharedKey(resourceGroupName, virtualNetworkGatewayConnectionName, options, function (err, parsedResult, httpRequest, response){
      if (err) return callback(err);
  
      var initialResult = new msRest.HttpOperationResponse();
      initialResult.request = httpRequest;
      initialResult.response = response;
      initialResult.body = response.body;
      client.getPostOrDeleteOperationResult(initialResult, options, function (err, pollingResult) {
        if (err) return callback(err);
  
        // Create Result
        var result = null;
        httpRequest = pollingResult.request;
        response = pollingResult.response;
        var responseBody = pollingResult.body;
        if (responseBody === '') responseBody = null;
  
        // Deserialize Response
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['ConnectionResetSharedKey']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
  
        return callback(null, result, httpRequest, response);
      });
    });
  };
  
  /**
   * The VirtualNetworkGatewayConnectionResetSharedKey operation resets the
   * virtual network gateway connection shared key for passed virtual network
   * gateway connection in the specified resource group through Network
   * resource provider.
   *
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} virtualNetworkGatewayConnectionName The virtual network
   * gateway connection reset shared key Name.
   * 
   * @param {object} [options] Optional Parameters.
   * 
   * @param {number} [options.keyLength] The virtual network connection reset
   * shared key length
   * 
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   * 
   * @param {function} 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.
   *                      See {@link ConnectionResetSharedKey} 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.
   */
  VirtualNetworkGatewayConnections.prototype.beginResetSharedKey = function (resourceGroupName, virtualNetworkGatewayConnectionName, options, callback) {
    var client = this.client;
    if(!callback && typeof options === 'function') {
      callback = options;
      options = null;
    }
    if (!callback) {
      throw new Error('callback cannot be null.');
    }
    var keyLength = (options && options.keyLength !== undefined) ? options.keyLength : 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 (virtualNetworkGatewayConnectionName === null || virtualNetworkGatewayConnectionName === undefined || typeof virtualNetworkGatewayConnectionName.valueOf() !== 'string') {
        throw new Error('virtualNetworkGatewayConnectionName 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 (keyLength !== null && keyLength !== undefined && typeof keyLength !== 'number') {
        throw new Error('keyLength must be of type number.');
      }
      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);
    }
    var parameters;
    if (keyLength !== null && keyLength !== undefined) {
        parameters = new client.models['ConnectionResetSharedKey']();
        parameters.keyLength = keyLength;
    }
  
    // Construct URL
    var requestUrl = this.client.baseUri +
                     '//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/connections/{virtualNetworkGatewayConnectionName}/sharedkey/reset';
    requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
    requestUrl = requestUrl.replace('{virtualNetworkGatewayConnectionName}', encodeURIComponent(virtualNetworkGatewayConnectionName));
    requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
    if (queryParameters.length > 0) {
      requestUrl += '?' + queryParameters.join('&');
    }
    // trim all duplicate forward slashes in the url
    var regex = /([^:]\/)\/+/gi;
    requestUrl = requestUrl.replace(regex, '$1');
  
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = requestUrl;
    // Set Headers
    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(var headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    // Serialize Request
    var requestContent = null;
    var requestModel = null;
    try {
      if (parameters !== null && parameters !== undefined) {
        var requestModelMapper = new client.models['ConnectionResetSharedKey']().mapper();
        requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
        requestContent = JSON.stringify(requestModel);
      }
    } catch (error) {
      var serializationError = new Error(util.format('Error "%s" occurred in serializing the ' + 
          'payload - "%s"', error.message, util.inspect(parameters, {depth: null})));
      return callback(serializationError);
    }
    httpRequest.body = requestContent;
    // Send Request
    return client.pipeline(httpRequest, function (err, response, responseBody) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 202) {
        var error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        var 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) {
            var resultMapper = new client.models['CloudError']().mapper();
            error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
          }
        } catch (defaultError) {
          error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 
                           '- "%s" for the default response.', defaultError.message, responseBody);
          return callback(error);
        }
        return callback(error);
      }
      // Create Result
      var result = null;
      if (responseBody === '') responseBody = null;
      // Deserialize Response
      if (statusCode === 200) {
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['ConnectionResetSharedKey']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
      }
  
      return callback(null, result, httpRequest, response);
    });
  };
  
  /**
   *
   * The Put VirtualNetworkGatewayConnectionSharedKey operation sets the virtual
   * network gateway connection shared key for passed virtual network gateway
   * connection in the specified resource group through Network resource
   * provider.
   *
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} virtualNetworkGatewayConnectionName The virtual network
   * gateway connection name.
   * 
   * @param {object} [options] Optional Parameters.
   * 
   * @param {string} [options.value] The virtual network connection shared key
   * value
   * 
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   * 
   * @param {function} 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.
   *                      See {@link ConnectionSharedKey} 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.
   */
  VirtualNetworkGatewayConnections.prototype.setSharedKey = function (resourceGroupName, virtualNetworkGatewayConnectionName, options, callback) {
    var client = this.client;
    if(!callback && typeof options === 'function') {
      callback = options;
      options = null;
    }
  
    if (!callback) {
      throw new Error('callback cannot be null.');
    }
  
    // Send request
    this.beginSetSharedKey(resourceGroupName, virtualNetworkGatewayConnectionName, options, function (err, parsedResult, httpRequest, response){
      if (err) return callback(err);
  
      var initialResult = new msRest.HttpOperationResponse();
      initialResult.request = httpRequest;
      initialResult.response = response;
      initialResult.body = response.body;
      client.getPutOrPatchOperationResult(initialResult, options, function (err, pollingResult) {
        if (err) return callback(err);
  
        // Create Result
        var result = null;
        httpRequest = pollingResult.request;
        response = pollingResult.response;
        var responseBody = pollingResult.body;
        if (responseBody === '') responseBody = null;
  
        // Deserialize Response
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['ConnectionSharedKey']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
  
        return callback(null, result, httpRequest, response);
      });
    });
  };
  
  /**
   * The Put VirtualNetworkGatewayConnectionSharedKey operation sets the virtual
   * network gateway connection shared key for passed virtual network gateway
   * connection in the specified resource group through Network resource
   * provider.
   *
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} virtualNetworkGatewayConnectionName The virtual network
   * gateway connection name.
   * 
   * @param {object} [options] Optional Parameters.
   * 
   * @param {string} [options.value] The virtual network connection shared key
   * value
   * 
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   * 
   * @param {function} 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.
   *                      See {@link ConnectionSharedKey} 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.
   */
  VirtualNetworkGatewayConnections.prototype.beginSetSharedKey = function (resourceGroupName, virtualNetworkGatewayConnectionName, options, callback) {
    var client = this.client;
    if(!callback && typeof options === 'function') {
      callback = options;
      options = null;
    }
    if (!callback) {
      throw new Error('callback cannot be null.');
    }
    var value = (options && options.value !== undefined) ? options.value : 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 (virtualNetworkGatewayConnectionName === null || virtualNetworkGatewayConnectionName === undefined || typeof virtualNetworkGatewayConnectionName.valueOf() !== 'string') {
        throw new Error('virtualNetworkGatewayConnectionName 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 (value !== null && value !== undefined && typeof value.valueOf() !== 'string') {
        throw new Error('value 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);
    }
    var parameters;
    if (value !== null && value !== undefined) {
        parameters = new client.models['ConnectionSharedKey']();
        parameters.value = value;
    }
  
    // Construct URL
    var requestUrl = this.client.baseUri +
                     '//subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/connections/{virtualNetworkGatewayConnectionName}/sharedkey';
    requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
    requestUrl = requestUrl.replace('{virtualNetworkGatewayConnectionName}', encodeURIComponent(virtualNetworkGatewayConnectionName));
    requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
    if (queryParameters.length > 0) {
      requestUrl += '?' + queryParameters.join('&');
    }
    // trim all duplicate forward slashes in the url
    var regex = /([^:]\/)\/+/gi;
    requestUrl = requestUrl.replace(regex, '$1');
  
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = requestUrl;
    // Set Headers
    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(var headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    // Serialize Request
    var requestContent = null;
    var requestModel = null;
    try {
      if (parameters !== null && parameters !== undefined) {
        var requestModelMapper = new client.models['ConnectionSharedKey']().mapper();
        requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
        requestContent = JSON.stringify(requestModel);
      }
    } catch (error) {
      var serializationError = new Error(util.format('Error "%s" occurred in serializing the ' + 
          'payload - "%s"', error.message, util.inspect(parameters, {depth: null})));
      return callback(serializationError);
    }
    httpRequest.body = requestContent;
    // Send Request
    return client.pipeline(httpRequest, function (err, response, responseBody) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 201 && statusCode !== 200) {
        var error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        var 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) {
            var resultMapper = new client.models['CloudError']().mapper();
            error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
          }
        } catch (defaultError) {
          error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 
                           '- "%s" for the default response.', defaultError.message, responseBody);
          return callback(error);
        }
        return callback(error);
      }
      // Create Result
      var result = null;
      if (responseBody === '') responseBody = null;
      // Deserialize Response
      if (statusCode === 201) {
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['ConnectionSharedKey']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
      }
      // Deserialize Response
      if (statusCode === 200) {
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['ConnectionSharedKey']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError1 = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError1.request = msRest.stripRequest(httpRequest);
          deserializationError1.response = msRest.stripResponse(response);
          return callback(deserializationError1);
        }
      }
  
      return callback(null, result, httpRequest, response);
    });
  };
  
  /**
   * The List VirtualNetworkGatewayConnections operation retrieves all the
   * virtual network gateways connections created.
   *
   * @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
   *
   * @returns {function} callback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object.
   *                      See {@link VirtualNetworkGatewayConnectionListResult}
   *                      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.
   */
  VirtualNetworkGatewayConnections.prototype.listNext = function (nextPageLink, options, callback) {
    var 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
    var requestUrl = '{nextLink}';
    requestUrl = requestUrl.replace('{nextLink}', nextPageLink);
    // trim all duplicate forward slashes in the url
    var regex = /([^:]\/)\/+/gi;
    requestUrl = requestUrl.replace(regex, '$1');
  
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = requestUrl;
    // Set Headers
    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(var headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    httpRequest.body = null;
    // Send Request
    return client.pipeline(httpRequest, function (err, response, responseBody) {
      if (err) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        var 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) {
            var resultMapper = new client.models['CloudError']().mapper();
            error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
          }
        } catch (defaultError) {
          error.message = util.format('Error "%s" occurred in deserializing the responseBody ' + 
                           '- "%s" for the default response.', defaultError.message, responseBody);
          return callback(error);
        }
        return callback(error);
      }
      // Create Result
      var result = null;
      if (responseBody === '') responseBody = null;
      // Deserialize Response
      if (statusCode === 200) {
        var parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            var resultMapper = new client.models['VirtualNetworkGatewayConnectionListResult']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          var deserializationError = new Error(util.format('Error "%s" occurred in deserializing the responseBody - "%s"', error, responseBody));
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
      }
  
      return callback(null, result, httpRequest, response);
    });
  };
  
  
  module.exports = VirtualNetworkGatewayConnections;
  