/* jshint latedef:false */
/* jshint forin:false */
/* jshint noempty:false */

// 
// Copyright (c) Microsoft and contributors.  All rights reserved.
// 
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//   http://www.apache.org/licenses/LICENSE-2.0
// 
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// 
// See the License for the specific language governing permissions and
// limitations under the License.
// 

// Warning: This code was generated by a tool.
// 
// Changes to this file may cause incorrect behavior and will be lost if the
// code is regenerated.

'use strict';

var util = require('util');
var _ = require('underscore');
var moment = require('moment');
var azureCommon = require('azure-common');
var Service = azureCommon.Service;
var WebResource = azureCommon.WebResource;
var OperationStatus = azureCommon.OperationStatus;

var ResourceManagementClient = ( /** @lends ResourceManagementClient */ function() {
  /**
   * @class
   * Initializes a new instance of the ResourceManagementClient class.
   * @constructor
   * 
   * @param {SubscriptionCloudCredentials} credentials Gets subscription
   * credentials which uniquely identify Microsoft Azure subscription. The
   * subscription ID forms part of the URI for every service call.
   * 
   * @param {string} [credentials.subscriptionId]
   * 
   * @param {string} [baseUri] Gets the URI used as the base for all cloud
   * service requests.
   * 
   * @param {Array} filters
   */
  function ResourceManagementClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    ResourceManagementClient['super_'].call(this, credentials, filters);
    
    this.credentials = credentials;
    this.baseUri = baseUri;
    if (this.baseUri === null || this.baseUri === undefined) {
      this.baseUri = 'https://management.azure.com/';
    }
    if (this.apiVersion === null || this.apiVersion === undefined) {
      this.apiVersion = '2015-11-01';
    }
    if (this.longRunningOperationInitialTimeout === null || this.longRunningOperationInitialTimeout === undefined) {
      this.longRunningOperationInitialTimeout = -1;
    }
    if (this.longRunningOperationRetryTimeout === null || this.longRunningOperationRetryTimeout === undefined) {
      this.longRunningOperationRetryTimeout = -1;
    }
    /**
     * Provides an instance of the
     * [DeploymentOperationOperations](-DeploymentOperationOperations.html)
     * object.
     * @type {object}
     */
    this.deploymentOperations = new DeploymentOperationOperations(this);
    /**
     * Provides an instance of the
     * [DeploymentOperations](-DeploymentOperations.html) object.
     * @type {object}
     */
    this.deployments = new DeploymentOperations(this);
    /**
     * Provides an instance of the
     * [ProviderOperations](-ProviderOperations.html) object.
     * @type {object}
     */
    this.providers = new ProviderOperations(this);
    /**
     * Provides an instance of the
     * [ProviderOperationsMetadataOperations](-ProviderOperationsMetadataOperations.html)
     * object.
     * @type {object}
     */
    this.providerOperationsMetadata = new ProviderOperationsMetadataOperations(this);
    /**
     * Provides an instance of the
     * [ResourceGroupOperations](-ResourceGroupOperations.html) object.
     * @type {object}
     */
    this.resourceGroups = new ResourceGroupOperations(this);
    /**
     * Provides an instance of the
     * [ResourceOperations](-ResourceOperations.html) object.
     * @type {object}
     */
    this.resources = new ResourceOperations(this);
    /**
     * Provides an instance of the
     * [ResourceProviderOperationDetailsOperations](-ResourceProviderOperationDetailsOperations.html)
     * object.
     * @type {object}
     */
    this.resourceProviderOperationDetails = new ResourceProviderOperationDetailsOperations(this);
    /**
     * Provides an instance of the [TagOperations](-TagOperations.html) object.
     * @type {object}
     */
    this.tags = new TagOperations(this);
  }
  
  util.inherits(ResourceManagementClient, Service);
  
  /**
   * The Get Operation Status operation returns the status of the specified
   * operation. After calling an asynchronous operation, you can call Get
   * Operation Status to determine whether the operation has succeeded,
   * failed, or is still in progress.
   * 
   * @param {string} operationStatusLink Location value returned by the Begin
   * operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceManagementClient.prototype.getLongRunningOperationStatus = function(operationStatusLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (operationStatusLink === null || operationStatusLink === undefined) {
      return callback(new Error('operationStatusLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + operationStatusLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['x-ms-version'] = '2015-11-01';
    
    // Send Request
    return this.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 202 && statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.retryAfter = parseInt(response.headers['retry-after'], 10);
      result.requestId = response.headers['x-ms-request-id'];
      if (statusCode === 400) {
        result.status = OperationStatus.Failed;
      }
      if (statusCode === 409) {
        result.status = OperationStatus.Failed;
      }
      if (statusCode === 202) {
        result.status = OperationStatus.InProgress;
      }
      if (statusCode === 204) {
        result.status = OperationStatus.Succeeded;
      }
      if (statusCode === 200) {
        result.status = OperationStatus.Succeeded;
      }
      
      return callback(null, result);
    });
  };
  
  return ResourceManagementClient;
})();
exports.ResourceManagementClient = ResourceManagementClient;

var DeploymentOperationOperations = ( /** @lends DeploymentOperationOperations */ function() {
  /**
   * @class
   * Operations for managing deployment operations.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ResourceManagementClient] {@link
   * ResourceManagementClient~ResourceManagementClient}.
   * See [deploymentOperations] {@link
   * ResourceManagementClient~ResourceManagementClient#deploymentOperations}.
   * Initializes a new instance of the DeploymentOperationOperations class.
   * @constructor
   * 
   * @param {ResourceManagementClient} client Reference to the service client.
   */
  function DeploymentOperationOperations(client) {
    this.client = client;
  }
  
  /**
   * Get a list of deployments operations.
   * 
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   * 
   * @param {string} deploymentName The name of the deployment.
   * 
   * @param {string} operationId Operation Id.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperationOperations.prototype.get = function(resourceGroupName, deploymentName, operationId, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (operationId === null || operationId === undefined) {
      return callback(new Error('operationId cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/deployments/';
    url2 = url2 + encodeURIComponent(deploymentName);
    url2 = url2 + '/operations/';
    url2 = url2 + encodeURIComponent(operationId);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var operationInstance = {};
          result.operation = operationInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            operationInstance.id = idInstance;
          }
          
          var operationIdValue = responseDoc['operationId'];
          if (operationIdValue !== null && operationIdValue !== undefined) {
            var operationIdInstance = operationIdValue;
            operationInstance.operationId = operationIdInstance;
          }
          
          var propertiesValue = responseDoc['properties'];
          if (propertiesValue !== null && propertiesValue !== undefined) {
            var propertiesInstance = {};
            operationInstance.properties = propertiesInstance;
            
            var provisioningStateValue = propertiesValue['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              propertiesInstance.provisioningState = provisioningStateInstance;
            }
            
            var timestampValue = propertiesValue['timestamp'];
            if (timestampValue !== null && timestampValue !== undefined) {
              var timestampInstance = timestampValue;
              propertiesInstance.timestamp = timestampInstance;
            }
            
            var statusCodeValue = propertiesValue['statusCode'];
            if (statusCodeValue !== null && statusCodeValue !== undefined) {
              var statusCodeInstance = statusCodeValue;
              propertiesInstance.statusCode = statusCodeInstance;
            }
            
            var statusMessageValue = propertiesValue['statusMessage'];
            if (statusMessageValue !== null && statusMessageValue !== undefined) {
              var statusMessageInstance = statusMessageValue;
              propertiesInstance.statusMessage = statusMessageInstance;
            }
            
            var targetResourceValue = propertiesValue['targetResource'];
            if (targetResourceValue !== null && targetResourceValue !== undefined) {
              var targetResourceInstance = {};
              propertiesInstance.targetResource = targetResourceInstance;
              
              var idValue2 = targetResourceValue['id'];
              if (idValue2 !== null && idValue2 !== undefined) {
                var idInstance2 = idValue2;
                targetResourceInstance.id = idInstance2;
              }
              
              var resourceNameValue = targetResourceValue['resourceName'];
              if (resourceNameValue !== null && resourceNameValue !== undefined) {
                var resourceNameInstance = resourceNameValue;
                targetResourceInstance.resourceName = resourceNameInstance;
              }
              
              var resourceTypeValue = targetResourceValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = resourceTypeValue;
                targetResourceInstance.resourceType = resourceTypeInstance;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets a list of deployments operations.
   * 
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   * 
   * @param {string} deploymentName The name of the deployment.
   * 
   * @param {DeploymentOperationsListParameters} [parametersOrCallback] Query
   * parameters.
   * 
   * @param {number} [parametersOrCallback.top] Get or sets the number of
   * records to return. Optional.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperationOperations.prototype.list = function(resourceGroupName, deploymentName, parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/deployments/';
    url2 = url2 + encodeURIComponent(deploymentName);
    url2 = url2 + '/operations';
    var queryParameters = [];
    if (parameters !== null && parameters !== undefined && parameters.top !== null && parameters.top !== undefined) {
      queryParameters.push('$top=' + encodeURIComponent(parameters.top.toString()));
    }
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { operations: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var deploymentOperationInstance = {};
              result.operations.push(deploymentOperationInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                deploymentOperationInstance.id = idInstance;
              }
              
              var operationIdValue = valueValue['operationId'];
              if (operationIdValue !== null && operationIdValue !== undefined) {
                var operationIdInstance = operationIdValue;
                deploymentOperationInstance.operationId = operationIdInstance;
              }
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var propertiesInstance = {};
                deploymentOperationInstance.properties = propertiesInstance;
                
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  propertiesInstance.provisioningState = provisioningStateInstance;
                }
                
                var timestampValue = propertiesValue['timestamp'];
                if (timestampValue !== null && timestampValue !== undefined) {
                  var timestampInstance = timestampValue;
                  propertiesInstance.timestamp = timestampInstance;
                }
                
                var statusCodeValue = propertiesValue['statusCode'];
                if (statusCodeValue !== null && statusCodeValue !== undefined) {
                  var statusCodeInstance = statusCodeValue;
                  propertiesInstance.statusCode = statusCodeInstance;
                }
                
                var statusMessageValue = propertiesValue['statusMessage'];
                if (statusMessageValue !== null && statusMessageValue !== undefined) {
                  var statusMessageInstance = statusMessageValue;
                  propertiesInstance.statusMessage = statusMessageInstance;
                }
                
                var targetResourceValue = propertiesValue['targetResource'];
                if (targetResourceValue !== null && targetResourceValue !== undefined) {
                  var targetResourceInstance = {};
                  propertiesInstance.targetResource = targetResourceInstance;
                  
                  var idValue2 = targetResourceValue['id'];
                  if (idValue2 !== null && idValue2 !== undefined) {
                    var idInstance2 = idValue2;
                    targetResourceInstance.id = idInstance2;
                  }
                  
                  var resourceNameValue = targetResourceValue['resourceName'];
                  if (resourceNameValue !== null && resourceNameValue !== undefined) {
                    var resourceNameInstance = resourceNameValue;
                    targetResourceInstance.resourceName = resourceNameInstance;
                  }
                  
                  var resourceTypeValue = targetResourceValue['resourceType'];
                  if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                    var resourceTypeInstance = resourceTypeValue;
                    targetResourceInstance.resourceType = resourceTypeInstance;
                  }
                }
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets a next list of deployments operations.
   * 
   * @param {string} nextLink NextLink from the previous successful call to
   * List operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperationOperations.prototype.listNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { operations: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var deploymentOperationInstance = {};
              result.operations.push(deploymentOperationInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                deploymentOperationInstance.id = idInstance;
              }
              
              var operationIdValue = valueValue['operationId'];
              if (operationIdValue !== null && operationIdValue !== undefined) {
                var operationIdInstance = operationIdValue;
                deploymentOperationInstance.operationId = operationIdInstance;
              }
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var propertiesInstance = {};
                deploymentOperationInstance.properties = propertiesInstance;
                
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  propertiesInstance.provisioningState = provisioningStateInstance;
                }
                
                var timestampValue = propertiesValue['timestamp'];
                if (timestampValue !== null && timestampValue !== undefined) {
                  var timestampInstance = timestampValue;
                  propertiesInstance.timestamp = timestampInstance;
                }
                
                var statusCodeValue = propertiesValue['statusCode'];
                if (statusCodeValue !== null && statusCodeValue !== undefined) {
                  var statusCodeInstance = statusCodeValue;
                  propertiesInstance.statusCode = statusCodeInstance;
                }
                
                var statusMessageValue = propertiesValue['statusMessage'];
                if (statusMessageValue !== null && statusMessageValue !== undefined) {
                  var statusMessageInstance = statusMessageValue;
                  propertiesInstance.statusMessage = statusMessageInstance;
                }
                
                var targetResourceValue = propertiesValue['targetResource'];
                if (targetResourceValue !== null && targetResourceValue !== undefined) {
                  var targetResourceInstance = {};
                  propertiesInstance.targetResource = targetResourceInstance;
                  
                  var idValue2 = targetResourceValue['id'];
                  if (idValue2 !== null && idValue2 !== undefined) {
                    var idInstance2 = idValue2;
                    targetResourceInstance.id = idInstance2;
                  }
                  
                  var resourceNameValue = targetResourceValue['resourceName'];
                  if (resourceNameValue !== null && resourceNameValue !== undefined) {
                    var resourceNameInstance = resourceNameValue;
                    targetResourceInstance.resourceName = resourceNameInstance;
                  }
                  
                  var resourceTypeValue = targetResourceValue['resourceType'];
                  if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                    var resourceTypeInstance = resourceTypeValue;
                    targetResourceInstance.resourceType = resourceTypeInstance;
                  }
                }
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return DeploymentOperationOperations;
})();

var DeploymentOperations = ( /** @lends DeploymentOperations */ function() {
  /**
   * @class
   * Operations for managing deployments.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ResourceManagementClient] {@link
   * ResourceManagementClient~ResourceManagementClient}.
   * See [deployments] {@link
   * ResourceManagementClient~ResourceManagementClient#deployments}.
   * Initializes a new instance of the DeploymentOperations class.
   * @constructor
   * 
   * @param {ResourceManagementClient} client Reference to the service client.
   */
  function DeploymentOperations(client) {
    this.client = client;
  }
  
  /**
   * Begin deleting deployment.To determine whether the operation has finished
   * processing the request, call GetLongRunningOperationStatus.
   * 
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   * 
   * @param {string} deploymentName The name of the deployment to be deleted.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.beginDeleting = function(resourceGroupName, deploymentName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/deployments/';
    url2 = url2 + encodeURIComponent(deploymentName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 202 && statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.operationStatusLink = response.headers['location'];
      result.retryAfter = parseInt(response.headers['retry-after'], 10);
      result.requestId = response.headers['x-ms-request-id'];
      if (statusCode === 409) {
        result.status = OperationStatus.Failed;
      }
      if (statusCode === 202) {
        result.status = OperationStatus.InProgress;
      }
      if (statusCode === 204) {
        result.status = OperationStatus.Succeeded;
      }
      
      return callback(null, result);
    });
  };
  
  /**
   * Cancel a currently running template deployment.
   * 
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   * 
   * @param {string} deploymentName The name of the deployment.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.cancel = function(resourceGroupName, deploymentName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/deployments/';
    url2 = url2 + encodeURIComponent(deploymentName);
    url2 = url2 + '/cancel';
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Checks whether deployment exists.
   * 
   * @param {string} resourceGroupName The name of the resource group to check.
   * The name is case insensitive.
   * 
   * @param {string} deploymentName The name of the deployment.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.checkExistence = function(resourceGroupName, deploymentName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + 'subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/deployments/';
    url2 = url2 + encodeURIComponent(deploymentName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'HEAD';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 204 && statusCode !== 404) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      if (statusCode === 204) {
        result.exists = true;
      }
      
      return callback(null, result);
    });
  };
  
  /**
   * Create a named template deployment using a template.
   * 
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   * 
   * @param {string} deploymentName The name of the deployment.
   * 
   * @param {Deployment} parameters Additional parameters supplied to the
   * operation.
   * 
   * @param {DeploymentProperties} [parameters.properties] Gets or sets the
   * deployment properties.
   * 
   * @param {string} [parameters.properties.template] Gets or sets the template
   * content. Use only one of Template or TemplateLink.
   * 
   * @param {TemplateLink} [parameters.properties.templateLink] Gets or sets
   * the URI referencing the template. Use only one of Template or
   * TemplateLink.
   * 
   * @param {string} [parameters.properties.templateLink.uri] URI referencing
   * the template.
   * 
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included it must match the ContentVersion in the template.
   * 
   * @param {string} [parameters.properties.parameters] Deployment parameters.
   * Use only one of Parameters or ParametersLink.
   * 
   * @param {ParametersLink} [parameters.properties.parametersLink] Gets or
   * sets the URI referencing the parameters. Use only one of Parameters or
   * ParametersLink.
   * 
   * @param {string} [parameters.properties.parametersLink.uri] URI referencing
   * the template.
   * 
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included it must match the ContentVersion in the template.
   * 
   * @param {DeploymentMode} [parameters.properties.mode] Gets or sets the
   * deployment mode.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.createOrUpdate = function(resourceGroupName, deploymentName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.properties !== null && parameters.properties !== undefined) {
      if (parameters.properties.parametersLink !== null && parameters.properties.parametersLink !== undefined) {
        if (parameters.properties.parametersLink.uri === null || parameters.properties.parametersLink.uri === undefined) {
          return callback(new Error('parameters.properties.parametersLink.uri cannot be null.'));
        }
      }
      if (parameters.properties.templateLink !== null && parameters.properties.templateLink !== undefined) {
        if (parameters.properties.templateLink.uri === null || parameters.properties.templateLink.uri === undefined) {
          return callback(new Error('parameters.properties.templateLink.uri cannot be null.'));
        }
      }
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/deployments/';
    url2 = url2 + encodeURIComponent(deploymentName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var deploymentValue = {};
    requestDoc = deploymentValue;
    
    if (parameters.properties !== null && parameters.properties !== undefined) {
      var propertiesValue = {};
      deploymentValue['properties'] = propertiesValue;
      
      if (parameters.properties.template !== null && parameters.properties.template !== undefined) {
        propertiesValue['template'] = parameters.properties.template;
      }
      
      if (parameters.properties.templateLink !== null && parameters.properties.templateLink !== undefined) {
        var templateLinkValue = {};
        propertiesValue['templateLink'] = templateLinkValue;
        
        templateLinkValue['uri'] = parameters.properties.templateLink.uri;
        
        if (parameters.properties.templateLink.contentVersion !== null && parameters.properties.templateLink.contentVersion !== undefined) {
          templateLinkValue['contentVersion'] = parameters.properties.templateLink.contentVersion;
        }
      }
      
      if (parameters.properties.parameters !== null && parameters.properties.parameters !== undefined) {
        propertiesValue['parameters'] = parameters.properties.parameters;
      }
      
      if (parameters.properties.parametersLink !== null && parameters.properties.parametersLink !== undefined) {
        var parametersLinkValue = {};
        propertiesValue['parametersLink'] = parametersLinkValue;
        
        parametersLinkValue['uri'] = parameters.properties.parametersLink.uri;
        
        if (parameters.properties.parametersLink.contentVersion !== null && parameters.properties.parametersLink.contentVersion !== undefined) {
          parametersLinkValue['contentVersion'] = parameters.properties.parametersLink.contentVersion;
        }
      }
      
      if (parameters.properties.mode !== null && parameters.properties.mode !== undefined) {
        propertiesValue['mode'] = parameters.properties.mode !== null && parameters.properties.mode !== undefined ? parameters.properties.mode.toString() : 'Incremental';
      }
    }
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 201) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var deploymentInstance = {};
          result.deployment = deploymentInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            deploymentInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            deploymentInstance.name = nameInstance;
          }
          
          var propertiesValue2 = responseDoc['properties'];
          if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
            var propertiesInstance = { dependencies: [], providers: [], validatedResources: [] };
            deploymentInstance.properties = propertiesInstance;
            
            var provisioningStateValue = propertiesValue2['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              propertiesInstance.provisioningState = provisioningStateInstance;
            }
            
            var correlationIdValue = propertiesValue2['correlationId'];
            if (correlationIdValue !== null && correlationIdValue !== undefined) {
              var correlationIdInstance = correlationIdValue;
              propertiesInstance.correlationId = correlationIdInstance;
            }
            
            var timestampValue = propertiesValue2['timestamp'];
            if (timestampValue !== null && timestampValue !== undefined) {
              var timestampInstance = timestampValue;
              propertiesInstance.timestamp = timestampInstance;
            }
            
            var durationValue = propertiesValue2['duration'];
            if (durationValue !== null && durationValue !== undefined) {
              var durationInstance = moment.duration(durationValue);
              propertiesInstance.duration = durationInstance;
            }
            
            var outputsValue = propertiesValue2['outputs'];
            if (outputsValue !== null && outputsValue !== undefined) {
              var outputsInstance = outputsValue;
              propertiesInstance.outputs = outputsInstance;
            }
            
            var providersArray = propertiesValue2['providers'];
            if (providersArray !== null && providersArray !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < providersArray.length; loweredIndex1 = loweredIndex1 + 1) {
                var providersValue = providersArray[loweredIndex1];
                var providerInstance = { resourceTypes: [] };
                propertiesInstance.providers.push(providerInstance);
                
                var idValue2 = providersValue['id'];
                if (idValue2 !== null && idValue2 !== undefined) {
                  var idInstance2 = idValue2;
                  providerInstance.id = idInstance2;
                }
                
                var namespaceValue = providersValue['namespace'];
                if (namespaceValue !== null && namespaceValue !== undefined) {
                  var namespaceInstance = namespaceValue;
                  providerInstance.namespace = namespaceInstance;
                }
                
                var registrationStateValue = providersValue['registrationState'];
                if (registrationStateValue !== null && registrationStateValue !== undefined) {
                  var registrationStateInstance = registrationStateValue;
                  providerInstance.registrationState = registrationStateInstance;
                }
                
                var resourceTypesArray = providersValue['resourceTypes'];
                if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
                  for (var loweredIndex2 = 0; loweredIndex2 < resourceTypesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                    var resourceTypesValue = resourceTypesArray[loweredIndex2];
                    var providerResourceTypeInstance = { apiVersions: [], locations: [], properties: {} };
                    providerInstance.resourceTypes.push(providerResourceTypeInstance);
                    
                    var resourceTypeValue = resourceTypesValue['resourceType'];
                    if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                      var resourceTypeInstance = resourceTypeValue;
                      providerResourceTypeInstance.name = resourceTypeInstance;
                    }
                    
                    var locationsArray = resourceTypesValue['locations'];
                    if (locationsArray !== null && locationsArray !== undefined) {
                      for (var loweredIndex3 = 0; loweredIndex3 < locationsArray.length; loweredIndex3 = loweredIndex3 + 1) {
                        var locationsValue = locationsArray[loweredIndex3];
                        providerResourceTypeInstance.locations.push(locationsValue);
                      }
                    }
                    
                    var apiVersionsArray = resourceTypesValue['apiVersions'];
                    if (apiVersionsArray !== null && apiVersionsArray !== undefined) {
                      for (var loweredIndex4 = 0; loweredIndex4 < apiVersionsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                        var apiVersionsValue = apiVersionsArray[loweredIndex4];
                        providerResourceTypeInstance.apiVersions.push(apiVersionsValue);
                      }
                    }
                    
                    var propertiesSequenceElement = resourceTypesValue['properties'];
                    if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                      for (var property in propertiesSequenceElement) {
                        var propertiesKey = property;
                        var propertiesValue3 = propertiesSequenceElement[property];
                        providerResourceTypeInstance.properties[propertiesKey] = propertiesValue3;
                      }
                    }
                  }
                }
              }
            }
            
            var dependenciesArray = propertiesValue2['dependencies'];
            if (dependenciesArray !== null && dependenciesArray !== undefined) {
              for (var loweredIndex5 = 0; loweredIndex5 < dependenciesArray.length; loweredIndex5 = loweredIndex5 + 1) {
                var dependenciesValue = dependenciesArray[loweredIndex5];
                var dependencyInstance = { dependsOn: [] };
                propertiesInstance.dependencies.push(dependencyInstance);
                
                var dependsOnArray = dependenciesValue['dependsOn'];
                if (dependsOnArray !== null && dependsOnArray !== undefined) {
                  for (var loweredIndex6 = 0; loweredIndex6 < dependsOnArray.length; loweredIndex6 = loweredIndex6 + 1) {
                    var dependsOnValue = dependsOnArray[loweredIndex6];
                    var basicDependencyInstance = {};
                    dependencyInstance.dependsOn.push(basicDependencyInstance);
                    
                    var idValue3 = dependsOnValue['id'];
                    if (idValue3 !== null && idValue3 !== undefined) {
                      var idInstance3 = idValue3;
                      basicDependencyInstance.id = idInstance3;
                    }
                    
                    var resourceTypeValue2 = dependsOnValue['resourceType'];
                    if (resourceTypeValue2 !== null && resourceTypeValue2 !== undefined) {
                      var resourceTypeInstance2 = resourceTypeValue2;
                      basicDependencyInstance.resourceType = resourceTypeInstance2;
                    }
                    
                    var resourceNameValue = dependsOnValue['resourceName'];
                    if (resourceNameValue !== null && resourceNameValue !== undefined) {
                      var resourceNameInstance = resourceNameValue;
                      basicDependencyInstance.resourceName = resourceNameInstance;
                    }
                  }
                }
                
                var idValue4 = dependenciesValue['id'];
                if (idValue4 !== null && idValue4 !== undefined) {
                  var idInstance4 = idValue4;
                  dependencyInstance.id = idInstance4;
                }
                
                var resourceTypeValue3 = dependenciesValue['resourceType'];
                if (resourceTypeValue3 !== null && resourceTypeValue3 !== undefined) {
                  var resourceTypeInstance3 = resourceTypeValue3;
                  dependencyInstance.resourceType = resourceTypeInstance3;
                }
                
                var resourceNameValue2 = dependenciesValue['resourceName'];
                if (resourceNameValue2 !== null && resourceNameValue2 !== undefined) {
                  var resourceNameInstance2 = resourceNameValue2;
                  dependencyInstance.resourceName = resourceNameInstance2;
                }
              }
            }
            
            var validatedResourcesArray = propertiesValue2['validatedResources'];
            if (validatedResourcesArray !== null && validatedResourcesArray !== undefined) {
              for (var loweredIndex7 = 0; loweredIndex7 < validatedResourcesArray.length; loweredIndex7 = loweredIndex7 + 1) {
                var validatedResourcesValue = validatedResourcesArray[loweredIndex7];
                var deploymentPreFlightResourceInstance = { dependsOn: [], tags: {} };
                propertiesInstance.validatedResources.push(deploymentPreFlightResourceInstance);
                
                var apiVersionValue = validatedResourcesValue['apiVersion'];
                if (apiVersionValue !== null && apiVersionValue !== undefined) {
                  var apiVersionInstance = apiVersionValue;
                  deploymentPreFlightResourceInstance.apiVersion = apiVersionInstance;
                }
                
                var dependsOnArray2 = validatedResourcesValue['dependsOn'];
                if (dependsOnArray2 !== null && dependsOnArray2 !== undefined) {
                  for (var loweredIndex8 = 0; loweredIndex8 < dependsOnArray2.length; loweredIndex8 = loweredIndex8 + 1) {
                    var dependsOnValue2 = dependsOnArray2[loweredIndex8];
                    deploymentPreFlightResourceInstance.dependsOn.push(dependsOnValue2);
                  }
                }
                
                var propertiesValue4 = validatedResourcesValue['properties'];
                if (propertiesValue4 !== null && propertiesValue4 !== undefined) {
                  var propertiesInstance2 = propertiesValue4;
                  deploymentPreFlightResourceInstance.properties = propertiesInstance2;
                }
                
                var provisioningStateValue2 = validatedResourcesValue['provisioningState'];
                if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
                  var provisioningStateInstance2 = provisioningStateValue2;
                  deploymentPreFlightResourceInstance.provisioningState = provisioningStateInstance2;
                }
                
                var planValue = validatedResourcesValue['plan'];
                if (planValue !== null && planValue !== undefined) {
                  var planInstance = {};
                  deploymentPreFlightResourceInstance.plan = planInstance;
                  
                  var nameValue2 = planValue['name'];
                  if (nameValue2 !== null && nameValue2 !== undefined) {
                    var nameInstance2 = nameValue2;
                    planInstance.name = nameInstance2;
                  }
                  
                  var publisherValue = planValue['publisher'];
                  if (publisherValue !== null && publisherValue !== undefined) {
                    var publisherInstance = publisherValue;
                    planInstance.publisher = publisherInstance;
                  }
                  
                  var productValue = planValue['product'];
                  if (productValue !== null && productValue !== undefined) {
                    var productInstance = productValue;
                    planInstance.product = productInstance;
                  }
                  
                  var promotionCodeValue = planValue['promotionCode'];
                  if (promotionCodeValue !== null && promotionCodeValue !== undefined) {
                    var promotionCodeInstance = promotionCodeValue;
                    planInstance.promotionCode = promotionCodeInstance;
                  }
                }
                
                var idValue5 = validatedResourcesValue['id'];
                if (idValue5 !== null && idValue5 !== undefined) {
                  var idInstance5 = idValue5;
                  deploymentPreFlightResourceInstance.id = idInstance5;
                }
                
                var nameValue3 = validatedResourcesValue['name'];
                if (nameValue3 !== null && nameValue3 !== undefined) {
                  var nameInstance3 = nameValue3;
                  deploymentPreFlightResourceInstance.name = nameInstance3;
                }
                
                var typeValue = validatedResourcesValue['type'];
                if (typeValue !== null && typeValue !== undefined) {
                  var typeInstance = typeValue;
                  deploymentPreFlightResourceInstance.type = typeInstance;
                }
                
                var locationValue = validatedResourcesValue['location'];
                if (locationValue !== null && locationValue !== undefined) {
                  var locationInstance = locationValue;
                  deploymentPreFlightResourceInstance.location = locationInstance;
                }
                
                var tagsSequenceElement = validatedResourcesValue['tags'];
                if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                  for (var property2 in tagsSequenceElement) {
                    var tagsKey = property2;
                    var tagsValue = tagsSequenceElement[property2];
                    deploymentPreFlightResourceInstance.tags[tagsKey] = tagsValue;
                  }
                }
              }
            }
            
            var templateValue = propertiesValue2['template'];
            if (templateValue !== null && templateValue !== undefined) {
              var templateInstance = templateValue;
              propertiesInstance.template = templateInstance;
            }
            
            var templateLinkValue2 = propertiesValue2['templateLink'];
            if (templateLinkValue2 !== null && templateLinkValue2 !== undefined) {
              var templateLinkInstance = {};
              propertiesInstance.templateLink = templateLinkInstance;
              
              var uriValue = templateLinkValue2['uri'];
              if (uriValue !== null && uriValue !== undefined) {
                var uriInstance = uriValue;
                templateLinkInstance.uri = uriInstance;
              }
              
              var contentVersionValue = templateLinkValue2['contentVersion'];
              if (contentVersionValue !== null && contentVersionValue !== undefined) {
                var contentVersionInstance = contentVersionValue;
                templateLinkInstance.contentVersion = contentVersionInstance;
              }
            }
            
            var parametersValue = propertiesValue2['parameters'];
            if (parametersValue !== null && parametersValue !== undefined) {
              var parametersInstance = parametersValue;
              propertiesInstance.parameters = parametersInstance;
            }
            
            var parametersLinkValue2 = propertiesValue2['parametersLink'];
            if (parametersLinkValue2 !== null && parametersLinkValue2 !== undefined) {
              var parametersLinkInstance = {};
              propertiesInstance.parametersLink = parametersLinkInstance;
              
              var uriValue2 = parametersLinkValue2['uri'];
              if (uriValue2 !== null && uriValue2 !== undefined) {
                var uriInstance2 = uriValue2;
                parametersLinkInstance.uri = uriInstance2;
              }
              
              var contentVersionValue2 = parametersLinkValue2['contentVersion'];
              if (contentVersionValue2 !== null && contentVersionValue2 !== undefined) {
                var contentVersionInstance2 = contentVersionValue2;
                parametersLinkInstance.contentVersion = contentVersionInstance2;
              }
            }
            
            var modeValue = propertiesValue2['mode'];
            if (modeValue !== null && modeValue !== undefined) {
              var modeInstance = modeValue;
              propertiesInstance.mode = modeInstance;
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Delete deployment and all of its resources.
   * 
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   * 
   * @param {string} deploymentName The name of the deployment to be deleted.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.deleteMethod = function(resourceGroupName, deploymentName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.deployments.beginDeleting(resourceGroupName, deploymentName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = result.retryAfter;
      if (delayInSeconds === 0) {
        delayInSeconds = 30;
      }
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getLongRunningOperationStatus(result.operationStatusLink, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                return callback(null, result2);
              } else {
                delayInSeconds = result2.retryAfter;
                if (delayInSeconds === 0) {
                  delayInSeconds = 15;
                }
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Get a deployment.
   * 
   * @param {string} resourceGroupName The name of the resource group to get.
   * The name is case insensitive.
   * 
   * @param {string} deploymentName The name of the deployment.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.get = function(resourceGroupName, deploymentName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/deployments/';
    url2 = url2 + encodeURIComponent(deploymentName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var deploymentInstance = {};
          result.deployment = deploymentInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            deploymentInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            deploymentInstance.name = nameInstance;
          }
          
          var propertiesValue = responseDoc['properties'];
          if (propertiesValue !== null && propertiesValue !== undefined) {
            var propertiesInstance = { dependencies: [], providers: [], validatedResources: [] };
            deploymentInstance.properties = propertiesInstance;
            
            var provisioningStateValue = propertiesValue['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              propertiesInstance.provisioningState = provisioningStateInstance;
            }
            
            var correlationIdValue = propertiesValue['correlationId'];
            if (correlationIdValue !== null && correlationIdValue !== undefined) {
              var correlationIdInstance = correlationIdValue;
              propertiesInstance.correlationId = correlationIdInstance;
            }
            
            var timestampValue = propertiesValue['timestamp'];
            if (timestampValue !== null && timestampValue !== undefined) {
              var timestampInstance = timestampValue;
              propertiesInstance.timestamp = timestampInstance;
            }
            
            var durationValue = propertiesValue['duration'];
            if (durationValue !== null && durationValue !== undefined) {
              var durationInstance = moment.duration(durationValue);
              propertiesInstance.duration = durationInstance;
            }
            
            var outputsValue = propertiesValue['outputs'];
            if (outputsValue !== null && outputsValue !== undefined) {
              var outputsInstance = outputsValue;
              propertiesInstance.outputs = outputsInstance;
            }
            
            var providersArray = propertiesValue['providers'];
            if (providersArray !== null && providersArray !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < providersArray.length; loweredIndex1 = loweredIndex1 + 1) {
                var providersValue = providersArray[loweredIndex1];
                var providerInstance = { resourceTypes: [] };
                propertiesInstance.providers.push(providerInstance);
                
                var idValue2 = providersValue['id'];
                if (idValue2 !== null && idValue2 !== undefined) {
                  var idInstance2 = idValue2;
                  providerInstance.id = idInstance2;
                }
                
                var namespaceValue = providersValue['namespace'];
                if (namespaceValue !== null && namespaceValue !== undefined) {
                  var namespaceInstance = namespaceValue;
                  providerInstance.namespace = namespaceInstance;
                }
                
                var registrationStateValue = providersValue['registrationState'];
                if (registrationStateValue !== null && registrationStateValue !== undefined) {
                  var registrationStateInstance = registrationStateValue;
                  providerInstance.registrationState = registrationStateInstance;
                }
                
                var resourceTypesArray = providersValue['resourceTypes'];
                if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
                  for (var loweredIndex2 = 0; loweredIndex2 < resourceTypesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                    var resourceTypesValue = resourceTypesArray[loweredIndex2];
                    var providerResourceTypeInstance = { apiVersions: [], locations: [], properties: {} };
                    providerInstance.resourceTypes.push(providerResourceTypeInstance);
                    
                    var resourceTypeValue = resourceTypesValue['resourceType'];
                    if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                      var resourceTypeInstance = resourceTypeValue;
                      providerResourceTypeInstance.name = resourceTypeInstance;
                    }
                    
                    var locationsArray = resourceTypesValue['locations'];
                    if (locationsArray !== null && locationsArray !== undefined) {
                      for (var loweredIndex3 = 0; loweredIndex3 < locationsArray.length; loweredIndex3 = loweredIndex3 + 1) {
                        var locationsValue = locationsArray[loweredIndex3];
                        providerResourceTypeInstance.locations.push(locationsValue);
                      }
                    }
                    
                    var apiVersionsArray = resourceTypesValue['apiVersions'];
                    if (apiVersionsArray !== null && apiVersionsArray !== undefined) {
                      for (var loweredIndex4 = 0; loweredIndex4 < apiVersionsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                        var apiVersionsValue = apiVersionsArray[loweredIndex4];
                        providerResourceTypeInstance.apiVersions.push(apiVersionsValue);
                      }
                    }
                    
                    var propertiesSequenceElement = resourceTypesValue['properties'];
                    if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                      for (var property in propertiesSequenceElement) {
                        var propertiesKey = property;
                        var propertiesValue2 = propertiesSequenceElement[property];
                        providerResourceTypeInstance.properties[propertiesKey] = propertiesValue2;
                      }
                    }
                  }
                }
              }
            }
            
            var dependenciesArray = propertiesValue['dependencies'];
            if (dependenciesArray !== null && dependenciesArray !== undefined) {
              for (var loweredIndex5 = 0; loweredIndex5 < dependenciesArray.length; loweredIndex5 = loweredIndex5 + 1) {
                var dependenciesValue = dependenciesArray[loweredIndex5];
                var dependencyInstance = { dependsOn: [] };
                propertiesInstance.dependencies.push(dependencyInstance);
                
                var dependsOnArray = dependenciesValue['dependsOn'];
                if (dependsOnArray !== null && dependsOnArray !== undefined) {
                  for (var loweredIndex6 = 0; loweredIndex6 < dependsOnArray.length; loweredIndex6 = loweredIndex6 + 1) {
                    var dependsOnValue = dependsOnArray[loweredIndex6];
                    var basicDependencyInstance = {};
                    dependencyInstance.dependsOn.push(basicDependencyInstance);
                    
                    var idValue3 = dependsOnValue['id'];
                    if (idValue3 !== null && idValue3 !== undefined) {
                      var idInstance3 = idValue3;
                      basicDependencyInstance.id = idInstance3;
                    }
                    
                    var resourceTypeValue2 = dependsOnValue['resourceType'];
                    if (resourceTypeValue2 !== null && resourceTypeValue2 !== undefined) {
                      var resourceTypeInstance2 = resourceTypeValue2;
                      basicDependencyInstance.resourceType = resourceTypeInstance2;
                    }
                    
                    var resourceNameValue = dependsOnValue['resourceName'];
                    if (resourceNameValue !== null && resourceNameValue !== undefined) {
                      var resourceNameInstance = resourceNameValue;
                      basicDependencyInstance.resourceName = resourceNameInstance;
                    }
                  }
                }
                
                var idValue4 = dependenciesValue['id'];
                if (idValue4 !== null && idValue4 !== undefined) {
                  var idInstance4 = idValue4;
                  dependencyInstance.id = idInstance4;
                }
                
                var resourceTypeValue3 = dependenciesValue['resourceType'];
                if (resourceTypeValue3 !== null && resourceTypeValue3 !== undefined) {
                  var resourceTypeInstance3 = resourceTypeValue3;
                  dependencyInstance.resourceType = resourceTypeInstance3;
                }
                
                var resourceNameValue2 = dependenciesValue['resourceName'];
                if (resourceNameValue2 !== null && resourceNameValue2 !== undefined) {
                  var resourceNameInstance2 = resourceNameValue2;
                  dependencyInstance.resourceName = resourceNameInstance2;
                }
              }
            }
            
            var validatedResourcesArray = propertiesValue['validatedResources'];
            if (validatedResourcesArray !== null && validatedResourcesArray !== undefined) {
              for (var loweredIndex7 = 0; loweredIndex7 < validatedResourcesArray.length; loweredIndex7 = loweredIndex7 + 1) {
                var validatedResourcesValue = validatedResourcesArray[loweredIndex7];
                var deploymentPreFlightResourceInstance = { dependsOn: [], tags: {} };
                propertiesInstance.validatedResources.push(deploymentPreFlightResourceInstance);
                
                var apiVersionValue = validatedResourcesValue['apiVersion'];
                if (apiVersionValue !== null && apiVersionValue !== undefined) {
                  var apiVersionInstance = apiVersionValue;
                  deploymentPreFlightResourceInstance.apiVersion = apiVersionInstance;
                }
                
                var dependsOnArray2 = validatedResourcesValue['dependsOn'];
                if (dependsOnArray2 !== null && dependsOnArray2 !== undefined) {
                  for (var loweredIndex8 = 0; loweredIndex8 < dependsOnArray2.length; loweredIndex8 = loweredIndex8 + 1) {
                    var dependsOnValue2 = dependsOnArray2[loweredIndex8];
                    deploymentPreFlightResourceInstance.dependsOn.push(dependsOnValue2);
                  }
                }
                
                var propertiesValue3 = validatedResourcesValue['properties'];
                if (propertiesValue3 !== null && propertiesValue3 !== undefined) {
                  var propertiesInstance2 = propertiesValue3;
                  deploymentPreFlightResourceInstance.properties = propertiesInstance2;
                }
                
                var provisioningStateValue2 = validatedResourcesValue['provisioningState'];
                if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
                  var provisioningStateInstance2 = provisioningStateValue2;
                  deploymentPreFlightResourceInstance.provisioningState = provisioningStateInstance2;
                }
                
                var planValue = validatedResourcesValue['plan'];
                if (planValue !== null && planValue !== undefined) {
                  var planInstance = {};
                  deploymentPreFlightResourceInstance.plan = planInstance;
                  
                  var nameValue2 = planValue['name'];
                  if (nameValue2 !== null && nameValue2 !== undefined) {
                    var nameInstance2 = nameValue2;
                    planInstance.name = nameInstance2;
                  }
                  
                  var publisherValue = planValue['publisher'];
                  if (publisherValue !== null && publisherValue !== undefined) {
                    var publisherInstance = publisherValue;
                    planInstance.publisher = publisherInstance;
                  }
                  
                  var productValue = planValue['product'];
                  if (productValue !== null && productValue !== undefined) {
                    var productInstance = productValue;
                    planInstance.product = productInstance;
                  }
                  
                  var promotionCodeValue = planValue['promotionCode'];
                  if (promotionCodeValue !== null && promotionCodeValue !== undefined) {
                    var promotionCodeInstance = promotionCodeValue;
                    planInstance.promotionCode = promotionCodeInstance;
                  }
                }
                
                var idValue5 = validatedResourcesValue['id'];
                if (idValue5 !== null && idValue5 !== undefined) {
                  var idInstance5 = idValue5;
                  deploymentPreFlightResourceInstance.id = idInstance5;
                }
                
                var nameValue3 = validatedResourcesValue['name'];
                if (nameValue3 !== null && nameValue3 !== undefined) {
                  var nameInstance3 = nameValue3;
                  deploymentPreFlightResourceInstance.name = nameInstance3;
                }
                
                var typeValue = validatedResourcesValue['type'];
                if (typeValue !== null && typeValue !== undefined) {
                  var typeInstance = typeValue;
                  deploymentPreFlightResourceInstance.type = typeInstance;
                }
                
                var locationValue = validatedResourcesValue['location'];
                if (locationValue !== null && locationValue !== undefined) {
                  var locationInstance = locationValue;
                  deploymentPreFlightResourceInstance.location = locationInstance;
                }
                
                var tagsSequenceElement = validatedResourcesValue['tags'];
                if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                  for (var property2 in tagsSequenceElement) {
                    var tagsKey = property2;
                    var tagsValue = tagsSequenceElement[property2];
                    deploymentPreFlightResourceInstance.tags[tagsKey] = tagsValue;
                  }
                }
              }
            }
            
            var templateValue = propertiesValue['template'];
            if (templateValue !== null && templateValue !== undefined) {
              var templateInstance = templateValue;
              propertiesInstance.template = templateInstance;
            }
            
            var templateLinkValue = propertiesValue['templateLink'];
            if (templateLinkValue !== null && templateLinkValue !== undefined) {
              var templateLinkInstance = {};
              propertiesInstance.templateLink = templateLinkInstance;
              
              var uriValue = templateLinkValue['uri'];
              if (uriValue !== null && uriValue !== undefined) {
                var uriInstance = uriValue;
                templateLinkInstance.uri = uriInstance;
              }
              
              var contentVersionValue = templateLinkValue['contentVersion'];
              if (contentVersionValue !== null && contentVersionValue !== undefined) {
                var contentVersionInstance = contentVersionValue;
                templateLinkInstance.contentVersion = contentVersionInstance;
              }
            }
            
            var parametersValue = propertiesValue['parameters'];
            if (parametersValue !== null && parametersValue !== undefined) {
              var parametersInstance = parametersValue;
              propertiesInstance.parameters = parametersInstance;
            }
            
            var parametersLinkValue = propertiesValue['parametersLink'];
            if (parametersLinkValue !== null && parametersLinkValue !== undefined) {
              var parametersLinkInstance = {};
              propertiesInstance.parametersLink = parametersLinkInstance;
              
              var uriValue2 = parametersLinkValue['uri'];
              if (uriValue2 !== null && uriValue2 !== undefined) {
                var uriInstance2 = uriValue2;
                parametersLinkInstance.uri = uriInstance2;
              }
              
              var contentVersionValue2 = parametersLinkValue['contentVersion'];
              if (contentVersionValue2 !== null && contentVersionValue2 !== undefined) {
                var contentVersionInstance2 = contentVersionValue2;
                parametersLinkInstance.contentVersion = contentVersionInstance2;
              }
            }
            
            var modeValue = propertiesValue['mode'];
            if (modeValue !== null && modeValue !== undefined) {
              var modeInstance = modeValue;
              propertiesInstance.mode = modeInstance;
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a list of deployments.
   * 
   * @param {string} resourceGroupName The name of the resource group to filter
   * by. The name is case insensitive.
   * 
   * @param {DeploymentListParameters} [parametersOrCallback] Query parameters.
   * If null is passed returns all deployments.
   * 
   * @param {number} [parametersOrCallback.top] Get or sets the number of
   * records to return. Optional.
   * 
   * @param {string} [parametersOrCallback.provisioningState] Get or sets the
   * provisioning state to filer by. Optional.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.list = function(resourceGroupName, parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/';
    url2 = url2 + 'resourcegroups/' + encodeURIComponent(resourceGroupName) + '/';
    url2 = url2 + 'deployments/';
    var queryParameters = [];
    var odataFilter = [];
    if (parameters !== null && parameters !== undefined && parameters.provisioningState !== null && parameters.provisioningState !== undefined) {
      odataFilter.push('provisioningState eq \'' + encodeURIComponent(parameters.provisioningState) + '\'');
    }
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(null));
    }
    if (parameters !== null && parameters !== undefined && parameters.top !== null && parameters.top !== undefined) {
      queryParameters.push('$top=' + encodeURIComponent(parameters.top.toString()));
    }
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { deployments: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var deploymentExtendedInstance = {};
              result.deployments.push(deploymentExtendedInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                deploymentExtendedInstance.id = idInstance;
              }
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                deploymentExtendedInstance.name = nameInstance;
              }
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var propertiesInstance = { dependencies: [], providers: [], validatedResources: [] };
                deploymentExtendedInstance.properties = propertiesInstance;
                
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  propertiesInstance.provisioningState = provisioningStateInstance;
                }
                
                var correlationIdValue = propertiesValue['correlationId'];
                if (correlationIdValue !== null && correlationIdValue !== undefined) {
                  var correlationIdInstance = correlationIdValue;
                  propertiesInstance.correlationId = correlationIdInstance;
                }
                
                var timestampValue = propertiesValue['timestamp'];
                if (timestampValue !== null && timestampValue !== undefined) {
                  var timestampInstance = timestampValue;
                  propertiesInstance.timestamp = timestampInstance;
                }
                
                var durationValue = propertiesValue['duration'];
                if (durationValue !== null && durationValue !== undefined) {
                  var durationInstance = moment.duration(durationValue);
                  propertiesInstance.duration = durationInstance;
                }
                
                var outputsValue = propertiesValue['outputs'];
                if (outputsValue !== null && outputsValue !== undefined) {
                  var outputsInstance = outputsValue;
                  propertiesInstance.outputs = outputsInstance;
                }
                
                var providersArray = propertiesValue['providers'];
                if (providersArray !== null && providersArray !== undefined) {
                  for (var loweredIndex2 = 0; loweredIndex2 < providersArray.length; loweredIndex2 = loweredIndex2 + 1) {
                    var providersValue = providersArray[loweredIndex2];
                    var providerInstance = { resourceTypes: [] };
                    propertiesInstance.providers.push(providerInstance);
                    
                    var idValue2 = providersValue['id'];
                    if (idValue2 !== null && idValue2 !== undefined) {
                      var idInstance2 = idValue2;
                      providerInstance.id = idInstance2;
                    }
                    
                    var namespaceValue = providersValue['namespace'];
                    if (namespaceValue !== null && namespaceValue !== undefined) {
                      var namespaceInstance = namespaceValue;
                      providerInstance.namespace = namespaceInstance;
                    }
                    
                    var registrationStateValue = providersValue['registrationState'];
                    if (registrationStateValue !== null && registrationStateValue !== undefined) {
                      var registrationStateInstance = registrationStateValue;
                      providerInstance.registrationState = registrationStateInstance;
                    }
                    
                    var resourceTypesArray = providersValue['resourceTypes'];
                    if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
                      for (var loweredIndex3 = 0; loweredIndex3 < resourceTypesArray.length; loweredIndex3 = loweredIndex3 + 1) {
                        var resourceTypesValue = resourceTypesArray[loweredIndex3];
                        var providerResourceTypeInstance = { apiVersions: [], locations: [], properties: {} };
                        providerInstance.resourceTypes.push(providerResourceTypeInstance);
                        
                        var resourceTypeValue = resourceTypesValue['resourceType'];
                        if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                          var resourceTypeInstance = resourceTypeValue;
                          providerResourceTypeInstance.name = resourceTypeInstance;
                        }
                        
                        var locationsArray = resourceTypesValue['locations'];
                        if (locationsArray !== null && locationsArray !== undefined) {
                          for (var loweredIndex4 = 0; loweredIndex4 < locationsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                            var locationsValue = locationsArray[loweredIndex4];
                            providerResourceTypeInstance.locations.push(locationsValue);
                          }
                        }
                        
                        var apiVersionsArray = resourceTypesValue['apiVersions'];
                        if (apiVersionsArray !== null && apiVersionsArray !== undefined) {
                          for (var loweredIndex5 = 0; loweredIndex5 < apiVersionsArray.length; loweredIndex5 = loweredIndex5 + 1) {
                            var apiVersionsValue = apiVersionsArray[loweredIndex5];
                            providerResourceTypeInstance.apiVersions.push(apiVersionsValue);
                          }
                        }
                        
                        var propertiesSequenceElement = resourceTypesValue['properties'];
                        if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                          for (var property in propertiesSequenceElement) {
                            var propertiesKey = property;
                            var propertiesValue2 = propertiesSequenceElement[property];
                            providerResourceTypeInstance.properties[propertiesKey] = propertiesValue2;
                          }
                        }
                      }
                    }
                  }
                }
                
                var dependenciesArray = propertiesValue['dependencies'];
                if (dependenciesArray !== null && dependenciesArray !== undefined) {
                  for (var loweredIndex6 = 0; loweredIndex6 < dependenciesArray.length; loweredIndex6 = loweredIndex6 + 1) {
                    var dependenciesValue = dependenciesArray[loweredIndex6];
                    var dependencyInstance = { dependsOn: [] };
                    propertiesInstance.dependencies.push(dependencyInstance);
                    
                    var dependsOnArray = dependenciesValue['dependsOn'];
                    if (dependsOnArray !== null && dependsOnArray !== undefined) {
                      for (var loweredIndex7 = 0; loweredIndex7 < dependsOnArray.length; loweredIndex7 = loweredIndex7 + 1) {
                        var dependsOnValue = dependsOnArray[loweredIndex7];
                        var basicDependencyInstance = {};
                        dependencyInstance.dependsOn.push(basicDependencyInstance);
                        
                        var idValue3 = dependsOnValue['id'];
                        if (idValue3 !== null && idValue3 !== undefined) {
                          var idInstance3 = idValue3;
                          basicDependencyInstance.id = idInstance3;
                        }
                        
                        var resourceTypeValue2 = dependsOnValue['resourceType'];
                        if (resourceTypeValue2 !== null && resourceTypeValue2 !== undefined) {
                          var resourceTypeInstance2 = resourceTypeValue2;
                          basicDependencyInstance.resourceType = resourceTypeInstance2;
                        }
                        
                        var resourceNameValue = dependsOnValue['resourceName'];
                        if (resourceNameValue !== null && resourceNameValue !== undefined) {
                          var resourceNameInstance = resourceNameValue;
                          basicDependencyInstance.resourceName = resourceNameInstance;
                        }
                      }
                    }
                    
                    var idValue4 = dependenciesValue['id'];
                    if (idValue4 !== null && idValue4 !== undefined) {
                      var idInstance4 = idValue4;
                      dependencyInstance.id = idInstance4;
                    }
                    
                    var resourceTypeValue3 = dependenciesValue['resourceType'];
                    if (resourceTypeValue3 !== null && resourceTypeValue3 !== undefined) {
                      var resourceTypeInstance3 = resourceTypeValue3;
                      dependencyInstance.resourceType = resourceTypeInstance3;
                    }
                    
                    var resourceNameValue2 = dependenciesValue['resourceName'];
                    if (resourceNameValue2 !== null && resourceNameValue2 !== undefined) {
                      var resourceNameInstance2 = resourceNameValue2;
                      dependencyInstance.resourceName = resourceNameInstance2;
                    }
                  }
                }
                
                var validatedResourcesArray = propertiesValue['validatedResources'];
                if (validatedResourcesArray !== null && validatedResourcesArray !== undefined) {
                  for (var loweredIndex8 = 0; loweredIndex8 < validatedResourcesArray.length; loweredIndex8 = loweredIndex8 + 1) {
                    var validatedResourcesValue = validatedResourcesArray[loweredIndex8];
                    var deploymentPreFlightResourceInstance = { dependsOn: [], tags: {} };
                    propertiesInstance.validatedResources.push(deploymentPreFlightResourceInstance);
                    
                    var apiVersionValue = validatedResourcesValue['apiVersion'];
                    if (apiVersionValue !== null && apiVersionValue !== undefined) {
                      var apiVersionInstance = apiVersionValue;
                      deploymentPreFlightResourceInstance.apiVersion = apiVersionInstance;
                    }
                    
                    var dependsOnArray2 = validatedResourcesValue['dependsOn'];
                    if (dependsOnArray2 !== null && dependsOnArray2 !== undefined) {
                      for (var loweredIndex9 = 0; loweredIndex9 < dependsOnArray2.length; loweredIndex9 = loweredIndex9 + 1) {
                        var dependsOnValue2 = dependsOnArray2[loweredIndex9];
                        deploymentPreFlightResourceInstance.dependsOn.push(dependsOnValue2);
                      }
                    }
                    
                    var propertiesValue3 = validatedResourcesValue['properties'];
                    if (propertiesValue3 !== null && propertiesValue3 !== undefined) {
                      var propertiesInstance2 = propertiesValue3;
                      deploymentPreFlightResourceInstance.properties = propertiesInstance2;
                    }
                    
                    var provisioningStateValue2 = validatedResourcesValue['provisioningState'];
                    if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
                      var provisioningStateInstance2 = provisioningStateValue2;
                      deploymentPreFlightResourceInstance.provisioningState = provisioningStateInstance2;
                    }
                    
                    var planValue = validatedResourcesValue['plan'];
                    if (planValue !== null && planValue !== undefined) {
                      var planInstance = {};
                      deploymentPreFlightResourceInstance.plan = planInstance;
                      
                      var nameValue2 = planValue['name'];
                      if (nameValue2 !== null && nameValue2 !== undefined) {
                        var nameInstance2 = nameValue2;
                        planInstance.name = nameInstance2;
                      }
                      
                      var publisherValue = planValue['publisher'];
                      if (publisherValue !== null && publisherValue !== undefined) {
                        var publisherInstance = publisherValue;
                        planInstance.publisher = publisherInstance;
                      }
                      
                      var productValue = planValue['product'];
                      if (productValue !== null && productValue !== undefined) {
                        var productInstance = productValue;
                        planInstance.product = productInstance;
                      }
                      
                      var promotionCodeValue = planValue['promotionCode'];
                      if (promotionCodeValue !== null && promotionCodeValue !== undefined) {
                        var promotionCodeInstance = promotionCodeValue;
                        planInstance.promotionCode = promotionCodeInstance;
                      }
                    }
                    
                    var idValue5 = validatedResourcesValue['id'];
                    if (idValue5 !== null && idValue5 !== undefined) {
                      var idInstance5 = idValue5;
                      deploymentPreFlightResourceInstance.id = idInstance5;
                    }
                    
                    var nameValue3 = validatedResourcesValue['name'];
                    if (nameValue3 !== null && nameValue3 !== undefined) {
                      var nameInstance3 = nameValue3;
                      deploymentPreFlightResourceInstance.name = nameInstance3;
                    }
                    
                    var typeValue = validatedResourcesValue['type'];
                    if (typeValue !== null && typeValue !== undefined) {
                      var typeInstance = typeValue;
                      deploymentPreFlightResourceInstance.type = typeInstance;
                    }
                    
                    var locationValue = validatedResourcesValue['location'];
                    if (locationValue !== null && locationValue !== undefined) {
                      var locationInstance = locationValue;
                      deploymentPreFlightResourceInstance.location = locationInstance;
                    }
                    
                    var tagsSequenceElement = validatedResourcesValue['tags'];
                    if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                      for (var property2 in tagsSequenceElement) {
                        var tagsKey = property2;
                        var tagsValue = tagsSequenceElement[property2];
                        deploymentPreFlightResourceInstance.tags[tagsKey] = tagsValue;
                      }
                    }
                  }
                }
                
                var templateValue = propertiesValue['template'];
                if (templateValue !== null && templateValue !== undefined) {
                  var templateInstance = templateValue;
                  propertiesInstance.template = templateInstance;
                }
                
                var templateLinkValue = propertiesValue['templateLink'];
                if (templateLinkValue !== null && templateLinkValue !== undefined) {
                  var templateLinkInstance = {};
                  propertiesInstance.templateLink = templateLinkInstance;
                  
                  var uriValue = templateLinkValue['uri'];
                  if (uriValue !== null && uriValue !== undefined) {
                    var uriInstance = uriValue;
                    templateLinkInstance.uri = uriInstance;
                  }
                  
                  var contentVersionValue = templateLinkValue['contentVersion'];
                  if (contentVersionValue !== null && contentVersionValue !== undefined) {
                    var contentVersionInstance = contentVersionValue;
                    templateLinkInstance.contentVersion = contentVersionInstance;
                  }
                }
                
                var parametersValue = propertiesValue['parameters'];
                if (parametersValue !== null && parametersValue !== undefined) {
                  var parametersInstance = parametersValue;
                  propertiesInstance.parameters = parametersInstance;
                }
                
                var parametersLinkValue = propertiesValue['parametersLink'];
                if (parametersLinkValue !== null && parametersLinkValue !== undefined) {
                  var parametersLinkInstance = {};
                  propertiesInstance.parametersLink = parametersLinkInstance;
                  
                  var uriValue2 = parametersLinkValue['uri'];
                  if (uriValue2 !== null && uriValue2 !== undefined) {
                    var uriInstance2 = uriValue2;
                    parametersLinkInstance.uri = uriInstance2;
                  }
                  
                  var contentVersionValue2 = parametersLinkValue['contentVersion'];
                  if (contentVersionValue2 !== null && contentVersionValue2 !== undefined) {
                    var contentVersionInstance2 = contentVersionValue2;
                    parametersLinkInstance.contentVersion = contentVersionInstance2;
                  }
                }
                
                var modeValue = propertiesValue['mode'];
                if (modeValue !== null && modeValue !== undefined) {
                  var modeInstance = modeValue;
                  propertiesInstance.mode = modeInstance;
                }
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a list of deployments.
   * 
   * @param {string} nextLink NextLink from the previous successful call to
   * List operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.listNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { deployments: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var deploymentExtendedInstance = {};
              result.deployments.push(deploymentExtendedInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                deploymentExtendedInstance.id = idInstance;
              }
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                deploymentExtendedInstance.name = nameInstance;
              }
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var propertiesInstance = { dependencies: [], providers: [], validatedResources: [] };
                deploymentExtendedInstance.properties = propertiesInstance;
                
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  propertiesInstance.provisioningState = provisioningStateInstance;
                }
                
                var correlationIdValue = propertiesValue['correlationId'];
                if (correlationIdValue !== null && correlationIdValue !== undefined) {
                  var correlationIdInstance = correlationIdValue;
                  propertiesInstance.correlationId = correlationIdInstance;
                }
                
                var timestampValue = propertiesValue['timestamp'];
                if (timestampValue !== null && timestampValue !== undefined) {
                  var timestampInstance = timestampValue;
                  propertiesInstance.timestamp = timestampInstance;
                }
                
                var durationValue = propertiesValue['duration'];
                if (durationValue !== null && durationValue !== undefined) {
                  var durationInstance = moment.duration(durationValue);
                  propertiesInstance.duration = durationInstance;
                }
                
                var outputsValue = propertiesValue['outputs'];
                if (outputsValue !== null && outputsValue !== undefined) {
                  var outputsInstance = outputsValue;
                  propertiesInstance.outputs = outputsInstance;
                }
                
                var providersArray = propertiesValue['providers'];
                if (providersArray !== null && providersArray !== undefined) {
                  for (var loweredIndex2 = 0; loweredIndex2 < providersArray.length; loweredIndex2 = loweredIndex2 + 1) {
                    var providersValue = providersArray[loweredIndex2];
                    var providerInstance = { resourceTypes: [] };
                    propertiesInstance.providers.push(providerInstance);
                    
                    var idValue2 = providersValue['id'];
                    if (idValue2 !== null && idValue2 !== undefined) {
                      var idInstance2 = idValue2;
                      providerInstance.id = idInstance2;
                    }
                    
                    var namespaceValue = providersValue['namespace'];
                    if (namespaceValue !== null && namespaceValue !== undefined) {
                      var namespaceInstance = namespaceValue;
                      providerInstance.namespace = namespaceInstance;
                    }
                    
                    var registrationStateValue = providersValue['registrationState'];
                    if (registrationStateValue !== null && registrationStateValue !== undefined) {
                      var registrationStateInstance = registrationStateValue;
                      providerInstance.registrationState = registrationStateInstance;
                    }
                    
                    var resourceTypesArray = providersValue['resourceTypes'];
                    if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
                      for (var loweredIndex3 = 0; loweredIndex3 < resourceTypesArray.length; loweredIndex3 = loweredIndex3 + 1) {
                        var resourceTypesValue = resourceTypesArray[loweredIndex3];
                        var providerResourceTypeInstance = { apiVersions: [], locations: [], properties: {} };
                        providerInstance.resourceTypes.push(providerResourceTypeInstance);
                        
                        var resourceTypeValue = resourceTypesValue['resourceType'];
                        if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                          var resourceTypeInstance = resourceTypeValue;
                          providerResourceTypeInstance.name = resourceTypeInstance;
                        }
                        
                        var locationsArray = resourceTypesValue['locations'];
                        if (locationsArray !== null && locationsArray !== undefined) {
                          for (var loweredIndex4 = 0; loweredIndex4 < locationsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                            var locationsValue = locationsArray[loweredIndex4];
                            providerResourceTypeInstance.locations.push(locationsValue);
                          }
                        }
                        
                        var apiVersionsArray = resourceTypesValue['apiVersions'];
                        if (apiVersionsArray !== null && apiVersionsArray !== undefined) {
                          for (var loweredIndex5 = 0; loweredIndex5 < apiVersionsArray.length; loweredIndex5 = loweredIndex5 + 1) {
                            var apiVersionsValue = apiVersionsArray[loweredIndex5];
                            providerResourceTypeInstance.apiVersions.push(apiVersionsValue);
                          }
                        }
                        
                        var propertiesSequenceElement = resourceTypesValue['properties'];
                        if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                          for (var property in propertiesSequenceElement) {
                            var propertiesKey = property;
                            var propertiesValue2 = propertiesSequenceElement[property];
                            providerResourceTypeInstance.properties[propertiesKey] = propertiesValue2;
                          }
                        }
                      }
                    }
                  }
                }
                
                var dependenciesArray = propertiesValue['dependencies'];
                if (dependenciesArray !== null && dependenciesArray !== undefined) {
                  for (var loweredIndex6 = 0; loweredIndex6 < dependenciesArray.length; loweredIndex6 = loweredIndex6 + 1) {
                    var dependenciesValue = dependenciesArray[loweredIndex6];
                    var dependencyInstance = { dependsOn: [] };
                    propertiesInstance.dependencies.push(dependencyInstance);
                    
                    var dependsOnArray = dependenciesValue['dependsOn'];
                    if (dependsOnArray !== null && dependsOnArray !== undefined) {
                      for (var loweredIndex7 = 0; loweredIndex7 < dependsOnArray.length; loweredIndex7 = loweredIndex7 + 1) {
                        var dependsOnValue = dependsOnArray[loweredIndex7];
                        var basicDependencyInstance = {};
                        dependencyInstance.dependsOn.push(basicDependencyInstance);
                        
                        var idValue3 = dependsOnValue['id'];
                        if (idValue3 !== null && idValue3 !== undefined) {
                          var idInstance3 = idValue3;
                          basicDependencyInstance.id = idInstance3;
                        }
                        
                        var resourceTypeValue2 = dependsOnValue['resourceType'];
                        if (resourceTypeValue2 !== null && resourceTypeValue2 !== undefined) {
                          var resourceTypeInstance2 = resourceTypeValue2;
                          basicDependencyInstance.resourceType = resourceTypeInstance2;
                        }
                        
                        var resourceNameValue = dependsOnValue['resourceName'];
                        if (resourceNameValue !== null && resourceNameValue !== undefined) {
                          var resourceNameInstance = resourceNameValue;
                          basicDependencyInstance.resourceName = resourceNameInstance;
                        }
                      }
                    }
                    
                    var idValue4 = dependenciesValue['id'];
                    if (idValue4 !== null && idValue4 !== undefined) {
                      var idInstance4 = idValue4;
                      dependencyInstance.id = idInstance4;
                    }
                    
                    var resourceTypeValue3 = dependenciesValue['resourceType'];
                    if (resourceTypeValue3 !== null && resourceTypeValue3 !== undefined) {
                      var resourceTypeInstance3 = resourceTypeValue3;
                      dependencyInstance.resourceType = resourceTypeInstance3;
                    }
                    
                    var resourceNameValue2 = dependenciesValue['resourceName'];
                    if (resourceNameValue2 !== null && resourceNameValue2 !== undefined) {
                      var resourceNameInstance2 = resourceNameValue2;
                      dependencyInstance.resourceName = resourceNameInstance2;
                    }
                  }
                }
                
                var validatedResourcesArray = propertiesValue['validatedResources'];
                if (validatedResourcesArray !== null && validatedResourcesArray !== undefined) {
                  for (var loweredIndex8 = 0; loweredIndex8 < validatedResourcesArray.length; loweredIndex8 = loweredIndex8 + 1) {
                    var validatedResourcesValue = validatedResourcesArray[loweredIndex8];
                    var deploymentPreFlightResourceInstance = { dependsOn: [], tags: {} };
                    propertiesInstance.validatedResources.push(deploymentPreFlightResourceInstance);
                    
                    var apiVersionValue = validatedResourcesValue['apiVersion'];
                    if (apiVersionValue !== null && apiVersionValue !== undefined) {
                      var apiVersionInstance = apiVersionValue;
                      deploymentPreFlightResourceInstance.apiVersion = apiVersionInstance;
                    }
                    
                    var dependsOnArray2 = validatedResourcesValue['dependsOn'];
                    if (dependsOnArray2 !== null && dependsOnArray2 !== undefined) {
                      for (var loweredIndex9 = 0; loweredIndex9 < dependsOnArray2.length; loweredIndex9 = loweredIndex9 + 1) {
                        var dependsOnValue2 = dependsOnArray2[loweredIndex9];
                        deploymentPreFlightResourceInstance.dependsOn.push(dependsOnValue2);
                      }
                    }
                    
                    var propertiesValue3 = validatedResourcesValue['properties'];
                    if (propertiesValue3 !== null && propertiesValue3 !== undefined) {
                      var propertiesInstance2 = propertiesValue3;
                      deploymentPreFlightResourceInstance.properties = propertiesInstance2;
                    }
                    
                    var provisioningStateValue2 = validatedResourcesValue['provisioningState'];
                    if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
                      var provisioningStateInstance2 = provisioningStateValue2;
                      deploymentPreFlightResourceInstance.provisioningState = provisioningStateInstance2;
                    }
                    
                    var planValue = validatedResourcesValue['plan'];
                    if (planValue !== null && planValue !== undefined) {
                      var planInstance = {};
                      deploymentPreFlightResourceInstance.plan = planInstance;
                      
                      var nameValue2 = planValue['name'];
                      if (nameValue2 !== null && nameValue2 !== undefined) {
                        var nameInstance2 = nameValue2;
                        planInstance.name = nameInstance2;
                      }
                      
                      var publisherValue = planValue['publisher'];
                      if (publisherValue !== null && publisherValue !== undefined) {
                        var publisherInstance = publisherValue;
                        planInstance.publisher = publisherInstance;
                      }
                      
                      var productValue = planValue['product'];
                      if (productValue !== null && productValue !== undefined) {
                        var productInstance = productValue;
                        planInstance.product = productInstance;
                      }
                      
                      var promotionCodeValue = planValue['promotionCode'];
                      if (promotionCodeValue !== null && promotionCodeValue !== undefined) {
                        var promotionCodeInstance = promotionCodeValue;
                        planInstance.promotionCode = promotionCodeInstance;
                      }
                    }
                    
                    var idValue5 = validatedResourcesValue['id'];
                    if (idValue5 !== null && idValue5 !== undefined) {
                      var idInstance5 = idValue5;
                      deploymentPreFlightResourceInstance.id = idInstance5;
                    }
                    
                    var nameValue3 = validatedResourcesValue['name'];
                    if (nameValue3 !== null && nameValue3 !== undefined) {
                      var nameInstance3 = nameValue3;
                      deploymentPreFlightResourceInstance.name = nameInstance3;
                    }
                    
                    var typeValue = validatedResourcesValue['type'];
                    if (typeValue !== null && typeValue !== undefined) {
                      var typeInstance = typeValue;
                      deploymentPreFlightResourceInstance.type = typeInstance;
                    }
                    
                    var locationValue = validatedResourcesValue['location'];
                    if (locationValue !== null && locationValue !== undefined) {
                      var locationInstance = locationValue;
                      deploymentPreFlightResourceInstance.location = locationInstance;
                    }
                    
                    var tagsSequenceElement = validatedResourcesValue['tags'];
                    if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                      for (var property2 in tagsSequenceElement) {
                        var tagsKey = property2;
                        var tagsValue = tagsSequenceElement[property2];
                        deploymentPreFlightResourceInstance.tags[tagsKey] = tagsValue;
                      }
                    }
                  }
                }
                
                var templateValue = propertiesValue['template'];
                if (templateValue !== null && templateValue !== undefined) {
                  var templateInstance = templateValue;
                  propertiesInstance.template = templateInstance;
                }
                
                var templateLinkValue = propertiesValue['templateLink'];
                if (templateLinkValue !== null && templateLinkValue !== undefined) {
                  var templateLinkInstance = {};
                  propertiesInstance.templateLink = templateLinkInstance;
                  
                  var uriValue = templateLinkValue['uri'];
                  if (uriValue !== null && uriValue !== undefined) {
                    var uriInstance = uriValue;
                    templateLinkInstance.uri = uriInstance;
                  }
                  
                  var contentVersionValue = templateLinkValue['contentVersion'];
                  if (contentVersionValue !== null && contentVersionValue !== undefined) {
                    var contentVersionInstance = contentVersionValue;
                    templateLinkInstance.contentVersion = contentVersionInstance;
                  }
                }
                
                var parametersValue = propertiesValue['parameters'];
                if (parametersValue !== null && parametersValue !== undefined) {
                  var parametersInstance = parametersValue;
                  propertiesInstance.parameters = parametersInstance;
                }
                
                var parametersLinkValue = propertiesValue['parametersLink'];
                if (parametersLinkValue !== null && parametersLinkValue !== undefined) {
                  var parametersLinkInstance = {};
                  propertiesInstance.parametersLink = parametersLinkInstance;
                  
                  var uriValue2 = parametersLinkValue['uri'];
                  if (uriValue2 !== null && uriValue2 !== undefined) {
                    var uriInstance2 = uriValue2;
                    parametersLinkInstance.uri = uriInstance2;
                  }
                  
                  var contentVersionValue2 = parametersLinkValue['contentVersion'];
                  if (contentVersionValue2 !== null && contentVersionValue2 !== undefined) {
                    var contentVersionInstance2 = contentVersionValue2;
                    parametersLinkInstance.contentVersion = contentVersionInstance2;
                  }
                }
                
                var modeValue = propertiesValue['mode'];
                if (modeValue !== null && modeValue !== undefined) {
                  var modeInstance = modeValue;
                  propertiesInstance.mode = modeInstance;
                }
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Validate a deployment template.
   * 
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   * 
   * @param {string} deploymentName The name of the deployment.
   * 
   * @param {Deployment} parameters Deployment to validate.
   * 
   * @param {DeploymentProperties} [parameters.properties] Gets or sets the
   * deployment properties.
   * 
   * @param {string} [parameters.properties.template] Gets or sets the template
   * content. Use only one of Template or TemplateLink.
   * 
   * @param {TemplateLink} [parameters.properties.templateLink] Gets or sets
   * the URI referencing the template. Use only one of Template or
   * TemplateLink.
   * 
   * @param {string} [parameters.properties.templateLink.uri] URI referencing
   * the template.
   * 
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included it must match the ContentVersion in the template.
   * 
   * @param {string} [parameters.properties.parameters] Deployment parameters.
   * Use only one of Parameters or ParametersLink.
   * 
   * @param {ParametersLink} [parameters.properties.parametersLink] Gets or
   * sets the URI referencing the parameters. Use only one of Parameters or
   * ParametersLink.
   * 
   * @param {string} [parameters.properties.parametersLink.uri] URI referencing
   * the template.
   * 
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included it must match the ContentVersion in the template.
   * 
   * @param {DeploymentMode} [parameters.properties.mode] Gets or sets the
   * deployment mode.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  DeploymentOperations.prototype.validate = function(resourceGroupName, deploymentName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (deploymentName === null || deploymentName === undefined) {
      return callback(new Error('deploymentName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.properties !== null && parameters.properties !== undefined) {
      if (parameters.properties.parametersLink !== null && parameters.properties.parametersLink !== undefined) {
        if (parameters.properties.parametersLink.uri === null || parameters.properties.parametersLink.uri === undefined) {
          return callback(new Error('parameters.properties.parametersLink.uri cannot be null.'));
        }
      }
      if (parameters.properties.templateLink !== null && parameters.properties.templateLink !== undefined) {
        if (parameters.properties.templateLink.uri === null || parameters.properties.templateLink.uri === undefined) {
          return callback(new Error('parameters.properties.templateLink.uri cannot be null.'));
        }
      }
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/microsoft.resources/deployments/';
    url2 = url2 + encodeURIComponent(deploymentName);
    url2 = url2 + '/validate';
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var deploymentValue = {};
    requestDoc = deploymentValue;
    
    if (parameters.properties !== null && parameters.properties !== undefined) {
      var propertiesValue = {};
      deploymentValue['properties'] = propertiesValue;
      
      if (parameters.properties.template !== null && parameters.properties.template !== undefined) {
        propertiesValue['template'] = parameters.properties.template;
      }
      
      if (parameters.properties.templateLink !== null && parameters.properties.templateLink !== undefined) {
        var templateLinkValue = {};
        propertiesValue['templateLink'] = templateLinkValue;
        
        templateLinkValue['uri'] = parameters.properties.templateLink.uri;
        
        if (parameters.properties.templateLink.contentVersion !== null && parameters.properties.templateLink.contentVersion !== undefined) {
          templateLinkValue['contentVersion'] = parameters.properties.templateLink.contentVersion;
        }
      }
      
      if (parameters.properties.parameters !== null && parameters.properties.parameters !== undefined) {
        propertiesValue['parameters'] = parameters.properties.parameters;
      }
      
      if (parameters.properties.parametersLink !== null && parameters.properties.parametersLink !== undefined) {
        var parametersLinkValue = {};
        propertiesValue['parametersLink'] = parametersLinkValue;
        
        parametersLinkValue['uri'] = parameters.properties.parametersLink.uri;
        
        if (parameters.properties.parametersLink.contentVersion !== null && parameters.properties.parametersLink.contentVersion !== undefined) {
          parametersLinkValue['contentVersion'] = parameters.properties.parametersLink.contentVersion;
        }
      }
      
      if (parameters.properties.mode !== null && parameters.properties.mode !== undefined) {
        propertiesValue['mode'] = parameters.properties.mode !== null && parameters.properties.mode !== undefined ? parameters.properties.mode.toString() : 'Incremental';
      }
    }
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 400) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var errorValue = responseDoc['error'];
          if (errorValue !== null && errorValue !== undefined) {
            var errorInstance = { details: [] };
            result.error = errorInstance;
            
            var detailsArray = errorValue['details'];
            if (detailsArray !== null && detailsArray !== undefined) {
              for (var loweredIndex1 = 0; loweredIndex1 < detailsArray.length; loweredIndex1 = loweredIndex1 + 1) {
                var detailsValue = detailsArray[loweredIndex1];
                var resourceManagementErrorInstance = {};
                errorInstance.details.push(resourceManagementErrorInstance);
                
                var codeValue = detailsValue['code'];
                if (codeValue !== null && codeValue !== undefined) {
                  var codeInstance = codeValue;
                  resourceManagementErrorInstance.code = codeInstance;
                }
                
                var messageValue = detailsValue['message'];
                if (messageValue !== null && messageValue !== undefined) {
                  var messageInstance = messageValue;
                  resourceManagementErrorInstance.message = messageInstance;
                }
                
                var targetValue = detailsValue['target'];
                if (targetValue !== null && targetValue !== undefined) {
                  var targetInstance = targetValue;
                  resourceManagementErrorInstance.target = targetInstance;
                }
              }
            }
            
            var codeValue2 = errorValue['code'];
            if (codeValue2 !== null && codeValue2 !== undefined) {
              var codeInstance2 = codeValue2;
              errorInstance.code = codeInstance2;
            }
            
            var messageValue2 = errorValue['message'];
            if (messageValue2 !== null && messageValue2 !== undefined) {
              var messageInstance2 = messageValue2;
              errorInstance.message = messageInstance2;
            }
            
            var targetValue2 = errorValue['target'];
            if (targetValue2 !== null && targetValue2 !== undefined) {
              var targetInstance2 = targetValue2;
              errorInstance.target = targetInstance2;
            }
          }
          
          var propertiesValue2 = responseDoc['properties'];
          if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
            var propertiesInstance = { dependencies: [], providers: [], validatedResources: [] };
            result.properties = propertiesInstance;
            
            var provisioningStateValue = propertiesValue2['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              propertiesInstance.provisioningState = provisioningStateInstance;
            }
            
            var correlationIdValue = propertiesValue2['correlationId'];
            if (correlationIdValue !== null && correlationIdValue !== undefined) {
              var correlationIdInstance = correlationIdValue;
              propertiesInstance.correlationId = correlationIdInstance;
            }
            
            var timestampValue = propertiesValue2['timestamp'];
            if (timestampValue !== null && timestampValue !== undefined) {
              var timestampInstance = timestampValue;
              propertiesInstance.timestamp = timestampInstance;
            }
            
            var durationValue = propertiesValue2['duration'];
            if (durationValue !== null && durationValue !== undefined) {
              var durationInstance = moment.duration(durationValue);
              propertiesInstance.duration = durationInstance;
            }
            
            var outputsValue = propertiesValue2['outputs'];
            if (outputsValue !== null && outputsValue !== undefined) {
              var outputsInstance = outputsValue;
              propertiesInstance.outputs = outputsInstance;
            }
            
            var providersArray = propertiesValue2['providers'];
            if (providersArray !== null && providersArray !== undefined) {
              for (var loweredIndex2 = 0; loweredIndex2 < providersArray.length; loweredIndex2 = loweredIndex2 + 1) {
                var providersValue = providersArray[loweredIndex2];
                var providerInstance = { resourceTypes: [] };
                propertiesInstance.providers.push(providerInstance);
                
                var idValue = providersValue['id'];
                if (idValue !== null && idValue !== undefined) {
                  var idInstance = idValue;
                  providerInstance.id = idInstance;
                }
                
                var namespaceValue = providersValue['namespace'];
                if (namespaceValue !== null && namespaceValue !== undefined) {
                  var namespaceInstance = namespaceValue;
                  providerInstance.namespace = namespaceInstance;
                }
                
                var registrationStateValue = providersValue['registrationState'];
                if (registrationStateValue !== null && registrationStateValue !== undefined) {
                  var registrationStateInstance = registrationStateValue;
                  providerInstance.registrationState = registrationStateInstance;
                }
                
                var resourceTypesArray = providersValue['resourceTypes'];
                if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
                  for (var loweredIndex3 = 0; loweredIndex3 < resourceTypesArray.length; loweredIndex3 = loweredIndex3 + 1) {
                    var resourceTypesValue = resourceTypesArray[loweredIndex3];
                    var providerResourceTypeInstance = { apiVersions: [], locations: [], properties: {} };
                    providerInstance.resourceTypes.push(providerResourceTypeInstance);
                    
                    var resourceTypeValue = resourceTypesValue['resourceType'];
                    if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                      var resourceTypeInstance = resourceTypeValue;
                      providerResourceTypeInstance.name = resourceTypeInstance;
                    }
                    
                    var locationsArray = resourceTypesValue['locations'];
                    if (locationsArray !== null && locationsArray !== undefined) {
                      for (var loweredIndex4 = 0; loweredIndex4 < locationsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                        var locationsValue = locationsArray[loweredIndex4];
                        providerResourceTypeInstance.locations.push(locationsValue);
                      }
                    }
                    
                    var apiVersionsArray = resourceTypesValue['apiVersions'];
                    if (apiVersionsArray !== null && apiVersionsArray !== undefined) {
                      for (var loweredIndex5 = 0; loweredIndex5 < apiVersionsArray.length; loweredIndex5 = loweredIndex5 + 1) {
                        var apiVersionsValue = apiVersionsArray[loweredIndex5];
                        providerResourceTypeInstance.apiVersions.push(apiVersionsValue);
                      }
                    }
                    
                    var propertiesSequenceElement = resourceTypesValue['properties'];
                    if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                      for (var property in propertiesSequenceElement) {
                        var propertiesKey = property;
                        var propertiesValue3 = propertiesSequenceElement[property];
                        providerResourceTypeInstance.properties[propertiesKey] = propertiesValue3;
                      }
                    }
                  }
                }
              }
            }
            
            var dependenciesArray = propertiesValue2['dependencies'];
            if (dependenciesArray !== null && dependenciesArray !== undefined) {
              for (var loweredIndex6 = 0; loweredIndex6 < dependenciesArray.length; loweredIndex6 = loweredIndex6 + 1) {
                var dependenciesValue = dependenciesArray[loweredIndex6];
                var dependencyInstance = { dependsOn: [] };
                propertiesInstance.dependencies.push(dependencyInstance);
                
                var dependsOnArray = dependenciesValue['dependsOn'];
                if (dependsOnArray !== null && dependsOnArray !== undefined) {
                  for (var loweredIndex7 = 0; loweredIndex7 < dependsOnArray.length; loweredIndex7 = loweredIndex7 + 1) {
                    var dependsOnValue = dependsOnArray[loweredIndex7];
                    var basicDependencyInstance = {};
                    dependencyInstance.dependsOn.push(basicDependencyInstance);
                    
                    var idValue2 = dependsOnValue['id'];
                    if (idValue2 !== null && idValue2 !== undefined) {
                      var idInstance2 = idValue2;
                      basicDependencyInstance.id = idInstance2;
                    }
                    
                    var resourceTypeValue2 = dependsOnValue['resourceType'];
                    if (resourceTypeValue2 !== null && resourceTypeValue2 !== undefined) {
                      var resourceTypeInstance2 = resourceTypeValue2;
                      basicDependencyInstance.resourceType = resourceTypeInstance2;
                    }
                    
                    var resourceNameValue = dependsOnValue['resourceName'];
                    if (resourceNameValue !== null && resourceNameValue !== undefined) {
                      var resourceNameInstance = resourceNameValue;
                      basicDependencyInstance.resourceName = resourceNameInstance;
                    }
                  }
                }
                
                var idValue3 = dependenciesValue['id'];
                if (idValue3 !== null && idValue3 !== undefined) {
                  var idInstance3 = idValue3;
                  dependencyInstance.id = idInstance3;
                }
                
                var resourceTypeValue3 = dependenciesValue['resourceType'];
                if (resourceTypeValue3 !== null && resourceTypeValue3 !== undefined) {
                  var resourceTypeInstance3 = resourceTypeValue3;
                  dependencyInstance.resourceType = resourceTypeInstance3;
                }
                
                var resourceNameValue2 = dependenciesValue['resourceName'];
                if (resourceNameValue2 !== null && resourceNameValue2 !== undefined) {
                  var resourceNameInstance2 = resourceNameValue2;
                  dependencyInstance.resourceName = resourceNameInstance2;
                }
              }
            }
            
            var validatedResourcesArray = propertiesValue2['validatedResources'];
            if (validatedResourcesArray !== null && validatedResourcesArray !== undefined) {
              for (var loweredIndex8 = 0; loweredIndex8 < validatedResourcesArray.length; loweredIndex8 = loweredIndex8 + 1) {
                var validatedResourcesValue = validatedResourcesArray[loweredIndex8];
                var deploymentPreFlightResourceInstance = { dependsOn: [], tags: {} };
                propertiesInstance.validatedResources.push(deploymentPreFlightResourceInstance);
                
                var apiVersionValue = validatedResourcesValue['apiVersion'];
                if (apiVersionValue !== null && apiVersionValue !== undefined) {
                  var apiVersionInstance = apiVersionValue;
                  deploymentPreFlightResourceInstance.apiVersion = apiVersionInstance;
                }
                
                var dependsOnArray2 = validatedResourcesValue['dependsOn'];
                if (dependsOnArray2 !== null && dependsOnArray2 !== undefined) {
                  for (var loweredIndex9 = 0; loweredIndex9 < dependsOnArray2.length; loweredIndex9 = loweredIndex9 + 1) {
                    var dependsOnValue2 = dependsOnArray2[loweredIndex9];
                    deploymentPreFlightResourceInstance.dependsOn.push(dependsOnValue2);
                  }
                }
                
                var propertiesValue4 = validatedResourcesValue['properties'];
                if (propertiesValue4 !== null && propertiesValue4 !== undefined) {
                  var propertiesInstance2 = propertiesValue4;
                  deploymentPreFlightResourceInstance.properties = propertiesInstance2;
                }
                
                var provisioningStateValue2 = validatedResourcesValue['provisioningState'];
                if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
                  var provisioningStateInstance2 = provisioningStateValue2;
                  deploymentPreFlightResourceInstance.provisioningState = provisioningStateInstance2;
                }
                
                var planValue = validatedResourcesValue['plan'];
                if (planValue !== null && planValue !== undefined) {
                  var planInstance = {};
                  deploymentPreFlightResourceInstance.plan = planInstance;
                  
                  var nameValue = planValue['name'];
                  if (nameValue !== null && nameValue !== undefined) {
                    var nameInstance = nameValue;
                    planInstance.name = nameInstance;
                  }
                  
                  var publisherValue = planValue['publisher'];
                  if (publisherValue !== null && publisherValue !== undefined) {
                    var publisherInstance = publisherValue;
                    planInstance.publisher = publisherInstance;
                  }
                  
                  var productValue = planValue['product'];
                  if (productValue !== null && productValue !== undefined) {
                    var productInstance = productValue;
                    planInstance.product = productInstance;
                  }
                  
                  var promotionCodeValue = planValue['promotionCode'];
                  if (promotionCodeValue !== null && promotionCodeValue !== undefined) {
                    var promotionCodeInstance = promotionCodeValue;
                    planInstance.promotionCode = promotionCodeInstance;
                  }
                }
                
                var idValue4 = validatedResourcesValue['id'];
                if (idValue4 !== null && idValue4 !== undefined) {
                  var idInstance4 = idValue4;
                  deploymentPreFlightResourceInstance.id = idInstance4;
                }
                
                var nameValue2 = validatedResourcesValue['name'];
                if (nameValue2 !== null && nameValue2 !== undefined) {
                  var nameInstance2 = nameValue2;
                  deploymentPreFlightResourceInstance.name = nameInstance2;
                }
                
                var typeValue = validatedResourcesValue['type'];
                if (typeValue !== null && typeValue !== undefined) {
                  var typeInstance = typeValue;
                  deploymentPreFlightResourceInstance.type = typeInstance;
                }
                
                var locationValue = validatedResourcesValue['location'];
                if (locationValue !== null && locationValue !== undefined) {
                  var locationInstance = locationValue;
                  deploymentPreFlightResourceInstance.location = locationInstance;
                }
                
                var tagsSequenceElement = validatedResourcesValue['tags'];
                if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                  for (var property2 in tagsSequenceElement) {
                    var tagsKey = property2;
                    var tagsValue = tagsSequenceElement[property2];
                    deploymentPreFlightResourceInstance.tags[tagsKey] = tagsValue;
                  }
                }
              }
            }
            
            var templateValue = propertiesValue2['template'];
            if (templateValue !== null && templateValue !== undefined) {
              var templateInstance = templateValue;
              propertiesInstance.template = templateInstance;
            }
            
            var templateLinkValue2 = propertiesValue2['templateLink'];
            if (templateLinkValue2 !== null && templateLinkValue2 !== undefined) {
              var templateLinkInstance = {};
              propertiesInstance.templateLink = templateLinkInstance;
              
              var uriValue = templateLinkValue2['uri'];
              if (uriValue !== null && uriValue !== undefined) {
                var uriInstance = uriValue;
                templateLinkInstance.uri = uriInstance;
              }
              
              var contentVersionValue = templateLinkValue2['contentVersion'];
              if (contentVersionValue !== null && contentVersionValue !== undefined) {
                var contentVersionInstance = contentVersionValue;
                templateLinkInstance.contentVersion = contentVersionInstance;
              }
            }
            
            var parametersValue = propertiesValue2['parameters'];
            if (parametersValue !== null && parametersValue !== undefined) {
              var parametersInstance = parametersValue;
              propertiesInstance.parameters = parametersInstance;
            }
            
            var parametersLinkValue2 = propertiesValue2['parametersLink'];
            if (parametersLinkValue2 !== null && parametersLinkValue2 !== undefined) {
              var parametersLinkInstance = {};
              propertiesInstance.parametersLink = parametersLinkInstance;
              
              var uriValue2 = parametersLinkValue2['uri'];
              if (uriValue2 !== null && uriValue2 !== undefined) {
                var uriInstance2 = uriValue2;
                parametersLinkInstance.uri = uriInstance2;
              }
              
              var contentVersionValue2 = parametersLinkValue2['contentVersion'];
              if (contentVersionValue2 !== null && contentVersionValue2 !== undefined) {
                var contentVersionInstance2 = contentVersionValue2;
                parametersLinkInstance.contentVersion = contentVersionInstance2;
              }
            }
            
            var modeValue = propertiesValue2['mode'];
            if (modeValue !== null && modeValue !== undefined) {
              var modeInstance = modeValue;
              propertiesInstance.mode = modeInstance;
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      if (statusCode === 200) {
        result.isValid = true;
      }
      
      return callback(null, result);
    });
  };
  
  return DeploymentOperations;
})();

var ProviderOperations = ( /** @lends ProviderOperations */ function() {
  /**
   * @class
   * Operations for managing providers.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ResourceManagementClient] {@link
   * ResourceManagementClient~ResourceManagementClient}.
   * See [providers] {@link
   * ResourceManagementClient~ResourceManagementClient#providers}.
   * Initializes a new instance of the ProviderOperations class.
   * @constructor
   * 
   * @param {ResourceManagementClient} client Reference to the service client.
   */
  function ProviderOperations(client) {
    this.client = client;
  }
  
  /**
   * Gets a resource provider.
   * 
   * @param {string} resourceProviderNamespace Namespace of the resource
   * provider.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProviderOperations.prototype.get = function(resourceProviderNamespace, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceProviderNamespace === null || resourceProviderNamespace === undefined) {
      return callback(new Error('resourceProviderNamespace cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/providers/';
    url2 = url2 + encodeURIComponent(resourceProviderNamespace);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var providerInstance = { resourceTypes: [] };
          result.provider = providerInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            providerInstance.id = idInstance;
          }
          
          var namespaceValue = responseDoc['namespace'];
          if (namespaceValue !== null && namespaceValue !== undefined) {
            var namespaceInstance = namespaceValue;
            providerInstance.namespace = namespaceInstance;
          }
          
          var registrationStateValue = responseDoc['registrationState'];
          if (registrationStateValue !== null && registrationStateValue !== undefined) {
            var registrationStateInstance = registrationStateValue;
            providerInstance.registrationState = registrationStateInstance;
          }
          
          var resourceTypesArray = responseDoc['resourceTypes'];
          if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < resourceTypesArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var resourceTypesValue = resourceTypesArray[loweredIndex1];
              var providerResourceTypeInstance = { apiVersions: [], locations: [], properties: {} };
              providerInstance.resourceTypes.push(providerResourceTypeInstance);
              
              var resourceTypeValue = resourceTypesValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = resourceTypeValue;
                providerResourceTypeInstance.name = resourceTypeInstance;
              }
              
              var locationsArray = resourceTypesValue['locations'];
              if (locationsArray !== null && locationsArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < locationsArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var locationsValue = locationsArray[loweredIndex2];
                  providerResourceTypeInstance.locations.push(locationsValue);
                }
              }
              
              var apiVersionsArray = resourceTypesValue['apiVersions'];
              if (apiVersionsArray !== null && apiVersionsArray !== undefined) {
                for (var loweredIndex3 = 0; loweredIndex3 < apiVersionsArray.length; loweredIndex3 = loweredIndex3 + 1) {
                  var apiVersionsValue = apiVersionsArray[loweredIndex3];
                  providerResourceTypeInstance.apiVersions.push(apiVersionsValue);
                }
              }
              
              var propertiesSequenceElement = resourceTypesValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property in propertiesSequenceElement) {
                  var propertiesKey = property;
                  var propertiesValue = propertiesSequenceElement[property];
                  providerResourceTypeInstance.properties[propertiesKey] = propertiesValue;
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets a list of resource providers.
   * 
   * @param {ProviderListParameters} [parametersOrCallback] Query parameters.
   * If null is passed returns all deployments.
   * 
   * @param {number} [parametersOrCallback.top] Get or sets the number of
   * records to return. Optional.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProviderOperations.prototype.list = function(parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/providers';
    var queryParameters = [];
    if (parameters !== null && parameters !== undefined && parameters.top !== null && parameters.top !== undefined) {
      queryParameters.push('$top=' + encodeURIComponent(parameters.top.toString()));
    }
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { providers: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var providerInstance = { resourceTypes: [] };
              result.providers.push(providerInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                providerInstance.id = idInstance;
              }
              
              var namespaceValue = valueValue['namespace'];
              if (namespaceValue !== null && namespaceValue !== undefined) {
                var namespaceInstance = namespaceValue;
                providerInstance.namespace = namespaceInstance;
              }
              
              var registrationStateValue = valueValue['registrationState'];
              if (registrationStateValue !== null && registrationStateValue !== undefined) {
                var registrationStateInstance = registrationStateValue;
                providerInstance.registrationState = registrationStateInstance;
              }
              
              var resourceTypesArray = valueValue['resourceTypes'];
              if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < resourceTypesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var resourceTypesValue = resourceTypesArray[loweredIndex2];
                  var providerResourceTypeInstance = { apiVersions: [], locations: [], properties: {} };
                  providerInstance.resourceTypes.push(providerResourceTypeInstance);
                  
                  var resourceTypeValue = resourceTypesValue['resourceType'];
                  if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                    var resourceTypeInstance = resourceTypeValue;
                    providerResourceTypeInstance.name = resourceTypeInstance;
                  }
                  
                  var locationsArray = resourceTypesValue['locations'];
                  if (locationsArray !== null && locationsArray !== undefined) {
                    for (var loweredIndex3 = 0; loweredIndex3 < locationsArray.length; loweredIndex3 = loweredIndex3 + 1) {
                      var locationsValue = locationsArray[loweredIndex3];
                      providerResourceTypeInstance.locations.push(locationsValue);
                    }
                  }
                  
                  var apiVersionsArray = resourceTypesValue['apiVersions'];
                  if (apiVersionsArray !== null && apiVersionsArray !== undefined) {
                    for (var loweredIndex4 = 0; loweredIndex4 < apiVersionsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                      var apiVersionsValue = apiVersionsArray[loweredIndex4];
                      providerResourceTypeInstance.apiVersions.push(apiVersionsValue);
                    }
                  }
                  
                  var propertiesSequenceElement = resourceTypesValue['properties'];
                  if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                    for (var property in propertiesSequenceElement) {
                      var propertiesKey = property;
                      var propertiesValue = propertiesSequenceElement[property];
                      providerResourceTypeInstance.properties[propertiesKey] = propertiesValue;
                    }
                  }
                }
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a list of deployments.
   * 
   * @param {string} nextLink NextLink from the previous successful call to
   * List operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProviderOperations.prototype.listNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { providers: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var providerInstance = { resourceTypes: [] };
              result.providers.push(providerInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                providerInstance.id = idInstance;
              }
              
              var namespaceValue = valueValue['namespace'];
              if (namespaceValue !== null && namespaceValue !== undefined) {
                var namespaceInstance = namespaceValue;
                providerInstance.namespace = namespaceInstance;
              }
              
              var registrationStateValue = valueValue['registrationState'];
              if (registrationStateValue !== null && registrationStateValue !== undefined) {
                var registrationStateInstance = registrationStateValue;
                providerInstance.registrationState = registrationStateInstance;
              }
              
              var resourceTypesArray = valueValue['resourceTypes'];
              if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < resourceTypesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var resourceTypesValue = resourceTypesArray[loweredIndex2];
                  var providerResourceTypeInstance = { apiVersions: [], locations: [], properties: {} };
                  providerInstance.resourceTypes.push(providerResourceTypeInstance);
                  
                  var resourceTypeValue = resourceTypesValue['resourceType'];
                  if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                    var resourceTypeInstance = resourceTypeValue;
                    providerResourceTypeInstance.name = resourceTypeInstance;
                  }
                  
                  var locationsArray = resourceTypesValue['locations'];
                  if (locationsArray !== null && locationsArray !== undefined) {
                    for (var loweredIndex3 = 0; loweredIndex3 < locationsArray.length; loweredIndex3 = loweredIndex3 + 1) {
                      var locationsValue = locationsArray[loweredIndex3];
                      providerResourceTypeInstance.locations.push(locationsValue);
                    }
                  }
                  
                  var apiVersionsArray = resourceTypesValue['apiVersions'];
                  if (apiVersionsArray !== null && apiVersionsArray !== undefined) {
                    for (var loweredIndex4 = 0; loweredIndex4 < apiVersionsArray.length; loweredIndex4 = loweredIndex4 + 1) {
                      var apiVersionsValue = apiVersionsArray[loweredIndex4];
                      providerResourceTypeInstance.apiVersions.push(apiVersionsValue);
                    }
                  }
                  
                  var propertiesSequenceElement = resourceTypesValue['properties'];
                  if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                    for (var property in propertiesSequenceElement) {
                      var propertiesKey = property;
                      var propertiesValue = propertiesSequenceElement[property];
                      providerResourceTypeInstance.properties[propertiesKey] = propertiesValue;
                    }
                  }
                }
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Registers provider to be used with a subscription.
   * 
   * @param {string} resourceProviderNamespace Namespace of the resource
   * provider.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProviderOperations.prototype.register = function(resourceProviderNamespace, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceProviderNamespace === null || resourceProviderNamespace === undefined) {
      return callback(new Error('resourceProviderNamespace cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/providers/';
    url2 = url2 + encodeURIComponent(resourceProviderNamespace);
    url2 = url2 + '/register';
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var providerInstance = { resourceTypes: [] };
          result.provider = providerInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            providerInstance.id = idInstance;
          }
          
          var namespaceValue = responseDoc['namespace'];
          if (namespaceValue !== null && namespaceValue !== undefined) {
            var namespaceInstance = namespaceValue;
            providerInstance.namespace = namespaceInstance;
          }
          
          var registrationStateValue = responseDoc['registrationState'];
          if (registrationStateValue !== null && registrationStateValue !== undefined) {
            var registrationStateInstance = registrationStateValue;
            providerInstance.registrationState = registrationStateInstance;
          }
          
          var resourceTypesArray = responseDoc['resourceTypes'];
          if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < resourceTypesArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var resourceTypesValue = resourceTypesArray[loweredIndex1];
              var providerResourceTypeInstance = { apiVersions: [], locations: [], properties: {} };
              providerInstance.resourceTypes.push(providerResourceTypeInstance);
              
              var resourceTypeValue = resourceTypesValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = resourceTypeValue;
                providerResourceTypeInstance.name = resourceTypeInstance;
              }
              
              var locationsArray = resourceTypesValue['locations'];
              if (locationsArray !== null && locationsArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < locationsArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var locationsValue = locationsArray[loweredIndex2];
                  providerResourceTypeInstance.locations.push(locationsValue);
                }
              }
              
              var apiVersionsArray = resourceTypesValue['apiVersions'];
              if (apiVersionsArray !== null && apiVersionsArray !== undefined) {
                for (var loweredIndex3 = 0; loweredIndex3 < apiVersionsArray.length; loweredIndex3 = loweredIndex3 + 1) {
                  var apiVersionsValue = apiVersionsArray[loweredIndex3];
                  providerResourceTypeInstance.apiVersions.push(apiVersionsValue);
                }
              }
              
              var propertiesSequenceElement = resourceTypesValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property in propertiesSequenceElement) {
                  var propertiesKey = property;
                  var propertiesValue = propertiesSequenceElement[property];
                  providerResourceTypeInstance.properties[propertiesKey] = propertiesValue;
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Unregisters provider from a subscription.
   * 
   * @param {string} resourceProviderNamespace Namespace of the resource
   * provider.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProviderOperations.prototype.unregister = function(resourceProviderNamespace, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceProviderNamespace === null || resourceProviderNamespace === undefined) {
      return callback(new Error('resourceProviderNamespace cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/providers/';
    url2 = url2 + encodeURIComponent(resourceProviderNamespace);
    url2 = url2 + '/unregister';
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var providerInstance = { resourceTypes: [] };
          result.provider = providerInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            providerInstance.id = idInstance;
          }
          
          var namespaceValue = responseDoc['namespace'];
          if (namespaceValue !== null && namespaceValue !== undefined) {
            var namespaceInstance = namespaceValue;
            providerInstance.namespace = namespaceInstance;
          }
          
          var registrationStateValue = responseDoc['registrationState'];
          if (registrationStateValue !== null && registrationStateValue !== undefined) {
            var registrationStateInstance = registrationStateValue;
            providerInstance.registrationState = registrationStateInstance;
          }
          
          var resourceTypesArray = responseDoc['resourceTypes'];
          if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < resourceTypesArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var resourceTypesValue = resourceTypesArray[loweredIndex1];
              var providerResourceTypeInstance = { apiVersions: [], locations: [], properties: {} };
              providerInstance.resourceTypes.push(providerResourceTypeInstance);
              
              var resourceTypeValue = resourceTypesValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = resourceTypeValue;
                providerResourceTypeInstance.name = resourceTypeInstance;
              }
              
              var locationsArray = resourceTypesValue['locations'];
              if (locationsArray !== null && locationsArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < locationsArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var locationsValue = locationsArray[loweredIndex2];
                  providerResourceTypeInstance.locations.push(locationsValue);
                }
              }
              
              var apiVersionsArray = resourceTypesValue['apiVersions'];
              if (apiVersionsArray !== null && apiVersionsArray !== undefined) {
                for (var loweredIndex3 = 0; loweredIndex3 < apiVersionsArray.length; loweredIndex3 = loweredIndex3 + 1) {
                  var apiVersionsValue = apiVersionsArray[loweredIndex3];
                  providerResourceTypeInstance.apiVersions.push(apiVersionsValue);
                }
              }
              
              var propertiesSequenceElement = resourceTypesValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property in propertiesSequenceElement) {
                  var propertiesKey = property;
                  var propertiesValue = propertiesSequenceElement[property];
                  providerResourceTypeInstance.properties[propertiesKey] = propertiesValue;
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ProviderOperations;
})();

var ProviderOperationsMetadataOperations = ( /** @lends ProviderOperationsMetadataOperations */ function() {
  /**
   * @class
   * Operations for getting provider operations metadata.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ResourceManagementClient] {@link
   * ResourceManagementClient~ResourceManagementClient}.
   * See [providerOperationsMetadata] {@link
   * ResourceManagementClient~ResourceManagementClient#providerOperationsMetadata}.
   * Initializes a new instance of the ProviderOperationsMetadataOperations
   * class.
   * @constructor
   * 
   * @param {ResourceManagementClient} client Reference to the service client.
   */
  function ProviderOperationsMetadataOperations(client) {
    this.client = client;
  }
  
  /**
   * Gets provider operations metadata
   * 
   * @param {string} resourceProviderNamespace Namespace of the resource
   * provider.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProviderOperationsMetadataOperations.prototype.get = function(resourceProviderNamespace, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceProviderNamespace === null || resourceProviderNamespace === undefined) {
      return callback(new Error('resourceProviderNamespace cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/providers/Microsoft.Authorization/providerOperations/';
    url2 = url2 + encodeURIComponent(resourceProviderNamespace);
    var queryParameters = [];
    queryParameters.push('api-version=2015-07-01');
    queryParameters.push('$expand=resourceTypes');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var providerInstance = { operations: [], resourceTypes: [] };
          result.provider = providerInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            providerInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            providerInstance.name = nameInstance;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            providerInstance.type = typeInstance;
          }
          
          var displayNameValue = responseDoc['displayName'];
          if (displayNameValue !== null && displayNameValue !== undefined) {
            var displayNameInstance = displayNameValue;
            providerInstance.displayName = displayNameInstance;
          }
          
          var resourceTypesArray = responseDoc['resourceTypes'];
          if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < resourceTypesArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var resourceTypesValue = resourceTypesArray[loweredIndex1];
              var resourceTypeInstance = { operations: [] };
              providerInstance.resourceTypes.push(resourceTypeInstance);
              
              var nameValue2 = resourceTypesValue['name'];
              if (nameValue2 !== null && nameValue2 !== undefined) {
                var nameInstance2 = nameValue2;
                resourceTypeInstance.name = nameInstance2;
              }
              
              var displayNameValue2 = resourceTypesValue['displayName'];
              if (displayNameValue2 !== null && displayNameValue2 !== undefined) {
                var displayNameInstance2 = displayNameValue2;
                resourceTypeInstance.displayName = displayNameInstance2;
              }
              
              var operationsArray = resourceTypesValue['operations'];
              if (operationsArray !== null && operationsArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < operationsArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var operationsValue = operationsArray[loweredIndex2];
                  var operationInstance = {};
                  resourceTypeInstance.operations.push(operationInstance);
                  
                  var nameValue3 = operationsValue['name'];
                  if (nameValue3 !== null && nameValue3 !== undefined) {
                    var nameInstance3 = nameValue3;
                    operationInstance.name = nameInstance3;
                  }
                  
                  var displayNameValue3 = operationsValue['displayName'];
                  if (displayNameValue3 !== null && displayNameValue3 !== undefined) {
                    var displayNameInstance3 = displayNameValue3;
                    operationInstance.displayName = displayNameInstance3;
                  }
                  
                  var descriptionValue = operationsValue['description'];
                  if (descriptionValue !== null && descriptionValue !== undefined) {
                    var descriptionInstance = descriptionValue;
                    operationInstance.description = descriptionInstance;
                  }
                  
                  var originValue = operationsValue['origin'];
                  if (originValue !== null && originValue !== undefined) {
                    var originInstance = originValue;
                    operationInstance.origin = originInstance;
                  }
                  
                  var propertiesValue = operationsValue['properties'];
                  if (propertiesValue !== null && propertiesValue !== undefined) {
                    var propertiesInstance = propertiesValue;
                    operationInstance.properties = propertiesInstance;
                  }
                }
              }
            }
          }
          
          var operationsArray2 = responseDoc['operations'];
          if (operationsArray2 !== null && operationsArray2 !== undefined) {
            for (var loweredIndex3 = 0; loweredIndex3 < operationsArray2.length; loweredIndex3 = loweredIndex3 + 1) {
              var operationsValue2 = operationsArray2[loweredIndex3];
              var operationInstance2 = {};
              providerInstance.operations.push(operationInstance2);
              
              var nameValue4 = operationsValue2['name'];
              if (nameValue4 !== null && nameValue4 !== undefined) {
                var nameInstance4 = nameValue4;
                operationInstance2.name = nameInstance4;
              }
              
              var displayNameValue4 = operationsValue2['displayName'];
              if (displayNameValue4 !== null && displayNameValue4 !== undefined) {
                var displayNameInstance4 = displayNameValue4;
                operationInstance2.displayName = displayNameInstance4;
              }
              
              var descriptionValue2 = operationsValue2['description'];
              if (descriptionValue2 !== null && descriptionValue2 !== undefined) {
                var descriptionInstance2 = descriptionValue2;
                operationInstance2.description = descriptionInstance2;
              }
              
              var originValue2 = operationsValue2['origin'];
              if (originValue2 !== null && originValue2 !== undefined) {
                var originInstance2 = originValue2;
                operationInstance2.origin = originInstance2;
              }
              
              var propertiesValue2 = operationsValue2['properties'];
              if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
                var propertiesInstance2 = propertiesValue2;
                operationInstance2.properties = propertiesInstance2;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets provider operations metadata list
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProviderOperationsMetadataOperations.prototype.list = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/providers/Microsoft.Authorization/providerOperations';
    var queryParameters = [];
    queryParameters.push('api-version=2015-07-01');
    queryParameters.push('$expand=resourceTypes');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { providers: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var providerOperationsMetadataInstance = { operations: [], resourceTypes: [] };
              result.providers.push(providerOperationsMetadataInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                providerOperationsMetadataInstance.id = idInstance;
              }
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                providerOperationsMetadataInstance.name = nameInstance;
              }
              
              var typeValue = valueValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                providerOperationsMetadataInstance.type = typeInstance;
              }
              
              var displayNameValue = valueValue['displayName'];
              if (displayNameValue !== null && displayNameValue !== undefined) {
                var displayNameInstance = displayNameValue;
                providerOperationsMetadataInstance.displayName = displayNameInstance;
              }
              
              var resourceTypesArray = valueValue['resourceTypes'];
              if (resourceTypesArray !== null && resourceTypesArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < resourceTypesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var resourceTypesValue = resourceTypesArray[loweredIndex2];
                  var resourceTypeInstance = { operations: [] };
                  providerOperationsMetadataInstance.resourceTypes.push(resourceTypeInstance);
                  
                  var nameValue2 = resourceTypesValue['name'];
                  if (nameValue2 !== null && nameValue2 !== undefined) {
                    var nameInstance2 = nameValue2;
                    resourceTypeInstance.name = nameInstance2;
                  }
                  
                  var displayNameValue2 = resourceTypesValue['displayName'];
                  if (displayNameValue2 !== null && displayNameValue2 !== undefined) {
                    var displayNameInstance2 = displayNameValue2;
                    resourceTypeInstance.displayName = displayNameInstance2;
                  }
                  
                  var operationsArray = resourceTypesValue['operations'];
                  if (operationsArray !== null && operationsArray !== undefined) {
                    for (var loweredIndex3 = 0; loweredIndex3 < operationsArray.length; loweredIndex3 = loweredIndex3 + 1) {
                      var operationsValue = operationsArray[loweredIndex3];
                      var operationInstance = {};
                      resourceTypeInstance.operations.push(operationInstance);
                      
                      var nameValue3 = operationsValue['name'];
                      if (nameValue3 !== null && nameValue3 !== undefined) {
                        var nameInstance3 = nameValue3;
                        operationInstance.name = nameInstance3;
                      }
                      
                      var displayNameValue3 = operationsValue['displayName'];
                      if (displayNameValue3 !== null && displayNameValue3 !== undefined) {
                        var displayNameInstance3 = displayNameValue3;
                        operationInstance.displayName = displayNameInstance3;
                      }
                      
                      var descriptionValue = operationsValue['description'];
                      if (descriptionValue !== null && descriptionValue !== undefined) {
                        var descriptionInstance = descriptionValue;
                        operationInstance.description = descriptionInstance;
                      }
                      
                      var originValue = operationsValue['origin'];
                      if (originValue !== null && originValue !== undefined) {
                        var originInstance = originValue;
                        operationInstance.origin = originInstance;
                      }
                      
                      var propertiesValue = operationsValue['properties'];
                      if (propertiesValue !== null && propertiesValue !== undefined) {
                        var propertiesInstance = propertiesValue;
                        operationInstance.properties = propertiesInstance;
                      }
                    }
                  }
                }
              }
              
              var operationsArray2 = valueValue['operations'];
              if (operationsArray2 !== null && operationsArray2 !== undefined) {
                for (var loweredIndex4 = 0; loweredIndex4 < operationsArray2.length; loweredIndex4 = loweredIndex4 + 1) {
                  var operationsValue2 = operationsArray2[loweredIndex4];
                  var operationInstance2 = {};
                  providerOperationsMetadataInstance.operations.push(operationInstance2);
                  
                  var nameValue4 = operationsValue2['name'];
                  if (nameValue4 !== null && nameValue4 !== undefined) {
                    var nameInstance4 = nameValue4;
                    operationInstance2.name = nameInstance4;
                  }
                  
                  var displayNameValue4 = operationsValue2['displayName'];
                  if (displayNameValue4 !== null && displayNameValue4 !== undefined) {
                    var displayNameInstance4 = displayNameValue4;
                    operationInstance2.displayName = displayNameInstance4;
                  }
                  
                  var descriptionValue2 = operationsValue2['description'];
                  if (descriptionValue2 !== null && descriptionValue2 !== undefined) {
                    var descriptionInstance2 = descriptionValue2;
                    operationInstance2.description = descriptionInstance2;
                  }
                  
                  var originValue2 = operationsValue2['origin'];
                  if (originValue2 !== null && originValue2 !== undefined) {
                    var originInstance2 = originValue2;
                    operationInstance2.origin = originInstance2;
                  }
                  
                  var propertiesValue2 = operationsValue2['properties'];
                  if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
                    var propertiesInstance2 = propertiesValue2;
                    operationInstance2.properties = propertiesInstance2;
                  }
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ProviderOperationsMetadataOperations;
})();

var ResourceGroupOperations = ( /** @lends ResourceGroupOperations */ function() {
  /**
   * @class
   * Operations for managing resource groups.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ResourceManagementClient] {@link
   * ResourceManagementClient~ResourceManagementClient}.
   * See [resourceGroups] {@link
   * ResourceManagementClient~ResourceManagementClient#resourceGroups}.
   * Initializes a new instance of the ResourceGroupOperations class.
   * @constructor
   * 
   * @param {ResourceManagementClient} client Reference to the service client.
   */
  function ResourceGroupOperations(client) {
    this.client = client;
  }
  
  /**
   * Begin deleting resource group.To determine whether the operation has
   * finished processing the request, call GetLongRunningOperationStatus.
   * 
   * @param {string} resourceGroupName The name of the resource group to be
   * deleted. The name is case insensitive.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceGroupOperations.prototype.beginDeleting = function(resourceGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 202) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.operationStatusLink = response.headers['location'];
      result.retryAfter = parseInt(response.headers['retry-after'], 10);
      result.requestId = response.headers['x-ms-request-id'];
      if (statusCode === 409) {
        result.status = OperationStatus.Failed;
      }
      if (statusCode === 200) {
        result.status = OperationStatus.Succeeded;
      }
      
      return callback(null, result);
    });
  };
  
  /**
   * Checks whether resource group exists.
   * 
   * @param {string} resourceGroupName The name of the resource group to check.
   * The name is case insensitive.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceGroupOperations.prototype.checkExistence = function(resourceGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + 'subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'HEAD';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 204 && statusCode !== 404) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      if (statusCode === 204) {
        result.exists = true;
      }
      
      return callback(null, result);
    });
  };
  
  /**
   * Create a resource group.
   * 
   * @param {string} resourceGroupName The name of the resource group to be
   * created or updated.
   * 
   * @param {ResourceGroup} parameters Parameters supplied to the create or
   * update resource group service operation.
   * 
   * @param {string} parameters.location Gets or sets the location of the
   * resource group. It cannot be changed after the resource group has been
   * created. Has to be one of the supported Azure Locations, such as West US,
   * East US, West Europe, East Asia, etc.
   * 
   * @param {string} [parameters.properties] Gets or sets the resource group
   * properties.
   * 
   * @param {object} [parameters.tags] Gets or sets the tags attached to the
   * resource group.
   * 
   * @param {string} [parameters.provisioningState] Gets or sets resource group
   * provisioning state.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceGroupOperations.prototype.createOrUpdate = function(resourceGroupName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.location === null || parameters.location === undefined) {
      return callback(new Error('parameters.location cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var resourceGroupValue = {};
    requestDoc = resourceGroupValue;
    
    resourceGroupValue['location'] = parameters.location;
    
    if (parameters.properties !== null && parameters.properties !== undefined) {
      resourceGroupValue['properties'] = parameters.properties;
    }
    
    if (parameters.tags !== null && parameters.tags !== undefined) {
      var tagsDictionary = {};
      for (var tagsKey in parameters.tags) {
        var tagsValue = parameters.tags[tagsKey];
        tagsDictionary[tagsKey] = tagsValue;
      }
      resourceGroupValue['tags'] = tagsDictionary;
    }
    
    if (parameters.provisioningState !== null && parameters.provisioningState !== undefined) {
      resourceGroupValue['provisioningState'] = parameters.provisioningState;
    }
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 201) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var resourceGroupInstance = { tags: {} };
          result.resourceGroup = resourceGroupInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            resourceGroupInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            resourceGroupInstance.name = nameInstance;
          }
          
          var propertiesValue = responseDoc['properties'];
          if (propertiesValue !== null && propertiesValue !== undefined) {
            var provisioningStateValue = propertiesValue['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              resourceGroupInstance.provisioningState = provisioningStateInstance;
            }
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            resourceGroupInstance.location = locationInstance;
          }
          
          var propertiesValue2 = responseDoc['properties'];
          if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
            var propertiesInstance = propertiesValue2;
            resourceGroupInstance.properties = propertiesInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey2 = property;
              var tagsValue2 = tagsSequenceElement[property];
              resourceGroupInstance.tags[tagsKey2] = tagsValue2;
            }
          }
          
          var provisioningStateValue2 = responseDoc['provisioningState'];
          if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
            var provisioningStateInstance2 = provisioningStateValue2;
            resourceGroupInstance.provisioningState = provisioningStateInstance2;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Delete resource group and all of its resources.
   * 
   * @param {string} resourceGroupName The name of the resource group to be
   * deleted. The name is case insensitive.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceGroupOperations.prototype.deleteMethod = function(resourceGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.resourceGroups.beginDeleting(resourceGroupName, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = result.retryAfter;
      if (delayInSeconds === 0) {
        delayInSeconds = 30;
      }
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getLongRunningOperationStatus(result.operationStatusLink, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                return callback(null, result2);
              } else {
                delayInSeconds = result2.retryAfter;
                if (delayInSeconds === 0) {
                  delayInSeconds = 15;
                }
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Get a resource group.
   * 
   * @param {string} resourceGroupName The name of the resource group to get.
   * The name is case insensitive.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceGroupOperations.prototype.get = function(resourceGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var resourceGroupInstance = { tags: {} };
          result.resourceGroup = resourceGroupInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            resourceGroupInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            resourceGroupInstance.name = nameInstance;
          }
          
          var propertiesValue = responseDoc['properties'];
          if (propertiesValue !== null && propertiesValue !== undefined) {
            var provisioningStateValue = propertiesValue['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              resourceGroupInstance.provisioningState = provisioningStateInstance;
            }
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            resourceGroupInstance.location = locationInstance;
          }
          
          var propertiesValue2 = responseDoc['properties'];
          if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
            var propertiesInstance = propertiesValue2;
            resourceGroupInstance.properties = propertiesInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey = property;
              var tagsValue = tagsSequenceElement[property];
              resourceGroupInstance.tags[tagsKey] = tagsValue;
            }
          }
          
          var provisioningStateValue2 = responseDoc['provisioningState'];
          if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
            var provisioningStateInstance2 = provisioningStateValue2;
            resourceGroupInstance.provisioningState = provisioningStateInstance2;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets a collection of resource groups.
   * 
   * @param {ResourceGroupListParameters} [parametersOrCallback] Query
   * parameters. If null is passed returns all resource groups.
   * 
   * @param {string} [parametersOrCallback.tagName] Filter the results based on
   * a particular tag name. Optional.
   * 
   * @param {string} [parametersOrCallback.tagValue] Filter the results for a
   * tag name along with a particular tag value. Optional.
   * 
   * @param {number} [parametersOrCallback.top] Number of records to return.
   * Optional.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceGroupOperations.prototype.list = function(parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups';
    var queryParameters = [];
    var odataFilter = [];
    if (parameters !== null && parameters !== undefined && parameters.tagName !== null && parameters.tagName !== undefined) {
      odataFilter.push('tagname eq \'' + encodeURIComponent(parameters.tagName) + '\'');
    }
    if (parameters !== null && parameters !== undefined && parameters.tagValue !== null && parameters.tagValue !== undefined) {
      odataFilter.push('tagvalue eq \'' + encodeURIComponent(parameters.tagValue) + '\'');
    }
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(' and '));
    }
    if (parameters !== null && parameters !== undefined && parameters.top !== null && parameters.top !== undefined) {
      queryParameters.push('$top=' + encodeURIComponent(parameters.top.toString()));
    }
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { resourceGroups: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var resourceGroupJsonFormatInstance = { tags: {} };
              result.resourceGroups.push(resourceGroupJsonFormatInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                resourceGroupJsonFormatInstance.id = idInstance;
              }
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                resourceGroupJsonFormatInstance.name = nameInstance;
              }
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  resourceGroupJsonFormatInstance.provisioningState = provisioningStateInstance;
                }
              }
              
              var locationValue = valueValue['location'];
              if (locationValue !== null && locationValue !== undefined) {
                var locationInstance = locationValue;
                resourceGroupJsonFormatInstance.location = locationInstance;
              }
              
              var propertiesValue2 = valueValue['properties'];
              if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
                var propertiesInstance = propertiesValue2;
                resourceGroupJsonFormatInstance.properties = propertiesInstance;
              }
              
              var tagsSequenceElement = valueValue['tags'];
              if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                for (var property in tagsSequenceElement) {
                  var tagsKey = property;
                  var tagsValue = tagsSequenceElement[property];
                  resourceGroupJsonFormatInstance.tags[tagsKey] = tagsValue;
                }
              }
              
              var provisioningStateValue2 = valueValue['provisioningState'];
              if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
                var provisioningStateInstance2 = provisioningStateValue2;
                resourceGroupJsonFormatInstance.provisioningState = provisioningStateInstance2;
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a list of deployments.
   * 
   * @param {string} nextLink NextLink from the previous successful call to
   * List operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceGroupOperations.prototype.listNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { resourceGroups: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var resourceGroupJsonFormatInstance = { tags: {} };
              result.resourceGroups.push(resourceGroupJsonFormatInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                resourceGroupJsonFormatInstance.id = idInstance;
              }
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                resourceGroupJsonFormatInstance.name = nameInstance;
              }
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  resourceGroupJsonFormatInstance.provisioningState = provisioningStateInstance;
                }
              }
              
              var locationValue = valueValue['location'];
              if (locationValue !== null && locationValue !== undefined) {
                var locationInstance = locationValue;
                resourceGroupJsonFormatInstance.location = locationInstance;
              }
              
              var propertiesValue2 = valueValue['properties'];
              if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
                var propertiesInstance = propertiesValue2;
                resourceGroupJsonFormatInstance.properties = propertiesInstance;
              }
              
              var tagsSequenceElement = valueValue['tags'];
              if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                for (var property in tagsSequenceElement) {
                  var tagsKey = property;
                  var tagsValue = tagsSequenceElement[property];
                  resourceGroupJsonFormatInstance.tags[tagsKey] = tagsValue;
                }
              }
              
              var provisioningStateValue2 = valueValue['provisioningState'];
              if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
                var provisioningStateInstance2 = provisioningStateValue2;
                resourceGroupJsonFormatInstance.provisioningState = provisioningStateInstance2;
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Resource groups can be updated through a simple PATCH operation to a group
   * address. The format of the request is the same as that for creating a
   * resource groups, though if a field is unspecified current value will be
   * carried over.
   * 
   * @param {string} resourceGroupName The name of the resource group to be
   * created or updated. The name is case insensitive.
   * 
   * @param {ResourceGroup} parameters Parameters supplied to the update state
   * resource group service operation.
   * 
   * @param {string} parameters.location Gets or sets the location of the
   * resource group. It cannot be changed after the resource group has been
   * created. Has to be one of the supported Azure Locations, such as West US,
   * East US, West Europe, East Asia, etc.
   * 
   * @param {string} [parameters.properties] Gets or sets the resource group
   * properties.
   * 
   * @param {object} [parameters.tags] Gets or sets the tags attached to the
   * resource group.
   * 
   * @param {string} [parameters.provisioningState] Gets or sets resource group
   * provisioning state.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceGroupOperations.prototype.patch = function(resourceGroupName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.location === null || parameters.location === undefined) {
      return callback(new Error('parameters.location cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var resourceGroupValue = {};
    requestDoc = resourceGroupValue;
    
    resourceGroupValue['location'] = parameters.location;
    
    if (parameters.properties !== null && parameters.properties !== undefined) {
      resourceGroupValue['properties'] = parameters.properties;
    }
    
    if (parameters.tags !== null && parameters.tags !== undefined) {
      var tagsDictionary = {};
      for (var tagsKey in parameters.tags) {
        var tagsValue = parameters.tags[tagsKey];
        tagsDictionary[tagsKey] = tagsValue;
      }
      resourceGroupValue['tags'] = tagsDictionary;
    }
    
    if (parameters.provisioningState !== null && parameters.provisioningState !== undefined) {
      resourceGroupValue['provisioningState'] = parameters.provisioningState;
    }
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var resourceGroupInstance = { tags: {} };
          result.resourceGroup = resourceGroupInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            resourceGroupInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            resourceGroupInstance.name = nameInstance;
          }
          
          var propertiesValue = responseDoc['properties'];
          if (propertiesValue !== null && propertiesValue !== undefined) {
            var provisioningStateValue = propertiesValue['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              resourceGroupInstance.provisioningState = provisioningStateInstance;
            }
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            resourceGroupInstance.location = locationInstance;
          }
          
          var propertiesValue2 = responseDoc['properties'];
          if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
            var propertiesInstance = propertiesValue2;
            resourceGroupInstance.properties = propertiesInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey2 = property;
              var tagsValue2 = tagsSequenceElement[property];
              resourceGroupInstance.tags[tagsKey2] = tagsValue2;
            }
          }
          
          var provisioningStateValue2 = responseDoc['provisioningState'];
          if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
            var provisioningStateInstance2 = provisioningStateValue2;
            resourceGroupInstance.provisioningState = provisioningStateInstance2;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ResourceGroupOperations;
})();

var ResourceOperations = ( /** @lends ResourceOperations */ function() {
  /**
   * @class
   * Operations for managing resources.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ResourceManagementClient] {@link
   * ResourceManagementClient~ResourceManagementClient}.
   * See [resources] {@link
   * ResourceManagementClient~ResourceManagementClient#resources}.
   * Initializes a new instance of the ResourceOperations class.
   * @constructor
   * 
   * @param {ResourceManagementClient} client Reference to the service client.
   */
  function ResourceOperations(client) {
    this.client = client;
  }
  
  /**
   * Begin moving resources.To determine whether the operation has finished
   * processing the request, call GetLongRunningOperationStatus.
   * 
   * @param {string} sourceResourceGroupName Source resource group name.
   * 
   * @param {ResourcesMoveInfo} parameters move resources' parameters.
   * 
   * @param {IEnumerable} [parameters.resources] Gets or sets the ids of the
   * resources.
   * 
   * @param {string} [parameters.targetResourceGroup] The target resource group.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceOperations.prototype.beginMoving = function(sourceResourceGroupName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (sourceResourceGroupName === null || sourceResourceGroupName === undefined) {
      return callback(new Error('sourceResourceGroupName cannot be null.'));
    }
    if (sourceResourceGroupName !== null && sourceResourceGroupName !== undefined && sourceResourceGroupName.length > 1000) {
      return callback(new Error('sourceResourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(sourceResourceGroupName) === false) {
      return callback(new Error('sourceResourceGroupName is outside the valid range.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(sourceResourceGroupName);
    url2 = url2 + '/moveResources';
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var resourcesMoveInfoValue = {};
    requestDoc = resourcesMoveInfoValue;
    
    if (parameters.resources !== null && parameters.resources !== undefined) {
      var resourcesArray = [];
      for (var loweredIndex1 = 0; loweredIndex1 < parameters.resources.length; loweredIndex1 = loweredIndex1 + 1) {
        var resourcesItem = parameters.resources[loweredIndex1];
        resourcesArray.push(resourcesItem);
      }
      resourcesMoveInfoValue['resources'] = resourcesArray;
    }
    
    if (parameters.targetResourceGroup !== null && parameters.targetResourceGroup !== undefined) {
      resourcesMoveInfoValue['targetResourceGroup'] = parameters.targetResourceGroup;
    }
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 202 && statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.operationStatusLink = response.headers['location'];
      result.retryAfter = parseInt(response.headers['retry-after'], 10);
      result.requestId = response.headers['x-ms-request-id'];
      if (statusCode === 400) {
        result.status = OperationStatus.Failed;
      }
      if (statusCode === 409) {
        result.status = OperationStatus.Failed;
      }
      if (statusCode === 202) {
        result.status = OperationStatus.InProgress;
      }
      if (statusCode === 204) {
        result.status = OperationStatus.Succeeded;
      }
      
      return callback(null, result);
    });
  };
  
  /**
   * Checks whether resource exists.
   * 
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   * 
   * @param {ResourceIdentity} identity Resource identity.
   * 
   * @param {string} identity.resourceName Gets or sets resource name.
   * 
   * @param {string} identity.resourceProviderNamespace Gets or sets namespace
   * of the resource provider.
   * 
   * @param {string} identity.resourceType Gets or sets resource type.
   * 
   * @param {string} identity.resourceProviderApiVersion Gets or sets API
   * version of the resource provider.
   * 
   * @param {string} [identity.parentResourcePath] Gets or sets parent resource
   * path (optional).
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceOperations.prototype.checkExistence = function(resourceGroupName, identity, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (identity === null || identity === undefined) {
      return callback(new Error('identity cannot be null.'));
    }
    if (identity.resourceName === null || identity.resourceName === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceProviderApiVersion === null || identity.resourceProviderApiVersion === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceProviderNamespace === null || identity.resourceProviderNamespace === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceType === null || identity.resourceType === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + encodeURIComponent(identity.resourceProviderNamespace);
    url2 = url2 + '/';
    if (identity.parentResourcePath !== null && identity.parentResourcePath !== undefined) {
      url2 = url2 + identity.parentResourcePath;
    }
    url2 = url2 + '/';
    url2 = url2 + identity.resourceType;
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(identity.resourceName);
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(identity.resourceProviderApiVersion));
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 404) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      if (statusCode === 200) {
        result.exists = true;
      } else {
        result.exists = false;
      }
      
      return callback(null, result);
    });
  };
  
  /**
   * Create a resource.
   * 
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   * 
   * @param {ResourceIdentity} identity Resource identity.
   * 
   * @param {string} identity.resourceName Gets or sets resource name.
   * 
   * @param {string} identity.resourceProviderNamespace Gets or sets namespace
   * of the resource provider.
   * 
   * @param {string} identity.resourceType Gets or sets resource type.
   * 
   * @param {string} identity.resourceProviderApiVersion Gets or sets API
   * version of the resource provider.
   * 
   * @param {string} [identity.parentResourcePath] Gets or sets parent resource
   * path (optional).
   * 
   * @param {GenericResource} parameters Create or update resource parameters.
   * 
   * @param {string} [parameters.properties] Gets or sets the resource
   * properties.
   * 
   * @param {string} [parameters.provisioningState] Gets or sets resource
   * provisioning state.
   * 
   * @param {Plan} [parameters.plan] Gets or sets the plan of the resource.
   * 
   * @param {string} [parameters.plan.name] Gets or sets the plan ID.
   * 
   * @param {string} [parameters.plan.publisher] Gets or sets the publisher ID.
   * 
   * @param {string} [parameters.plan.product] Gets or sets the offer ID.
   * 
   * @param {string} [parameters.plan.promotionCode] Gets or sets the promotion
   * code.
   * 
   * @param {string} parameters.location Gets or sets the location of the
   * resource.
   * 
   * @param {object} [parameters.tags] Gets or sets the tags attached to the
   * resource.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceOperations.prototype.createOrUpdate = function(resourceGroupName, identity, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (identity === null || identity === undefined) {
      return callback(new Error('identity cannot be null.'));
    }
    if (identity.resourceName === null || identity.resourceName === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceProviderApiVersion === null || identity.resourceProviderApiVersion === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceProviderNamespace === null || identity.resourceProviderNamespace === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceType === null || identity.resourceType === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.location === null || parameters.location === undefined) {
      return callback(new Error('parameters.location cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + encodeURIComponent(identity.resourceProviderNamespace);
    url2 = url2 + '/';
    if (identity.parentResourcePath !== null && identity.parentResourcePath !== undefined) {
      url2 = url2 + identity.parentResourcePath;
    }
    url2 = url2 + '/';
    url2 = url2 + identity.resourceType;
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(identity.resourceName);
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(identity.resourceProviderApiVersion));
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var genericResourceValue = {};
    requestDoc = genericResourceValue;
    
    if (parameters.properties !== null && parameters.properties !== undefined) {
      genericResourceValue['properties'] = parameters.properties;
    }
    
    if (parameters.provisioningState !== null && parameters.provisioningState !== undefined) {
      genericResourceValue['provisioningState'] = parameters.provisioningState;
    }
    
    if (parameters.plan !== null && parameters.plan !== undefined) {
      var planValue = {};
      genericResourceValue['plan'] = planValue;
      
      if (parameters.plan.name !== null && parameters.plan.name !== undefined) {
        planValue['name'] = parameters.plan.name;
      }
      
      if (parameters.plan.publisher !== null && parameters.plan.publisher !== undefined) {
        planValue['publisher'] = parameters.plan.publisher;
      }
      
      if (parameters.plan.product !== null && parameters.plan.product !== undefined) {
        planValue['product'] = parameters.plan.product;
      }
      
      if (parameters.plan.promotionCode !== null && parameters.plan.promotionCode !== undefined) {
        planValue['promotionCode'] = parameters.plan.promotionCode;
      }
    }
    
    genericResourceValue['location'] = parameters.location;
    
    if (parameters.tags !== null && parameters.tags !== undefined) {
      var tagsDictionary = {};
      for (var tagsKey in parameters.tags) {
        var tagsValue = parameters.tags[tagsKey];
        tagsDictionary[tagsKey] = tagsValue;
      }
      genericResourceValue['tags'] = tagsDictionary;
    }
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 201) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var resourceInstance = { tags: {} };
          result.resource = resourceInstance;
          
          var propertiesValue = responseDoc['properties'];
          if (propertiesValue !== null && propertiesValue !== undefined) {
            var provisioningStateValue = propertiesValue['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              resourceInstance.provisioningState = provisioningStateInstance;
            }
          }
          
          var propertiesValue2 = responseDoc['properties'];
          if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
            var propertiesInstance = propertiesValue2;
            resourceInstance.properties = propertiesInstance;
          }
          
          var provisioningStateValue2 = responseDoc['provisioningState'];
          if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
            var provisioningStateInstance2 = provisioningStateValue2;
            resourceInstance.provisioningState = provisioningStateInstance2;
          }
          
          var planValue2 = responseDoc['plan'];
          if (planValue2 !== null && planValue2 !== undefined) {
            var planInstance = {};
            resourceInstance.plan = planInstance;
            
            var nameValue = planValue2['name'];
            if (nameValue !== null && nameValue !== undefined) {
              var nameInstance = nameValue;
              planInstance.name = nameInstance;
            }
            
            var publisherValue = planValue2['publisher'];
            if (publisherValue !== null && publisherValue !== undefined) {
              var publisherInstance = publisherValue;
              planInstance.publisher = publisherInstance;
            }
            
            var productValue = planValue2['product'];
            if (productValue !== null && productValue !== undefined) {
              var productInstance = productValue;
              planInstance.product = productInstance;
            }
            
            var promotionCodeValue = planValue2['promotionCode'];
            if (promotionCodeValue !== null && promotionCodeValue !== undefined) {
              var promotionCodeInstance = promotionCodeValue;
              planInstance.promotionCode = promotionCodeInstance;
            }
          }
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            resourceInstance.id = idInstance;
          }
          
          var nameValue2 = responseDoc['name'];
          if (nameValue2 !== null && nameValue2 !== undefined) {
            var nameInstance2 = nameValue2;
            resourceInstance.name = nameInstance2;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            resourceInstance.type = typeInstance;
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            resourceInstance.location = locationInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey2 = property;
              var tagsValue2 = tagsSequenceElement[property];
              resourceInstance.tags[tagsKey2] = tagsValue2;
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Delete resource and all of its resources.
   * 
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   * 
   * @param {ResourceIdentity} identity Resource identity.
   * 
   * @param {string} identity.resourceName Gets or sets resource name.
   * 
   * @param {string} identity.resourceProviderNamespace Gets or sets namespace
   * of the resource provider.
   * 
   * @param {string} identity.resourceType Gets or sets resource type.
   * 
   * @param {string} identity.resourceProviderApiVersion Gets or sets API
   * version of the resource provider.
   * 
   * @param {string} [identity.parentResourcePath] Gets or sets parent resource
   * path (optional).
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceOperations.prototype.deleteMethod = function(resourceGroupName, identity, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (identity === null || identity === undefined) {
      return callback(new Error('identity cannot be null.'));
    }
    if (identity.resourceName === null || identity.resourceName === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceProviderApiVersion === null || identity.resourceProviderApiVersion === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceProviderNamespace === null || identity.resourceProviderNamespace === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceType === null || identity.resourceType === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + encodeURIComponent(identity.resourceProviderNamespace);
    url2 = url2 + '/';
    if (identity.parentResourcePath !== null && identity.parentResourcePath !== undefined) {
      url2 = url2 + identity.parentResourcePath;
    }
    url2 = url2 + '/';
    url2 = url2 + identity.resourceType;
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(identity.resourceName);
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(identity.resourceProviderApiVersion));
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 202 && statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Returns a resource belonging to a resource group.
   * 
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   * 
   * @param {ResourceIdentity} identity Resource identity.
   * 
   * @param {string} identity.resourceName Gets or sets resource name.
   * 
   * @param {string} identity.resourceProviderNamespace Gets or sets namespace
   * of the resource provider.
   * 
   * @param {string} identity.resourceType Gets or sets resource type.
   * 
   * @param {string} identity.resourceProviderApiVersion Gets or sets API
   * version of the resource provider.
   * 
   * @param {string} [identity.parentResourcePath] Gets or sets parent resource
   * path (optional).
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceOperations.prototype.get = function(resourceGroupName, identity, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (resourceGroupName !== null && resourceGroupName !== undefined && resourceGroupName.length > 1000) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (/^[-\w\._]+$/.test(resourceGroupName) === false) {
      return callback(new Error('resourceGroupName is outside the valid range.'));
    }
    if (identity === null || identity === undefined) {
      return callback(new Error('identity cannot be null.'));
    }
    if (identity.resourceName === null || identity.resourceName === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceProviderApiVersion === null || identity.resourceProviderApiVersion === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceProviderNamespace === null || identity.resourceProviderNamespace === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceType === null || identity.resourceType === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourcegroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + encodeURIComponent(identity.resourceProviderNamespace);
    url2 = url2 + '/';
    if (identity.parentResourcePath !== null && identity.parentResourcePath !== undefined) {
      url2 = url2 + identity.parentResourcePath;
    }
    url2 = url2 + '/';
    url2 = url2 + identity.resourceType;
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(identity.resourceName);
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(identity.resourceProviderApiVersion));
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 204) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var resourceInstance = { tags: {} };
          result.resource = resourceInstance;
          
          var propertiesValue = responseDoc['properties'];
          if (propertiesValue !== null && propertiesValue !== undefined) {
            var provisioningStateValue = propertiesValue['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              resourceInstance.provisioningState = provisioningStateInstance;
            }
          }
          
          var propertiesValue2 = responseDoc['properties'];
          if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
            var propertiesInstance = propertiesValue2;
            resourceInstance.properties = propertiesInstance;
          }
          
          var provisioningStateValue2 = responseDoc['provisioningState'];
          if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
            var provisioningStateInstance2 = provisioningStateValue2;
            resourceInstance.provisioningState = provisioningStateInstance2;
          }
          
          var planValue = responseDoc['plan'];
          if (planValue !== null && planValue !== undefined) {
            var planInstance = {};
            resourceInstance.plan = planInstance;
            
            var nameValue = planValue['name'];
            if (nameValue !== null && nameValue !== undefined) {
              var nameInstance = nameValue;
              planInstance.name = nameInstance;
            }
            
            var publisherValue = planValue['publisher'];
            if (publisherValue !== null && publisherValue !== undefined) {
              var publisherInstance = publisherValue;
              planInstance.publisher = publisherInstance;
            }
            
            var productValue = planValue['product'];
            if (productValue !== null && productValue !== undefined) {
              var productInstance = productValue;
              planInstance.product = productInstance;
            }
            
            var promotionCodeValue = planValue['promotionCode'];
            if (promotionCodeValue !== null && promotionCodeValue !== undefined) {
              var promotionCodeInstance = promotionCodeValue;
              planInstance.promotionCode = promotionCodeInstance;
            }
          }
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            resourceInstance.id = idInstance;
          }
          
          var nameValue2 = responseDoc['name'];
          if (nameValue2 !== null && nameValue2 !== undefined) {
            var nameInstance2 = nameValue2;
            resourceInstance.name = nameInstance2;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            resourceInstance.type = typeInstance;
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            resourceInstance.location = locationInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey = property;
              var tagsValue = tagsSequenceElement[property];
              resourceInstance.tags[tagsKey] = tagsValue;
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get all of the resources under a subscription.
   * 
   * @param {ResourceListParameters} [parametersOrCallback] Query parameters.
   * If null is passed returns all resource groups.
   * 
   * @param {string} [parametersOrCallback.resourceGroupName] Gets or sets
   * resource resource group to filter by. Optional.
   * 
   * @param {string} [parametersOrCallback.resourceType] Filter the results for
   * a particular resource type. Optional.
   * 
   * @param {string} [parametersOrCallback.tagName] Filter the results based on
   * a particular tag name. Optional.
   * 
   * @param {string} [parametersOrCallback.tagValue] Filter the results for a
   * tag name along with a particular tag value. Optional.
   * 
   * @param {number} [parametersOrCallback.top] Number of records to return.
   * Optional.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceOperations.prototype.list = function(parametersOrCallback, callback) {
    var parameters = parametersOrCallback;
    if (_.isFunction(parameters)) {
      callback = parameters;
      parameters = null;
    }
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/';
    if (parameters !== null && parameters !== undefined && parameters.resourceGroupName !== null && parameters.resourceGroupName !== undefined) {
      url2 = url2 + 'resourceGroups/' + encodeURIComponent(parameters.resourceGroupName) + '/';
    }
    url2 = url2 + 'resources';
    var queryParameters = [];
    var odataFilter = [];
    if (parameters !== null && parameters !== undefined && parameters.resourceType !== null && parameters.resourceType !== undefined) {
      odataFilter.push('resourceType eq \'' + encodeURIComponent(parameters.resourceType) + '\'');
    }
    if (parameters !== null && parameters !== undefined && parameters.tagName !== null && parameters.tagName !== undefined) {
      odataFilter.push('tagname eq \'' + encodeURIComponent(parameters.tagName) + '\'');
    }
    if (parameters !== null && parameters !== undefined && parameters.tagValue !== null && parameters.tagValue !== undefined) {
      odataFilter.push('tagvalue eq \'' + encodeURIComponent(parameters.tagValue) + '\'');
    }
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(' and '));
    }
    if (parameters !== null && parameters !== undefined && parameters.top !== null && parameters.top !== undefined) {
      queryParameters.push('$top=' + encodeURIComponent(parameters.top.toString()));
    }
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { resources: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var resourceJsonFormatInstance = { tags: {} };
              result.resources.push(resourceJsonFormatInstance);
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  resourceJsonFormatInstance.provisioningState = provisioningStateInstance;
                }
              }
              
              var propertiesValue2 = valueValue['properties'];
              if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
                var propertiesInstance = propertiesValue2;
                resourceJsonFormatInstance.properties = propertiesInstance;
              }
              
              var provisioningStateValue2 = valueValue['provisioningState'];
              if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
                var provisioningStateInstance2 = provisioningStateValue2;
                resourceJsonFormatInstance.provisioningState = provisioningStateInstance2;
              }
              
              var planValue = valueValue['plan'];
              if (planValue !== null && planValue !== undefined) {
                var planInstance = {};
                resourceJsonFormatInstance.plan = planInstance;
                
                var nameValue = planValue['name'];
                if (nameValue !== null && nameValue !== undefined) {
                  var nameInstance = nameValue;
                  planInstance.name = nameInstance;
                }
                
                var publisherValue = planValue['publisher'];
                if (publisherValue !== null && publisherValue !== undefined) {
                  var publisherInstance = publisherValue;
                  planInstance.publisher = publisherInstance;
                }
                
                var productValue = planValue['product'];
                if (productValue !== null && productValue !== undefined) {
                  var productInstance = productValue;
                  planInstance.product = productInstance;
                }
                
                var promotionCodeValue = planValue['promotionCode'];
                if (promotionCodeValue !== null && promotionCodeValue !== undefined) {
                  var promotionCodeInstance = promotionCodeValue;
                  planInstance.promotionCode = promotionCodeInstance;
                }
              }
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                resourceJsonFormatInstance.id = idInstance;
              }
              
              var nameValue2 = valueValue['name'];
              if (nameValue2 !== null && nameValue2 !== undefined) {
                var nameInstance2 = nameValue2;
                resourceJsonFormatInstance.name = nameInstance2;
              }
              
              var typeValue = valueValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                resourceJsonFormatInstance.type = typeInstance;
              }
              
              var locationValue = valueValue['location'];
              if (locationValue !== null && locationValue !== undefined) {
                var locationInstance = locationValue;
                resourceJsonFormatInstance.location = locationInstance;
              }
              
              var tagsSequenceElement = valueValue['tags'];
              if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                for (var property in tagsSequenceElement) {
                  var tagsKey = property;
                  var tagsValue = tagsSequenceElement[property];
                  resourceJsonFormatInstance.tags[tagsKey] = tagsValue;
                }
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a list of deployments.
   * 
   * @param {string} nextLink NextLink from the previous successful call to
   * List operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceOperations.prototype.listNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { resources: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var resourceJsonFormatInstance = { tags: {} };
              result.resources.push(resourceJsonFormatInstance);
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  resourceJsonFormatInstance.provisioningState = provisioningStateInstance;
                }
              }
              
              var propertiesValue2 = valueValue['properties'];
              if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
                var propertiesInstance = propertiesValue2;
                resourceJsonFormatInstance.properties = propertiesInstance;
              }
              
              var provisioningStateValue2 = valueValue['provisioningState'];
              if (provisioningStateValue2 !== null && provisioningStateValue2 !== undefined) {
                var provisioningStateInstance2 = provisioningStateValue2;
                resourceJsonFormatInstance.provisioningState = provisioningStateInstance2;
              }
              
              var planValue = valueValue['plan'];
              if (planValue !== null && planValue !== undefined) {
                var planInstance = {};
                resourceJsonFormatInstance.plan = planInstance;
                
                var nameValue = planValue['name'];
                if (nameValue !== null && nameValue !== undefined) {
                  var nameInstance = nameValue;
                  planInstance.name = nameInstance;
                }
                
                var publisherValue = planValue['publisher'];
                if (publisherValue !== null && publisherValue !== undefined) {
                  var publisherInstance = publisherValue;
                  planInstance.publisher = publisherInstance;
                }
                
                var productValue = planValue['product'];
                if (productValue !== null && productValue !== undefined) {
                  var productInstance = productValue;
                  planInstance.product = productInstance;
                }
                
                var promotionCodeValue = planValue['promotionCode'];
                if (promotionCodeValue !== null && promotionCodeValue !== undefined) {
                  var promotionCodeInstance = promotionCodeValue;
                  planInstance.promotionCode = promotionCodeInstance;
                }
              }
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                resourceJsonFormatInstance.id = idInstance;
              }
              
              var nameValue2 = valueValue['name'];
              if (nameValue2 !== null && nameValue2 !== undefined) {
                var nameInstance2 = nameValue2;
                resourceJsonFormatInstance.name = nameInstance2;
              }
              
              var typeValue = valueValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                resourceJsonFormatInstance.type = typeInstance;
              }
              
              var locationValue = valueValue['location'];
              if (locationValue !== null && locationValue !== undefined) {
                var locationInstance = locationValue;
                resourceJsonFormatInstance.location = locationInstance;
              }
              
              var tagsSequenceElement = valueValue['tags'];
              if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                for (var property in tagsSequenceElement) {
                  var tagsKey = property;
                  var tagsValue = tagsSequenceElement[property];
                  resourceJsonFormatInstance.tags[tagsKey] = tagsValue;
                }
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Move resources within or across subscriptions.
   * 
   * @param {string} sourceResourceGroupName Source resource group name.
   * 
   * @param {ResourcesMoveInfo} parameters move resources' parameters.
   * 
   * @param {IEnumerable} [parameters.resources] Gets or sets the ids of the
   * resources.
   * 
   * @param {string} [parameters.targetResourceGroup] The target resource group.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceOperations.prototype.moveResources = function(sourceResourceGroupName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.resources.beginMoving(sourceResourceGroupName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = result.retryAfter;
      if (delayInSeconds === 0) {
        delayInSeconds = 30;
      }
      if (client2.longRunningOperationInitialTimeout >= 0) {
        delayInSeconds = client2.longRunningOperationInitialTimeout;
      }
      
      var pollOperation = function () {
        setTimeout(function () {
          return client2.getLongRunningOperationStatus(result.operationStatusLink, function (err2, result2) {
            if (err2 !== null && err2 !== undefined) {
              return callback(err2);
            } else {
              if (result2.status !== 'InProgress') {
                return callback(null, result2);
              } else {
                delayInSeconds = result2.retryAfter;
                if (delayInSeconds === 0) {
                  delayInSeconds = 15;
                }
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  return ResourceOperations;
})();

var ResourceProviderOperationDetailsOperations = ( /** @lends ResourceProviderOperationDetailsOperations */ function() {
  /**
   * @class
   * Operations for managing Resource provider operations.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ResourceManagementClient] {@link
   * ResourceManagementClient~ResourceManagementClient}.
   * See [resourceProviderOperationDetails] {@link
   * ResourceManagementClient~ResourceManagementClient#resourceProviderOperationDetails}.
   * Initializes a new instance of the
   * ResourceProviderOperationDetailsOperations class.
   * @constructor
   * 
   * @param {ResourceManagementClient} client Reference to the service client.
   */
  function ResourceProviderOperationDetailsOperations(client) {
    this.client = client;
  }
  
  /**
   * Gets a list of resource providers.
   * 
   * @param {ResourceIdentity} identity Resource identity.
   * 
   * @param {string} identity.resourceName Gets or sets resource name.
   * 
   * @param {string} identity.resourceProviderNamespace Gets or sets namespace
   * of the resource provider.
   * 
   * @param {string} identity.resourceType Gets or sets resource type.
   * 
   * @param {string} identity.resourceProviderApiVersion Gets or sets API
   * version of the resource provider.
   * 
   * @param {string} [identity.parentResourcePath] Gets or sets parent resource
   * path (optional).
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ResourceProviderOperationDetailsOperations.prototype.list = function(identity, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (identity === null || identity === undefined) {
      return callback(new Error('identity cannot be null.'));
    }
    if (identity.resourceName === null || identity.resourceName === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceProviderApiVersion === null || identity.resourceProviderApiVersion === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceProviderNamespace === null || identity.resourceProviderNamespace === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    if (identity.resourceType === null || identity.resourceType === undefined) {
      return callback(new Error('identity. cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/providers/';
    url2 = url2 + encodeURIComponent(identity.resourceProviderNamespace);
    url2 = url2 + '/operations';
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(identity.resourceProviderApiVersion));
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 204) {
        var responseContent = body;
        result = { resourceProviderOperationDetails: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var resourceProviderOperationDefinitionInstance = {};
              result.resourceProviderOperationDetails.push(resourceProviderOperationDefinitionInstance);
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                resourceProviderOperationDefinitionInstance.name = nameInstance;
              }
              
              var displayValue = valueValue['display'];
              if (displayValue !== null && displayValue !== undefined) {
                var displayInstance = {};
                resourceProviderOperationDefinitionInstance.resourceProviderOperationDisplayProperties = displayInstance;
                
                var publisherValue = displayValue['publisher'];
                if (publisherValue !== null && publisherValue !== undefined) {
                  var publisherInstance = publisherValue;
                  displayInstance.publisher = publisherInstance;
                }
                
                var providerValue = displayValue['provider'];
                if (providerValue !== null && providerValue !== undefined) {
                  var providerInstance = providerValue;
                  displayInstance.provider = providerInstance;
                }
                
                var resourceValue = displayValue['resource'];
                if (resourceValue !== null && resourceValue !== undefined) {
                  var resourceInstance = resourceValue;
                  displayInstance.resource = resourceInstance;
                }
                
                var operationValue = displayValue['operation'];
                if (operationValue !== null && operationValue !== undefined) {
                  var operationInstance = operationValue;
                  displayInstance.operation = operationInstance;
                }
                
                var descriptionValue = displayValue['description'];
                if (descriptionValue !== null && descriptionValue !== undefined) {
                  var descriptionInstance = descriptionValue;
                  displayInstance.description = descriptionInstance;
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ResourceProviderOperationDetailsOperations;
})();

var TagOperations = ( /** @lends TagOperations */ function() {
  /**
   * @class
   * Operations for managing tags.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [ResourceManagementClient] {@link
   * ResourceManagementClient~ResourceManagementClient}.
   * See [tags] {@link ResourceManagementClient~ResourceManagementClient#tags}.
   * Initializes a new instance of the TagOperations class.
   * @constructor
   * 
   * @param {ResourceManagementClient} client Reference to the service client.
   */
  function TagOperations(client) {
    this.client = client;
  }
  
  /**
   * Create a subscription resource tag.
   * 
   * @param {string} tagName The name of the tag.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TagOperations.prototype.createOrUpdate = function(tagName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (tagName === null || tagName === undefined) {
      return callback(new Error('tagName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/tagNames/';
    url2 = url2 + encodeURIComponent(tagName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 201) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var tagInstance = { values: [] };
          result.tag = tagInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            tagInstance.id = idInstance;
          }
          
          var tagNameValue = responseDoc['tagName'];
          if (tagNameValue !== null && tagNameValue !== undefined) {
            var tagNameInstance = tagNameValue;
            tagInstance.name = tagNameInstance;
          }
          
          var countValue = responseDoc['count'];
          if (countValue !== null && countValue !== undefined) {
            var countInstance = {};
            tagInstance.count = countInstance;
            
            var typeValue = countValue['type'];
            if (typeValue !== null && typeValue !== undefined) {
              var typeInstance = typeValue;
              countInstance.type = typeInstance;
            }
            
            var valueValue = countValue['value'];
            if (valueValue !== null && valueValue !== undefined) {
              var valueInstance = valueValue;
              countInstance.value = valueInstance;
            }
          }
          
          var valuesArray = responseDoc['values'];
          if (valuesArray !== null && valuesArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valuesArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valuesValue = valuesArray[loweredIndex1];
              var tagValueInstance = {};
              tagInstance.values.push(tagValueInstance);
              
              var idValue2 = valuesValue['id'];
              if (idValue2 !== null && idValue2 !== undefined) {
                var idInstance2 = idValue2;
                tagValueInstance.id = idInstance2;
              }
              
              var tagValueValue = valuesValue['tagValue'];
              if (tagValueValue !== null && tagValueValue !== undefined) {
                var tagValueInstance2 = tagValueValue;
                tagValueInstance.value = tagValueInstance2;
              }
              
              var countValue2 = valuesValue['count'];
              if (countValue2 !== null && countValue2 !== undefined) {
                var countInstance2 = {};
                tagValueInstance.count = countInstance2;
                
                var typeValue2 = countValue2['type'];
                if (typeValue2 !== null && typeValue2 !== undefined) {
                  var typeInstance2 = typeValue2;
                  countInstance2.type = typeInstance2;
                }
                
                var valueValue2 = countValue2['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance2 = valueValue2;
                  countInstance2.value = valueInstance2;
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Create a subscription resource tag value.
   * 
   * @param {string} tagName The name of the tag.
   * 
   * @param {string} tagValue The value of the tag.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TagOperations.prototype.createOrUpdateValue = function(tagName, tagValue, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (tagName === null || tagName === undefined) {
      return callback(new Error('tagName cannot be null.'));
    }
    if (tagValue === null || tagValue === undefined) {
      return callback(new Error('tagValue cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/tagNames/';
    url2 = url2 + encodeURIComponent(tagName);
    url2 = url2 + '/tagValues/';
    url2 = url2 + encodeURIComponent(tagValue);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 201) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 201) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueInstance = {};
          result.value = valueInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            valueInstance.id = idInstance;
          }
          
          var tagValueValue = responseDoc['tagValue'];
          if (tagValueValue !== null && tagValueValue !== undefined) {
            var tagValueInstance = tagValueValue;
            valueInstance.value = tagValueInstance;
          }
          
          var countValue = responseDoc['count'];
          if (countValue !== null && countValue !== undefined) {
            var countInstance = {};
            valueInstance.count = countInstance;
            
            var typeValue = countValue['type'];
            if (typeValue !== null && typeValue !== undefined) {
              var typeInstance = typeValue;
              countInstance.type = typeInstance;
            }
            
            var valueValue = countValue['value'];
            if (valueValue !== null && valueValue !== undefined) {
              var valueInstance2 = valueValue;
              countInstance.value = valueInstance2;
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Delete a subscription resource tag.
   * 
   * @param {string} tagName The name of the tag.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TagOperations.prototype.deleteMethod = function(tagName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (tagName === null || tagName === undefined) {
      return callback(new Error('tagName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/tagNames/';
    url2 = url2 + encodeURIComponent(tagName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Delete a subscription resource tag value.
   * 
   * @param {string} tagName The name of the tag.
   * 
   * @param {string} tagValue The value of the tag.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TagOperations.prototype.deleteValue = function(tagName, tagValue, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (tagName === null || tagName === undefined) {
      return callback(new Error('tagName cannot be null.'));
    }
    if (tagValue === null || tagValue === undefined) {
      return callback(new Error('tagValue cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/tagNames/';
    url2 = url2 + encodeURIComponent(tagName);
    url2 = url2 + '/tagValues/';
    url2 = url2 + encodeURIComponent(tagValue);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200 && statusCode !== 204) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a list of subscription resource tags.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TagOperations.prototype.list = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/tagNames';
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { tags: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var tagDetailsInstance = { values: [] };
              result.tags.push(tagDetailsInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                tagDetailsInstance.id = idInstance;
              }
              
              var tagNameValue = valueValue['tagName'];
              if (tagNameValue !== null && tagNameValue !== undefined) {
                var tagNameInstance = tagNameValue;
                tagDetailsInstance.name = tagNameInstance;
              }
              
              var countValue = valueValue['count'];
              if (countValue !== null && countValue !== undefined) {
                var countInstance = {};
                tagDetailsInstance.count = countInstance;
                
                var typeValue = countValue['type'];
                if (typeValue !== null && typeValue !== undefined) {
                  var typeInstance = typeValue;
                  countInstance.type = typeInstance;
                }
                
                var valueValue2 = countValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  countInstance.value = valueInstance;
                }
              }
              
              var valuesArray = valueValue['values'];
              if (valuesArray !== null && valuesArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < valuesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var valuesValue = valuesArray[loweredIndex2];
                  var tagValueInstance = {};
                  tagDetailsInstance.values.push(tagValueInstance);
                  
                  var idValue2 = valuesValue['id'];
                  if (idValue2 !== null && idValue2 !== undefined) {
                    var idInstance2 = idValue2;
                    tagValueInstance.id = idInstance2;
                  }
                  
                  var tagValueValue = valuesValue['tagValue'];
                  if (tagValueValue !== null && tagValueValue !== undefined) {
                    var tagValueInstance2 = tagValueValue;
                    tagValueInstance.value = tagValueInstance2;
                  }
                  
                  var countValue2 = valuesValue['count'];
                  if (countValue2 !== null && countValue2 !== undefined) {
                    var countInstance2 = {};
                    tagValueInstance.count = countInstance2;
                    
                    var typeValue2 = countValue2['type'];
                    if (typeValue2 !== null && typeValue2 !== undefined) {
                      var typeInstance2 = typeValue2;
                      countInstance2.type = typeInstance2;
                    }
                    
                    var valueValue3 = countValue2['value'];
                    if (valueValue3 !== null && valueValue3 !== undefined) {
                      var valueInstance2 = valueValue3;
                      countInstance2.value = valueInstance2;
                    }
                  }
                }
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Get a list of tags under a subscription.
   * 
   * @param {string} nextLink NextLink from the previous successful call to
   * List operation.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  TagOperations.prototype.listNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode !== 200) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200) {
        var responseContent = body;
        result = { tags: [] };
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var tagDetailsInstance = { values: [] };
              result.tags.push(tagDetailsInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                tagDetailsInstance.id = idInstance;
              }
              
              var tagNameValue = valueValue['tagName'];
              if (tagNameValue !== null && tagNameValue !== undefined) {
                var tagNameInstance = tagNameValue;
                tagDetailsInstance.name = tagNameInstance;
              }
              
              var countValue = valueValue['count'];
              if (countValue !== null && countValue !== undefined) {
                var countInstance = {};
                tagDetailsInstance.count = countInstance;
                
                var typeValue = countValue['type'];
                if (typeValue !== null && typeValue !== undefined) {
                  var typeInstance = typeValue;
                  countInstance.type = typeInstance;
                }
                
                var valueValue2 = countValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  countInstance.value = valueInstance;
                }
              }
              
              var valuesArray = valueValue['values'];
              if (valuesArray !== null && valuesArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < valuesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var valuesValue = valuesArray[loweredIndex2];
                  var tagValueInstance = {};
                  tagDetailsInstance.values.push(tagValueInstance);
                  
                  var idValue2 = valuesValue['id'];
                  if (idValue2 !== null && idValue2 !== undefined) {
                    var idInstance2 = idValue2;
                    tagValueInstance.id = idInstance2;
                  }
                  
                  var tagValueValue = valuesValue['tagValue'];
                  if (tagValueValue !== null && tagValueValue !== undefined) {
                    var tagValueInstance2 = tagValueValue;
                    tagValueInstance.value = tagValueInstance2;
                  }
                  
                  var countValue2 = valuesValue['count'];
                  if (countValue2 !== null && countValue2 !== undefined) {
                    var countInstance2 = {};
                    tagValueInstance.count = countInstance2;
                    
                    var typeValue2 = countValue2['type'];
                    if (typeValue2 !== null && typeValue2 !== undefined) {
                      var typeInstance2 = typeValue2;
                      countInstance2.type = typeInstance2;
                    }
                    
                    var valueValue3 = countValue2['value'];
                    if (valueValue3 !== null && valueValue3 !== undefined) {
                      var valueInstance2 = valueValue3;
                      countInstance2.value = valueInstance2;
                    }
                  }
                }
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            result.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return TagOperations;
})();