/* 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 uuid = require('node-uuid');
var azureCommon = require('azure-common');
var Service = azureCommon.Service;
var WebResource = azureCommon.WebResource;
var OperationStatus = azureCommon.OperationStatus;

var StorageManagementClient = ( /** @lends StorageManagementClient */ function() {
  /**
   * @class
   * The Storage Management Client.
   * Initializes a new instance of the StorageManagementClient 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 StorageManagementClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    StorageManagementClient['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-05-01-preview';
    }
    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
     * [StorageAccountOperations](-StorageAccountOperations.html) object.
     * @type {object}
     */
    this.storageAccounts = new StorageAccountOperations(this);
  }
  
  util.inherits(StorageManagementClient, 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 The URL where the status of the
   * long-running operation can be checked.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StorageManagementClient.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
    if (uuid() !== null && uuid() !== undefined) {
      httpRequest.headers['x-ms-client-request-id'] = uuid();
    }
    
    // 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 !== 500) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 202 || statusCode === 500) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var storageAccountInstance = { tags: {} };
          result.storageAccount = storageAccountInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            storageAccountInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            storageAccountInstance.name = nameInstance;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            storageAccountInstance.type = typeInstance;
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            storageAccountInstance.location = locationInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey = property;
              var tagsValue = tagsSequenceElement[property];
              storageAccountInstance.tags[tagsKey] = tagsValue;
            }
          }
          
          var propertiesValue = responseDoc['properties'];
          if (propertiesValue !== null && propertiesValue !== undefined) {
            var provisioningStateValue = propertiesValue['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              storageAccountInstance.provisioningState = provisioningStateInstance;
            }
            
            var accountTypeValue = propertiesValue['accountType'];
            if (accountTypeValue !== null && accountTypeValue !== undefined) {
              var accountTypeInstance = accountTypeValue;
              storageAccountInstance.accountType = accountTypeInstance;
            }
            
            var primaryEndpointsValue = propertiesValue['primaryEndpoints'];
            if (primaryEndpointsValue !== null && primaryEndpointsValue !== undefined) {
              var primaryEndpointsInstance = {};
              storageAccountInstance.primaryEndpoints = primaryEndpointsInstance;
              
              var blobValue = primaryEndpointsValue['blob'];
              if (blobValue !== null && blobValue !== undefined) {
                var blobInstance = blobValue;
                primaryEndpointsInstance.blob = blobInstance;
              }
              
              var queueValue = primaryEndpointsValue['queue'];
              if (queueValue !== null && queueValue !== undefined) {
                var queueInstance = queueValue;
                primaryEndpointsInstance.queue = queueInstance;
              }
              
              var tableValue = primaryEndpointsValue['table'];
              if (tableValue !== null && tableValue !== undefined) {
                var tableInstance = tableValue;
                primaryEndpointsInstance.table = tableInstance;
              }
            }
            
            var primaryLocationValue = propertiesValue['primaryLocation'];
            if (primaryLocationValue !== null && primaryLocationValue !== undefined) {
              var primaryLocationInstance = primaryLocationValue;
              storageAccountInstance.primaryLocation = primaryLocationInstance;
            }
            
            var statusOfPrimaryValue = propertiesValue['statusOfPrimary'];
            if (statusOfPrimaryValue !== null && statusOfPrimaryValue !== undefined) {
              var statusOfPrimaryInstance = statusOfPrimaryValue;
              storageAccountInstance.statusOfPrimary = statusOfPrimaryInstance;
            }
            
            var lastGeoFailoverTimeValue = propertiesValue['lastGeoFailoverTime'];
            if (lastGeoFailoverTimeValue !== null && lastGeoFailoverTimeValue !== undefined) {
              var lastGeoFailoverTimeInstance = lastGeoFailoverTimeValue;
              storageAccountInstance.lastGeoFailoverTime = lastGeoFailoverTimeInstance;
            }
            
            var secondaryLocationValue = propertiesValue['secondaryLocation'];
            if (secondaryLocationValue !== null && secondaryLocationValue !== undefined) {
              var secondaryLocationInstance = secondaryLocationValue;
              storageAccountInstance.secondaryLocation = secondaryLocationInstance;
            }
            
            var statusOfSecondaryValue = propertiesValue['statusOfSecondary'];
            if (statusOfSecondaryValue !== null && statusOfSecondaryValue !== undefined) {
              var statusOfSecondaryInstance = statusOfSecondaryValue;
              storageAccountInstance.statusOfSecondary = statusOfSecondaryInstance;
            }
            
            var creationTimeValue = propertiesValue['creationTime'];
            if (creationTimeValue !== null && creationTimeValue !== undefined) {
              var creationTimeInstance = creationTimeValue;
              storageAccountInstance.creationTime = creationTimeInstance;
            }
            
            var customDomainValue = propertiesValue['customDomain'];
            if (customDomainValue !== null && customDomainValue !== undefined) {
              var customDomainInstance = {};
              storageAccountInstance.customDomain = customDomainInstance;
              
              var nameValue2 = customDomainValue['name'];
              if (nameValue2 !== null && nameValue2 !== undefined) {
                var nameInstance2 = nameValue2;
                customDomainInstance.name = nameInstance2;
              }
              
              var useSubDomainValue = customDomainValue['useSubDomain'];
              if (useSubDomainValue !== null && useSubDomainValue !== undefined) {
                var useSubDomainInstance = useSubDomainValue;
                customDomainInstance.useSubDomain = useSubDomainInstance;
              }
            }
            
            var secondaryEndpointsValue = propertiesValue['secondaryEndpoints'];
            if (secondaryEndpointsValue !== null && secondaryEndpointsValue !== undefined) {
              var secondaryEndpointsInstance = {};
              storageAccountInstance.secondaryEndpoints = secondaryEndpointsInstance;
              
              var blobValue2 = secondaryEndpointsValue['blob'];
              if (blobValue2 !== null && blobValue2 !== undefined) {
                var blobInstance2 = blobValue2;
                secondaryEndpointsInstance.blob = blobInstance2;
              }
              
              var queueValue2 = secondaryEndpointsValue['queue'];
              if (queueValue2 !== null && queueValue2 !== undefined) {
                var queueInstance2 = queueValue2;
                secondaryEndpointsInstance.queue = queueInstance2;
              }
              
              var tableValue2 = secondaryEndpointsValue['table'];
              if (tableValue2 !== null && tableValue2 !== undefined) {
                var tableInstance2 = tableValue2;
                secondaryEndpointsInstance.table = tableInstance2;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.retryAfter = parseInt(response.headers['retryafter'], 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 === 500) {
        result.status = OperationStatus.InProgress;
      }
      if (statusCode === 200) {
        result.status = OperationStatus.Succeeded;
      }
      
      return callback(null, result);
    });
  };
  
  return StorageManagementClient;
})();
exports.StorageManagementClient = StorageManagementClient;

var StorageAccountOperations = ( /** @lends StorageAccountOperations */ function() {
  /**
   * @class
   * Operations for managing storage accounts.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [StorageManagementClient] {@link
   * StorageManagementClient~StorageManagementClient}.
   * See [storageAccounts] {@link
   * StorageManagementClient~StorageManagementClient#storageAccounts}.
   * Initializes a new instance of the StorageAccountOperations class.
   * @constructor
   * 
   * @param {StorageManagementClient} client Reference to the service client.
   */
  function StorageAccountOperations(client) {
    this.client = client;
  }
  
  /**
   * Asynchronously creates a new storage account with the specified
   * parameters. Existing accounts cannot be updated with this API and should
   * instead use the Update Storage Account API. If an account is already
   * created and subsequent PUT request is issued with exact same set of
   * properties, then HTTP 200 would be returned.
   * 
   * @param {string} resourceGroupName The name of the resource group within
   * the user’s subscription.
   * 
   * @param {string} accountName The name of the storage account within the
   * specified resource group. Storage account names must be between 3 and 24
   * characters in length and use numbers and lower-case letters only.
   * 
   * @param {StorageAccountCreateParameters} parameters The parameters to
   * provide for the created account.
   * 
   * @param {AccountType} parameters.accountType Gets or sets the account type.
   * 
   * @param {string} parameters.location Gets or sets the location of the
   * resource. This will be one of the supported and registered Azure Geo
   * Regions (e.g. West US, East US, Southeast Asia, etc.). The geo region of
   * a resource cannot be changed once it is created.
   * 
   * @param {object} [parameters.tags] Gets or sets a list of key value pairs
   * that describe the resource. These tags can be used in viewing and
   * grouping this resource (across resource groups). A maximum of 15 tags can
   * be provided for a resource. Each tag must have a key no greater than 128
   * characters and value no greater than 256 characters.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StorageAccountOperations.prototype.beginCreate = function(resourceGroupName, accountName, 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 (accountName === null || accountName === undefined) {
      return callback(new Error('accountName cannot be null.'));
    }
    if (accountName.length < 3) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    if (accountName.length > 24) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    for (var loweredIndex1 = 0; loweredIndex1 < accountName.length; loweredIndex1 = loweredIndex1 + 1) {
      var accountNameChar = accountName[loweredIndex1];
      if (accountNameChar === accountNameChar.toLowerCase() === false && isNaN(parseInt(accountNameChar, 10)) === false === false) {
        return callback(new Error('accountName is outside the valid range.'));
      }
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.accountType === null || parameters.accountType === undefined) {
      return callback(new Error('parameters.accountType 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/Microsoft.Storage/storageAccounts/';
    url2 = url2 + encodeURIComponent(accountName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-05-01-preview');
    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';
    if (uuid() !== null && uuid() !== undefined) {
      httpRequest.headers['x-ms-client-request-id'] = uuid();
    }
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var storageAccountCreateParametersJsonValue = {};
    requestDoc = storageAccountCreateParametersJsonValue;
    
    storageAccountCreateParametersJsonValue['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;
      }
      storageAccountCreateParametersJsonValue['tags'] = tagsDictionary;
    }
    
    var propertiesValue = {};
    storageAccountCreateParametersJsonValue['properties'] = propertiesValue;
    
    propertiesValue['accountType'] = parameters.accountType !== null && parameters.accountType !== undefined ? parameters.accountType.toString() : 'StandardLRS';
    
    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 !== 202) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      if (statusCode === 200 || statusCode === 202) {
        var responseContent = body;
        result = {};
        var responseDoc = null;
        if (responseContent) {
          responseDoc = JSON.parse(responseContent);
        }
        
        if (responseDoc !== null && responseDoc !== undefined) {
          var storageAccountInstance = { tags: {} };
          result.storageAccount = storageAccountInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            storageAccountInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            storageAccountInstance.name = nameInstance;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            storageAccountInstance.type = typeInstance;
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            storageAccountInstance.location = locationInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey2 = property;
              var tagsValue2 = tagsSequenceElement[property];
              storageAccountInstance.tags[tagsKey2] = tagsValue2;
            }
          }
          
          var propertiesValue2 = responseDoc['properties'];
          if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
            var provisioningStateValue = propertiesValue2['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              storageAccountInstance.provisioningState = provisioningStateInstance;
            }
            
            var accountTypeValue = propertiesValue2['accountType'];
            if (accountTypeValue !== null && accountTypeValue !== undefined) {
              var accountTypeInstance = accountTypeValue;
              storageAccountInstance.accountType = accountTypeInstance;
            }
            
            var primaryEndpointsValue = propertiesValue2['primaryEndpoints'];
            if (primaryEndpointsValue !== null && primaryEndpointsValue !== undefined) {
              var primaryEndpointsInstance = {};
              storageAccountInstance.primaryEndpoints = primaryEndpointsInstance;
              
              var blobValue = primaryEndpointsValue['blob'];
              if (blobValue !== null && blobValue !== undefined) {
                var blobInstance = blobValue;
                primaryEndpointsInstance.blob = blobInstance;
              }
              
              var queueValue = primaryEndpointsValue['queue'];
              if (queueValue !== null && queueValue !== undefined) {
                var queueInstance = queueValue;
                primaryEndpointsInstance.queue = queueInstance;
              }
              
              var tableValue = primaryEndpointsValue['table'];
              if (tableValue !== null && tableValue !== undefined) {
                var tableInstance = tableValue;
                primaryEndpointsInstance.table = tableInstance;
              }
            }
            
            var primaryLocationValue = propertiesValue2['primaryLocation'];
            if (primaryLocationValue !== null && primaryLocationValue !== undefined) {
              var primaryLocationInstance = primaryLocationValue;
              storageAccountInstance.primaryLocation = primaryLocationInstance;
            }
            
            var statusOfPrimaryValue = propertiesValue2['statusOfPrimary'];
            if (statusOfPrimaryValue !== null && statusOfPrimaryValue !== undefined) {
              var statusOfPrimaryInstance = statusOfPrimaryValue;
              storageAccountInstance.statusOfPrimary = statusOfPrimaryInstance;
            }
            
            var lastGeoFailoverTimeValue = propertiesValue2['lastGeoFailoverTime'];
            if (lastGeoFailoverTimeValue !== null && lastGeoFailoverTimeValue !== undefined) {
              var lastGeoFailoverTimeInstance = lastGeoFailoverTimeValue;
              storageAccountInstance.lastGeoFailoverTime = lastGeoFailoverTimeInstance;
            }
            
            var secondaryLocationValue = propertiesValue2['secondaryLocation'];
            if (secondaryLocationValue !== null && secondaryLocationValue !== undefined) {
              var secondaryLocationInstance = secondaryLocationValue;
              storageAccountInstance.secondaryLocation = secondaryLocationInstance;
            }
            
            var statusOfSecondaryValue = propertiesValue2['statusOfSecondary'];
            if (statusOfSecondaryValue !== null && statusOfSecondaryValue !== undefined) {
              var statusOfSecondaryInstance = statusOfSecondaryValue;
              storageAccountInstance.statusOfSecondary = statusOfSecondaryInstance;
            }
            
            var creationTimeValue = propertiesValue2['creationTime'];
            if (creationTimeValue !== null && creationTimeValue !== undefined) {
              var creationTimeInstance = creationTimeValue;
              storageAccountInstance.creationTime = creationTimeInstance;
            }
            
            var customDomainValue = propertiesValue2['customDomain'];
            if (customDomainValue !== null && customDomainValue !== undefined) {
              var customDomainInstance = {};
              storageAccountInstance.customDomain = customDomainInstance;
              
              var nameValue2 = customDomainValue['name'];
              if (nameValue2 !== null && nameValue2 !== undefined) {
                var nameInstance2 = nameValue2;
                customDomainInstance.name = nameInstance2;
              }
              
              var useSubDomainValue = customDomainValue['useSubDomain'];
              if (useSubDomainValue !== null && useSubDomainValue !== undefined) {
                var useSubDomainInstance = useSubDomainValue;
                customDomainInstance.useSubDomain = useSubDomainInstance;
              }
            }
            
            var secondaryEndpointsValue = propertiesValue2['secondaryEndpoints'];
            if (secondaryEndpointsValue !== null && secondaryEndpointsValue !== undefined) {
              var secondaryEndpointsInstance = {};
              storageAccountInstance.secondaryEndpoints = secondaryEndpointsInstance;
              
              var blobValue2 = secondaryEndpointsValue['blob'];
              if (blobValue2 !== null && blobValue2 !== undefined) {
                var blobInstance2 = blobValue2;
                secondaryEndpointsInstance.blob = blobInstance2;
              }
              
              var queueValue2 = secondaryEndpointsValue['queue'];
              if (queueValue2 !== null && queueValue2 !== undefined) {
                var queueInstance2 = queueValue2;
                secondaryEndpointsInstance.queue = queueInstance2;
              }
              
              var tableValue2 = secondaryEndpointsValue['table'];
              if (tableValue2 !== null && tableValue2 !== undefined) {
                var tableInstance2 = tableValue2;
                secondaryEndpointsInstance.table = tableInstance2;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.operationStatusLink = response.headers['location'];
      result.retryAfter = parseInt(response.headers['retryafter'], 10);
      result.requestId = response.headers['x-ms-request-id'];
      if (statusCode === 409 || statusCode === 400) {
        result.status = OperationStatus.Failed;
      }
      if (statusCode === 200) {
        result.status = OperationStatus.Succeeded;
      }
      
      return callback(null, result);
    });
  };
  
  /**
   * Checks that account name is valid and is not in use.
   * 
   * @param {string} accountName The name of the storage account within the
   * specified resource group. Storage account names must be between 3 and 24
   * characters in length and use numbers and lower-case letters only.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StorageAccountOperations.prototype.checkNameAvailability = function(accountName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (accountName === null || accountName === undefined) {
      return callback(new Error('accountName 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/Microsoft.Storage/checkNameAvailability';
    var queryParameters = [];
    queryParameters.push('api-version=2015-05-01-preview');
    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';
    if (uuid() !== null && uuid() !== undefined) {
      httpRequest.headers['x-ms-client-request-id'] = uuid();
    }
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var storageAccountCheckNameAvailabilityParametersValue = {};
    requestDoc = storageAccountCheckNameAvailabilityParametersValue;
    
    storageAccountCheckNameAvailabilityParametersValue['name'] = accountName;
    
    storageAccountCheckNameAvailabilityParametersValue['type'] = 'Microsoft.Storage/storageAccounts';
    
    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 nameAvailableValue = responseDoc['nameAvailable'];
          if (nameAvailableValue !== null && nameAvailableValue !== undefined) {
            var nameAvailableInstance = nameAvailableValue;
            result.nameAvailable = nameAvailableInstance;
          }
          
          var reasonValue = responseDoc['reason'];
          if (reasonValue !== null && reasonValue !== undefined) {
            var reasonInstance = reasonValue;
            result.reason = reasonInstance;
          }
          
          var messageValue = responseDoc['message'];
          if (messageValue !== null && messageValue !== undefined) {
            var messageInstance = messageValue;
            result.message = messageInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Asynchronously creates a new storage account with the specified
   * parameters. Existing accounts cannot be updated with this API and should
   * instead use the Update Storage Account API. If an account is already
   * created and subsequent create request is issued with exact same set of
   * properties, the request succeeds.The max number of storage accounts that
   * can be created per subscription is limited to 20.
   * 
   * @param {string} resourceGroupName The name of the resource group within
   * the user’s subscription.
   * 
   * @param {string} accountName The name of the storage account within the
   * specified resource group. Storage account names must be between 3 and 24
   * characters in length and use numbers and lower-case letters only.
   * 
   * @param {StorageAccountCreateParameters} parameters The parameters to
   * provide for the created account.
   * 
   * @param {AccountType} parameters.accountType Gets or sets the account type.
   * 
   * @param {string} parameters.location Gets or sets the location of the
   * resource. This will be one of the supported and registered Azure Geo
   * Regions (e.g. West US, East US, Southeast Asia, etc.). The geo region of
   * a resource cannot be changed once it is created.
   * 
   * @param {object} [parameters.tags] Gets or sets a list of key value pairs
   * that describe the resource. These tags can be used in viewing and
   * grouping this resource (across resource groups). A maximum of 15 tags can
   * be provided for a resource. Each tag must have a key no greater than 128
   * characters and value no greater than 256 characters.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StorageAccountOperations.prototype.create = function(resourceGroupName, accountName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    var client2 = this.client;
    
    return client2.storageAccounts.beginCreate(resourceGroupName, accountName, parameters, function (err, result) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var delayInSeconds = result.retryAfter;
      if (delayInSeconds === 0) {
        delayInSeconds = 25;
      }
      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 = 25;
                }
                if (client2.longRunningOperationRetryTimeout >= 0) {
                  delayInSeconds = client2.longRunningOperationRetryTimeout;
                }
                pollOperation();
              }
            }
          });
        }, delayInSeconds * 1000);
      };
      
      pollOperation();
    });
  };
  
  /**
   * Deletes a storage account in Microsoft Azure.
   * 
   * @param {string} resourceGroupName The name of the resource group within
   * the user’s subscription.
   * 
   * @param {string} accountName The name of the storage account within the
   * specified resource group. Storage account names must be between 3 and 24
   * characters in length and use numbers and lower-case letters only.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StorageAccountOperations.prototype.deleteMethod = function(resourceGroupName, accountName, 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 (accountName === null || accountName === undefined) {
      return callback(new Error('accountName cannot be null.'));
    }
    if (accountName.length < 3) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    if (accountName.length > 24) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    for (var loweredIndex1 = 0; loweredIndex1 < accountName.length; loweredIndex1 = loweredIndex1 + 1) {
      var accountNameChar = accountName[loweredIndex1];
      if (accountNameChar === accountNameChar.toLowerCase() === false && isNaN(parseInt(accountNameChar, 10)) === false === false) {
        return callback(new Error('accountName 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);
    url2 = url2 + '/providers/Microsoft.Storage/storageAccounts/';
    url2 = url2 + encodeURIComponent(accountName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-05-01-preview');
    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
    if (uuid() !== null && uuid() !== undefined) {
      httpRequest.headers['x-ms-client-request-id'] = uuid();
    }
    
    // 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);
    });
  };
  
  /**
   * Returns the properties for the specified storage account including but not
   * limited to name, account type, location, and account status. The ListKeys
   * operation should be used to retrieve storage keys.
   * 
   * @param {string} resourceGroupName The name of the resource group within
   * the user’s subscription.
   * 
   * @param {string} accountName The name of the storage account within the
   * specified resource group. Storage account names must be between 3 and 24
   * characters in length and use numbers and lower-case letters only.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StorageAccountOperations.prototype.getProperties = function(resourceGroupName, accountName, 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 (accountName === null || accountName === undefined) {
      return callback(new Error('accountName cannot be null.'));
    }
    if (accountName.length < 3) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    if (accountName.length > 24) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    for (var loweredIndex1 = 0; loweredIndex1 < accountName.length; loweredIndex1 = loweredIndex1 + 1) {
      var accountNameChar = accountName[loweredIndex1];
      if (accountNameChar === accountNameChar.toLowerCase() === false && isNaN(parseInt(accountNameChar, 10)) === false === false) {
        return callback(new Error('accountName 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);
    url2 = url2 + '/providers/Microsoft.Storage/storageAccounts/';
    url2 = url2 + encodeURIComponent(accountName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-05-01-preview');
    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
    if (uuid() !== null && uuid() !== undefined) {
      httpRequest.headers['x-ms-client-request-id'] = uuid();
    }
    
    // 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 storageAccountInstance = { tags: {} };
          result.storageAccount = storageAccountInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            storageAccountInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            storageAccountInstance.name = nameInstance;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            storageAccountInstance.type = typeInstance;
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            storageAccountInstance.location = locationInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey = property;
              var tagsValue = tagsSequenceElement[property];
              storageAccountInstance.tags[tagsKey] = tagsValue;
            }
          }
          
          var propertiesValue = responseDoc['properties'];
          if (propertiesValue !== null && propertiesValue !== undefined) {
            var provisioningStateValue = propertiesValue['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              storageAccountInstance.provisioningState = provisioningStateInstance;
            }
            
            var accountTypeValue = propertiesValue['accountType'];
            if (accountTypeValue !== null && accountTypeValue !== undefined) {
              var accountTypeInstance = accountTypeValue;
              storageAccountInstance.accountType = accountTypeInstance;
            }
            
            var primaryEndpointsValue = propertiesValue['primaryEndpoints'];
            if (primaryEndpointsValue !== null && primaryEndpointsValue !== undefined) {
              var primaryEndpointsInstance = {};
              storageAccountInstance.primaryEndpoints = primaryEndpointsInstance;
              
              var blobValue = primaryEndpointsValue['blob'];
              if (blobValue !== null && blobValue !== undefined) {
                var blobInstance = blobValue;
                primaryEndpointsInstance.blob = blobInstance;
              }
              
              var queueValue = primaryEndpointsValue['queue'];
              if (queueValue !== null && queueValue !== undefined) {
                var queueInstance = queueValue;
                primaryEndpointsInstance.queue = queueInstance;
              }
              
              var tableValue = primaryEndpointsValue['table'];
              if (tableValue !== null && tableValue !== undefined) {
                var tableInstance = tableValue;
                primaryEndpointsInstance.table = tableInstance;
              }
            }
            
            var primaryLocationValue = propertiesValue['primaryLocation'];
            if (primaryLocationValue !== null && primaryLocationValue !== undefined) {
              var primaryLocationInstance = primaryLocationValue;
              storageAccountInstance.primaryLocation = primaryLocationInstance;
            }
            
            var statusOfPrimaryValue = propertiesValue['statusOfPrimary'];
            if (statusOfPrimaryValue !== null && statusOfPrimaryValue !== undefined) {
              var statusOfPrimaryInstance = statusOfPrimaryValue;
              storageAccountInstance.statusOfPrimary = statusOfPrimaryInstance;
            }
            
            var lastGeoFailoverTimeValue = propertiesValue['lastGeoFailoverTime'];
            if (lastGeoFailoverTimeValue !== null && lastGeoFailoverTimeValue !== undefined) {
              var lastGeoFailoverTimeInstance = lastGeoFailoverTimeValue;
              storageAccountInstance.lastGeoFailoverTime = lastGeoFailoverTimeInstance;
            }
            
            var secondaryLocationValue = propertiesValue['secondaryLocation'];
            if (secondaryLocationValue !== null && secondaryLocationValue !== undefined) {
              var secondaryLocationInstance = secondaryLocationValue;
              storageAccountInstance.secondaryLocation = secondaryLocationInstance;
            }
            
            var statusOfSecondaryValue = propertiesValue['statusOfSecondary'];
            if (statusOfSecondaryValue !== null && statusOfSecondaryValue !== undefined) {
              var statusOfSecondaryInstance = statusOfSecondaryValue;
              storageAccountInstance.statusOfSecondary = statusOfSecondaryInstance;
            }
            
            var creationTimeValue = propertiesValue['creationTime'];
            if (creationTimeValue !== null && creationTimeValue !== undefined) {
              var creationTimeInstance = creationTimeValue;
              storageAccountInstance.creationTime = creationTimeInstance;
            }
            
            var customDomainValue = propertiesValue['customDomain'];
            if (customDomainValue !== null && customDomainValue !== undefined) {
              var customDomainInstance = {};
              storageAccountInstance.customDomain = customDomainInstance;
              
              var nameValue2 = customDomainValue['name'];
              if (nameValue2 !== null && nameValue2 !== undefined) {
                var nameInstance2 = nameValue2;
                customDomainInstance.name = nameInstance2;
              }
              
              var useSubDomainValue = customDomainValue['useSubDomain'];
              if (useSubDomainValue !== null && useSubDomainValue !== undefined) {
                var useSubDomainInstance = useSubDomainValue;
                customDomainInstance.useSubDomain = useSubDomainInstance;
              }
            }
            
            var secondaryEndpointsValue = propertiesValue['secondaryEndpoints'];
            if (secondaryEndpointsValue !== null && secondaryEndpointsValue !== undefined) {
              var secondaryEndpointsInstance = {};
              storageAccountInstance.secondaryEndpoints = secondaryEndpointsInstance;
              
              var blobValue2 = secondaryEndpointsValue['blob'];
              if (blobValue2 !== null && blobValue2 !== undefined) {
                var blobInstance2 = blobValue2;
                secondaryEndpointsInstance.blob = blobInstance2;
              }
              
              var queueValue2 = secondaryEndpointsValue['queue'];
              if (queueValue2 !== null && queueValue2 !== undefined) {
                var queueInstance2 = queueValue2;
                secondaryEndpointsInstance.queue = queueInstance2;
              }
              
              var tableValue2 = secondaryEndpointsValue['table'];
              if (tableValue2 !== null && tableValue2 !== undefined) {
                var tableInstance2 = tableValue2;
                secondaryEndpointsInstance.table = tableInstance2;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Lists all the storage accounts available under the subscription. Note that
   * storage keys are not returned; use the ListKeys operation for this.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StorageAccountOperations.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 + '/providers/Microsoft.Storage/storageAccounts';
    var queryParameters = [];
    queryParameters.push('api-version=2015-05-01-preview');
    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
    if (uuid() !== null && uuid() !== undefined) {
      httpRequest.headers['x-ms-client-request-id'] = uuid();
    }
    
    // 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 = { storageAccounts: [] };
        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 storageAccountJsonInstance = { tags: {} };
              result.storageAccounts.push(storageAccountJsonInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                storageAccountJsonInstance.id = idInstance;
              }
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                storageAccountJsonInstance.name = nameInstance;
              }
              
              var typeValue = valueValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                storageAccountJsonInstance.type = typeInstance;
              }
              
              var locationValue = valueValue['location'];
              if (locationValue !== null && locationValue !== undefined) {
                var locationInstance = locationValue;
                storageAccountJsonInstance.location = locationInstance;
              }
              
              var tagsSequenceElement = valueValue['tags'];
              if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                for (var property in tagsSequenceElement) {
                  var tagsKey = property;
                  var tagsValue = tagsSequenceElement[property];
                  storageAccountJsonInstance.tags[tagsKey] = tagsValue;
                }
              }
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  storageAccountJsonInstance.provisioningState = provisioningStateInstance;
                }
                
                var accountTypeValue = propertiesValue['accountType'];
                if (accountTypeValue !== null && accountTypeValue !== undefined) {
                  var accountTypeInstance = accountTypeValue;
                  storageAccountJsonInstance.accountType = accountTypeInstance;
                }
                
                var primaryEndpointsValue = propertiesValue['primaryEndpoints'];
                if (primaryEndpointsValue !== null && primaryEndpointsValue !== undefined) {
                  var primaryEndpointsInstance = {};
                  storageAccountJsonInstance.primaryEndpoints = primaryEndpointsInstance;
                  
                  var blobValue = primaryEndpointsValue['blob'];
                  if (blobValue !== null && blobValue !== undefined) {
                    var blobInstance = blobValue;
                    primaryEndpointsInstance.blob = blobInstance;
                  }
                  
                  var queueValue = primaryEndpointsValue['queue'];
                  if (queueValue !== null && queueValue !== undefined) {
                    var queueInstance = queueValue;
                    primaryEndpointsInstance.queue = queueInstance;
                  }
                  
                  var tableValue = primaryEndpointsValue['table'];
                  if (tableValue !== null && tableValue !== undefined) {
                    var tableInstance = tableValue;
                    primaryEndpointsInstance.table = tableInstance;
                  }
                }
                
                var primaryLocationValue = propertiesValue['primaryLocation'];
                if (primaryLocationValue !== null && primaryLocationValue !== undefined) {
                  var primaryLocationInstance = primaryLocationValue;
                  storageAccountJsonInstance.primaryLocation = primaryLocationInstance;
                }
                
                var statusOfPrimaryValue = propertiesValue['statusOfPrimary'];
                if (statusOfPrimaryValue !== null && statusOfPrimaryValue !== undefined) {
                  var statusOfPrimaryInstance = statusOfPrimaryValue;
                  storageAccountJsonInstance.statusOfPrimary = statusOfPrimaryInstance;
                }
                
                var lastGeoFailoverTimeValue = propertiesValue['lastGeoFailoverTime'];
                if (lastGeoFailoverTimeValue !== null && lastGeoFailoverTimeValue !== undefined) {
                  var lastGeoFailoverTimeInstance = lastGeoFailoverTimeValue;
                  storageAccountJsonInstance.lastGeoFailoverTime = lastGeoFailoverTimeInstance;
                }
                
                var secondaryLocationValue = propertiesValue['secondaryLocation'];
                if (secondaryLocationValue !== null && secondaryLocationValue !== undefined) {
                  var secondaryLocationInstance = secondaryLocationValue;
                  storageAccountJsonInstance.secondaryLocation = secondaryLocationInstance;
                }
                
                var statusOfSecondaryValue = propertiesValue['statusOfSecondary'];
                if (statusOfSecondaryValue !== null && statusOfSecondaryValue !== undefined) {
                  var statusOfSecondaryInstance = statusOfSecondaryValue;
                  storageAccountJsonInstance.statusOfSecondary = statusOfSecondaryInstance;
                }
                
                var creationTimeValue = propertiesValue['creationTime'];
                if (creationTimeValue !== null && creationTimeValue !== undefined) {
                  var creationTimeInstance = creationTimeValue;
                  storageAccountJsonInstance.creationTime = creationTimeInstance;
                }
                
                var customDomainValue = propertiesValue['customDomain'];
                if (customDomainValue !== null && customDomainValue !== undefined) {
                  var customDomainInstance = {};
                  storageAccountJsonInstance.customDomain = customDomainInstance;
                  
                  var nameValue2 = customDomainValue['name'];
                  if (nameValue2 !== null && nameValue2 !== undefined) {
                    var nameInstance2 = nameValue2;
                    customDomainInstance.name = nameInstance2;
                  }
                  
                  var useSubDomainValue = customDomainValue['useSubDomain'];
                  if (useSubDomainValue !== null && useSubDomainValue !== undefined) {
                    var useSubDomainInstance = useSubDomainValue;
                    customDomainInstance.useSubDomain = useSubDomainInstance;
                  }
                }
                
                var secondaryEndpointsValue = propertiesValue['secondaryEndpoints'];
                if (secondaryEndpointsValue !== null && secondaryEndpointsValue !== undefined) {
                  var secondaryEndpointsInstance = {};
                  storageAccountJsonInstance.secondaryEndpoints = secondaryEndpointsInstance;
                  
                  var blobValue2 = secondaryEndpointsValue['blob'];
                  if (blobValue2 !== null && blobValue2 !== undefined) {
                    var blobInstance2 = blobValue2;
                    secondaryEndpointsInstance.blob = blobInstance2;
                  }
                  
                  var queueValue2 = secondaryEndpointsValue['queue'];
                  if (queueValue2 !== null && queueValue2 !== undefined) {
                    var queueInstance2 = queueValue2;
                    secondaryEndpointsInstance.queue = queueInstance2;
                  }
                  
                  var tableValue2 = secondaryEndpointsValue['table'];
                  if (tableValue2 !== null && tableValue2 !== undefined) {
                    var tableInstance2 = tableValue2;
                    secondaryEndpointsInstance.table = tableInstance2;
                  }
                }
              }
            }
          }
          
          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);
    });
  };
  
  /**
   * Lists all the storage accounts available under the given resource group.
   * Note that storage keys are not returned; use the ListKeys operation for
   * this.
   * 
   * @param {string} resourceGroupName The name of the resource group within
   * the user’s subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StorageAccountOperations.prototype.listByResourceGroup = 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.'));
    }
    
    // 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.Storage/storageAccounts';
    var queryParameters = [];
    queryParameters.push('api-version=2015-05-01-preview');
    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
    if (uuid() !== null && uuid() !== undefined) {
      httpRequest.headers['x-ms-client-request-id'] = uuid();
    }
    
    // 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 = { storageAccounts: [] };
        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 storageAccountJsonInstance = { tags: {} };
              result.storageAccounts.push(storageAccountJsonInstance);
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                storageAccountJsonInstance.id = idInstance;
              }
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                storageAccountJsonInstance.name = nameInstance;
              }
              
              var typeValue = valueValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                storageAccountJsonInstance.type = typeInstance;
              }
              
              var locationValue = valueValue['location'];
              if (locationValue !== null && locationValue !== undefined) {
                var locationInstance = locationValue;
                storageAccountJsonInstance.location = locationInstance;
              }
              
              var tagsSequenceElement = valueValue['tags'];
              if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
                for (var property in tagsSequenceElement) {
                  var tagsKey = property;
                  var tagsValue = tagsSequenceElement[property];
                  storageAccountJsonInstance.tags[tagsKey] = tagsValue;
                }
              }
              
              var propertiesValue = valueValue['properties'];
              if (propertiesValue !== null && propertiesValue !== undefined) {
                var provisioningStateValue = propertiesValue['provisioningState'];
                if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
                  var provisioningStateInstance = provisioningStateValue;
                  storageAccountJsonInstance.provisioningState = provisioningStateInstance;
                }
                
                var accountTypeValue = propertiesValue['accountType'];
                if (accountTypeValue !== null && accountTypeValue !== undefined) {
                  var accountTypeInstance = accountTypeValue;
                  storageAccountJsonInstance.accountType = accountTypeInstance;
                }
                
                var primaryEndpointsValue = propertiesValue['primaryEndpoints'];
                if (primaryEndpointsValue !== null && primaryEndpointsValue !== undefined) {
                  var primaryEndpointsInstance = {};
                  storageAccountJsonInstance.primaryEndpoints = primaryEndpointsInstance;
                  
                  var blobValue = primaryEndpointsValue['blob'];
                  if (blobValue !== null && blobValue !== undefined) {
                    var blobInstance = blobValue;
                    primaryEndpointsInstance.blob = blobInstance;
                  }
                  
                  var queueValue = primaryEndpointsValue['queue'];
                  if (queueValue !== null && queueValue !== undefined) {
                    var queueInstance = queueValue;
                    primaryEndpointsInstance.queue = queueInstance;
                  }
                  
                  var tableValue = primaryEndpointsValue['table'];
                  if (tableValue !== null && tableValue !== undefined) {
                    var tableInstance = tableValue;
                    primaryEndpointsInstance.table = tableInstance;
                  }
                }
                
                var primaryLocationValue = propertiesValue['primaryLocation'];
                if (primaryLocationValue !== null && primaryLocationValue !== undefined) {
                  var primaryLocationInstance = primaryLocationValue;
                  storageAccountJsonInstance.primaryLocation = primaryLocationInstance;
                }
                
                var statusOfPrimaryValue = propertiesValue['statusOfPrimary'];
                if (statusOfPrimaryValue !== null && statusOfPrimaryValue !== undefined) {
                  var statusOfPrimaryInstance = statusOfPrimaryValue;
                  storageAccountJsonInstance.statusOfPrimary = statusOfPrimaryInstance;
                }
                
                var lastGeoFailoverTimeValue = propertiesValue['lastGeoFailoverTime'];
                if (lastGeoFailoverTimeValue !== null && lastGeoFailoverTimeValue !== undefined) {
                  var lastGeoFailoverTimeInstance = lastGeoFailoverTimeValue;
                  storageAccountJsonInstance.lastGeoFailoverTime = lastGeoFailoverTimeInstance;
                }
                
                var secondaryLocationValue = propertiesValue['secondaryLocation'];
                if (secondaryLocationValue !== null && secondaryLocationValue !== undefined) {
                  var secondaryLocationInstance = secondaryLocationValue;
                  storageAccountJsonInstance.secondaryLocation = secondaryLocationInstance;
                }
                
                var statusOfSecondaryValue = propertiesValue['statusOfSecondary'];
                if (statusOfSecondaryValue !== null && statusOfSecondaryValue !== undefined) {
                  var statusOfSecondaryInstance = statusOfSecondaryValue;
                  storageAccountJsonInstance.statusOfSecondary = statusOfSecondaryInstance;
                }
                
                var creationTimeValue = propertiesValue['creationTime'];
                if (creationTimeValue !== null && creationTimeValue !== undefined) {
                  var creationTimeInstance = creationTimeValue;
                  storageAccountJsonInstance.creationTime = creationTimeInstance;
                }
                
                var customDomainValue = propertiesValue['customDomain'];
                if (customDomainValue !== null && customDomainValue !== undefined) {
                  var customDomainInstance = {};
                  storageAccountJsonInstance.customDomain = customDomainInstance;
                  
                  var nameValue2 = customDomainValue['name'];
                  if (nameValue2 !== null && nameValue2 !== undefined) {
                    var nameInstance2 = nameValue2;
                    customDomainInstance.name = nameInstance2;
                  }
                  
                  var useSubDomainValue = customDomainValue['useSubDomain'];
                  if (useSubDomainValue !== null && useSubDomainValue !== undefined) {
                    var useSubDomainInstance = useSubDomainValue;
                    customDomainInstance.useSubDomain = useSubDomainInstance;
                  }
                }
                
                var secondaryEndpointsValue = propertiesValue['secondaryEndpoints'];
                if (secondaryEndpointsValue !== null && secondaryEndpointsValue !== undefined) {
                  var secondaryEndpointsInstance = {};
                  storageAccountJsonInstance.secondaryEndpoints = secondaryEndpointsInstance;
                  
                  var blobValue2 = secondaryEndpointsValue['blob'];
                  if (blobValue2 !== null && blobValue2 !== undefined) {
                    var blobInstance2 = blobValue2;
                    secondaryEndpointsInstance.blob = blobInstance2;
                  }
                  
                  var queueValue2 = secondaryEndpointsValue['queue'];
                  if (queueValue2 !== null && queueValue2 !== undefined) {
                    var queueInstance2 = queueValue2;
                    secondaryEndpointsInstance.queue = queueInstance2;
                  }
                  
                  var tableValue2 = secondaryEndpointsValue['table'];
                  if (tableValue2 !== null && tableValue2 !== undefined) {
                    var tableInstance2 = tableValue2;
                    secondaryEndpointsInstance.table = tableInstance2;
                  }
                }
              }
            }
          }
          
          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);
    });
  };
  
  /**
   * Lists the access keys for the specified storage account.
   * 
   * @param {string} resourceGroupName The name of the resource group.
   * 
   * @param {string} accountName The name of the storage account.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StorageAccountOperations.prototype.listKeys = function(resourceGroupName, accountName, 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 (accountName === null || accountName === undefined) {
      return callback(new Error('accountName cannot be null.'));
    }
    if (accountName.length < 3) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    if (accountName.length > 24) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    for (var loweredIndex1 = 0; loweredIndex1 < accountName.length; loweredIndex1 = loweredIndex1 + 1) {
      var accountNameChar = accountName[loweredIndex1];
      if (accountNameChar === accountNameChar.toLowerCase() === false && isNaN(parseInt(accountNameChar, 10)) === false === false) {
        return callback(new Error('accountName 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);
    url2 = url2 + '/providers/Microsoft.Storage/storageAccounts/';
    url2 = url2 + encodeURIComponent(accountName);
    url2 = url2 + '/listKeys';
    var queryParameters = [];
    queryParameters.push('api-version=2015-05-01-preview');
    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
    if (uuid() !== null && uuid() !== undefined) {
      httpRequest.headers['x-ms-client-request-id'] = uuid();
    }
    
    // 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 storageAccountKeysInstance = {};
          result.storageAccountKeys = storageAccountKeysInstance;
          
          var key1Value = responseDoc['key1'];
          if (key1Value !== null && key1Value !== undefined) {
            var key1Instance = key1Value;
            storageAccountKeysInstance.key1 = key1Instance;
          }
          
          var key2Value = responseDoc['key2'];
          if (key2Value !== null && key2Value !== undefined) {
            var key2Instance = key2Value;
            storageAccountKeysInstance.key2 = key2Instance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Regenerates the access keys for the specified storage account.
   * 
   * @param {string} resourceGroupName The name of the resource group within
   * the user’s subscription.
   * 
   * @param {string} accountName The name of the storage account within the
   * specified resource group. Storage account names must be between 3 and 24
   * characters in length and use numbers and lower-case letters only.
   * 
   * @param {KeyName} regenerateKey Specifies name of the key which should be
   * regenerated.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StorageAccountOperations.prototype.regenerateKey = function(resourceGroupName, accountName, regenerateKey, 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 (accountName === null || accountName === undefined) {
      return callback(new Error('accountName cannot be null.'));
    }
    if (accountName.length < 3) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    if (accountName.length > 24) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    for (var loweredIndex1 = 0; loweredIndex1 < accountName.length; loweredIndex1 = loweredIndex1 + 1) {
      var accountNameChar = accountName[loweredIndex1];
      if (accountNameChar === accountNameChar.toLowerCase() === false && isNaN(parseInt(accountNameChar, 10)) === false === false) {
        return callback(new Error('accountName is outside the valid range.'));
      }
    }
    if (regenerateKey === null || regenerateKey === undefined) {
      return callback(new Error('regenerateKey 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.Storage/storageAccounts/';
    url2 = url2 + encodeURIComponent(accountName);
    url2 = url2 + '/regenerateKey';
    var queryParameters = [];
    queryParameters.push('api-version=2015-05-01-preview');
    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';
    if (uuid() !== null && uuid() !== undefined) {
      httpRequest.headers['x-ms-client-request-id'] = uuid();
    }
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var storageAccountRegenerateKeyParametersValue = {};
    requestDoc = storageAccountRegenerateKeyParametersValue;
    
    storageAccountRegenerateKeyParametersValue['keyName'] = regenerateKey !== null && regenerateKey !== undefined ? regenerateKey.toString() : 'Key1';
    
    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 storageAccountKeysInstance = {};
          result.storageAccountKeys = storageAccountKeysInstance;
          
          var key1Value = responseDoc['key1'];
          if (key1Value !== null && key1Value !== undefined) {
            var key1Instance = key1Value;
            storageAccountKeysInstance.key1 = key1Instance;
          }
          
          var key2Value = responseDoc['key2'];
          if (key2Value !== null && key2Value !== undefined) {
            var key2Instance = key2Value;
            storageAccountKeysInstance.key2 = key2Instance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Updates the account type or tags for a storage account. It can also be
   * used to add a custom domain (note that custom domains cannot be added via
   * the Create operation). Only one custom domain is supported per storage
   * account. This API can only be used to update one of tags, accountType, or
   * customDomain per call. To update multiple of these properties, call the
   * API multiple times with one change per call. This call does not change
   * the storage keys for the account. If you want to change storage account
   * keys, use the RegenerateKey operation. The location and name of the
   * storage account cannot be changed after creation.
   * 
   * @param {string} resourceGroupName The name of the resource group within
   * the user’s subscription.
   * 
   * @param {string} accountName The name of the storage account within the
   * specified resource group. Storage account names must be between 3 and 24
   * characters in length and use numbers and lower-case letters only.
   * 
   * @param {StorageAccountUpdateParameters} parameters The parameters to
   * update on the account. Note that only one property can be changed at a
   * time using this API.
   * 
   * @param {AccountType} [parameters.accountType] Gets or sets the account
   * type. Note that StandardZRS and PremiumLRS accounts cannot be changed to
   * other account types, and other account types cannot be changed to
   * StandardZRS or PremiumLRS.
   * 
   * @param {CustomDomain} [parameters.customDomain] User domain assigned to
   * the storage account. Name is the CNAME source. Only one custom domain is
   * supported per storage account at this time. To clear the existing custom
   * domain, use an empty string for the custom domain name property.
   * 
   * @param {string} [parameters.customDomain.name] Gets or sets the custom
   * domain name. Name is the CNAME source.
   * 
   * @param {boolean} [parameters.customDomain.useSubDomain] Indicates whether
   * indirect CName validation is enabled. Default value is false. This should
   * only be set on updates
   * 
   * @param {object} [parameters.tags] Gets or sets a list of key value pairs
   * that describe the resource. These tags can be used in viewing and
   * grouping this resource (across resource groups). A maximum of 15 tags can
   * be provided for a resource. Each tag must have a key no greater than 128
   * characters and value no greater than 256 characters. This is a full
   * replace so all the existing tags will be replaced on Update.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  StorageAccountOperations.prototype.update = function(resourceGroupName, accountName, 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 (accountName === null || accountName === undefined) {
      return callback(new Error('accountName cannot be null.'));
    }
    if (accountName.length < 3) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    if (accountName.length > 24) {
      return callback(new Error('accountName is outside the valid range.'));
    }
    for (var loweredIndex1 = 0; loweredIndex1 < accountName.length; loweredIndex1 = loweredIndex1 + 1) {
      var accountNameChar = accountName[loweredIndex1];
      if (accountNameChar === accountNameChar.toLowerCase() === false && isNaN(parseInt(accountNameChar, 10)) === false === false) {
        return callback(new Error('accountName is outside the valid range.'));
      }
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.customDomain !== null && parameters.customDomain !== undefined) {
      if (parameters.customDomain.name === null || parameters.customDomain.name === undefined) {
        return callback(new Error('parameters.customDomain.name 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.Storage/storageAccounts/';
    url2 = url2 + encodeURIComponent(accountName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-05-01-preview');
    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';
    if (uuid() !== null && uuid() !== undefined) {
      httpRequest.headers['x-ms-client-request-id'] = uuid();
    }
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var storageAccountUpdateParametersJsonValue = {};
    requestDoc = storageAccountUpdateParametersJsonValue;
    
    if (parameters.tags !== null && parameters.tags !== undefined) {
      var tagsDictionary = {};
      for (var tagsKey in parameters.tags) {
        var tagsValue = parameters.tags[tagsKey];
        tagsDictionary[tagsKey] = tagsValue;
      }
      storageAccountUpdateParametersJsonValue['tags'] = tagsDictionary;
    }
    
    var propertiesValue = {};
    storageAccountUpdateParametersJsonValue['properties'] = propertiesValue;
    
    if (parameters.accountType !== null && parameters.accountType !== undefined) {
      propertiesValue['accountType'] = parameters.accountType !== null && parameters.accountType !== undefined ? parameters.accountType.toString() : 'StandardLRS';
    }
    
    if (parameters.customDomain !== null && parameters.customDomain !== undefined) {
      var customDomainValue = {};
      propertiesValue['customDomain'] = customDomainValue;
      
      customDomainValue['name'] = parameters.customDomain.name;
      
      if (parameters.customDomain.useSubDomain !== null && parameters.customDomain.useSubDomain !== undefined) {
        customDomainValue['useSubDomain'] = parameters.customDomain.useSubDomain;
      }
    }
    
    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 storageAccountInstance = { tags: {} };
          result.storageAccount = storageAccountInstance;
          
          var idValue = responseDoc['id'];
          if (idValue !== null && idValue !== undefined) {
            var idInstance = idValue;
            storageAccountInstance.id = idInstance;
          }
          
          var nameValue = responseDoc['name'];
          if (nameValue !== null && nameValue !== undefined) {
            var nameInstance = nameValue;
            storageAccountInstance.name = nameInstance;
          }
          
          var typeValue = responseDoc['type'];
          if (typeValue !== null && typeValue !== undefined) {
            var typeInstance = typeValue;
            storageAccountInstance.type = typeInstance;
          }
          
          var locationValue = responseDoc['location'];
          if (locationValue !== null && locationValue !== undefined) {
            var locationInstance = locationValue;
            storageAccountInstance.location = locationInstance;
          }
          
          var tagsSequenceElement = responseDoc['tags'];
          if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
            for (var property in tagsSequenceElement) {
              var tagsKey2 = property;
              var tagsValue2 = tagsSequenceElement[property];
              storageAccountInstance.tags[tagsKey2] = tagsValue2;
            }
          }
          
          var propertiesValue2 = responseDoc['properties'];
          if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
            var provisioningStateValue = propertiesValue2['provisioningState'];
            if (provisioningStateValue !== null && provisioningStateValue !== undefined) {
              var provisioningStateInstance = provisioningStateValue;
              storageAccountInstance.provisioningState = provisioningStateInstance;
            }
            
            var accountTypeValue = propertiesValue2['accountType'];
            if (accountTypeValue !== null && accountTypeValue !== undefined) {
              var accountTypeInstance = accountTypeValue;
              storageAccountInstance.accountType = accountTypeInstance;
            }
            
            var primaryEndpointsValue = propertiesValue2['primaryEndpoints'];
            if (primaryEndpointsValue !== null && primaryEndpointsValue !== undefined) {
              var primaryEndpointsInstance = {};
              storageAccountInstance.primaryEndpoints = primaryEndpointsInstance;
              
              var blobValue = primaryEndpointsValue['blob'];
              if (blobValue !== null && blobValue !== undefined) {
                var blobInstance = blobValue;
                primaryEndpointsInstance.blob = blobInstance;
              }
              
              var queueValue = primaryEndpointsValue['queue'];
              if (queueValue !== null && queueValue !== undefined) {
                var queueInstance = queueValue;
                primaryEndpointsInstance.queue = queueInstance;
              }
              
              var tableValue = primaryEndpointsValue['table'];
              if (tableValue !== null && tableValue !== undefined) {
                var tableInstance = tableValue;
                primaryEndpointsInstance.table = tableInstance;
              }
            }
            
            var primaryLocationValue = propertiesValue2['primaryLocation'];
            if (primaryLocationValue !== null && primaryLocationValue !== undefined) {
              var primaryLocationInstance = primaryLocationValue;
              storageAccountInstance.primaryLocation = primaryLocationInstance;
            }
            
            var statusOfPrimaryValue = propertiesValue2['statusOfPrimary'];
            if (statusOfPrimaryValue !== null && statusOfPrimaryValue !== undefined) {
              var statusOfPrimaryInstance = statusOfPrimaryValue;
              storageAccountInstance.statusOfPrimary = statusOfPrimaryInstance;
            }
            
            var lastGeoFailoverTimeValue = propertiesValue2['lastGeoFailoverTime'];
            if (lastGeoFailoverTimeValue !== null && lastGeoFailoverTimeValue !== undefined) {
              var lastGeoFailoverTimeInstance = lastGeoFailoverTimeValue;
              storageAccountInstance.lastGeoFailoverTime = lastGeoFailoverTimeInstance;
            }
            
            var secondaryLocationValue = propertiesValue2['secondaryLocation'];
            if (secondaryLocationValue !== null && secondaryLocationValue !== undefined) {
              var secondaryLocationInstance = secondaryLocationValue;
              storageAccountInstance.secondaryLocation = secondaryLocationInstance;
            }
            
            var statusOfSecondaryValue = propertiesValue2['statusOfSecondary'];
            if (statusOfSecondaryValue !== null && statusOfSecondaryValue !== undefined) {
              var statusOfSecondaryInstance = statusOfSecondaryValue;
              storageAccountInstance.statusOfSecondary = statusOfSecondaryInstance;
            }
            
            var creationTimeValue = propertiesValue2['creationTime'];
            if (creationTimeValue !== null && creationTimeValue !== undefined) {
              var creationTimeInstance = creationTimeValue;
              storageAccountInstance.creationTime = creationTimeInstance;
            }
            
            var customDomainValue2 = propertiesValue2['customDomain'];
            if (customDomainValue2 !== null && customDomainValue2 !== undefined) {
              var customDomainInstance = {};
              storageAccountInstance.customDomain = customDomainInstance;
              
              var nameValue2 = customDomainValue2['name'];
              if (nameValue2 !== null && nameValue2 !== undefined) {
                var nameInstance2 = nameValue2;
                customDomainInstance.name = nameInstance2;
              }
              
              var useSubDomainValue = customDomainValue2['useSubDomain'];
              if (useSubDomainValue !== null && useSubDomainValue !== undefined) {
                var useSubDomainInstance = useSubDomainValue;
                customDomainInstance.useSubDomain = useSubDomainInstance;
              }
            }
            
            var secondaryEndpointsValue = propertiesValue2['secondaryEndpoints'];
            if (secondaryEndpointsValue !== null && secondaryEndpointsValue !== undefined) {
              var secondaryEndpointsInstance = {};
              storageAccountInstance.secondaryEndpoints = secondaryEndpointsInstance;
              
              var blobValue2 = secondaryEndpointsValue['blob'];
              if (blobValue2 !== null && blobValue2 !== undefined) {
                var blobInstance2 = blobValue2;
                secondaryEndpointsInstance.blob = blobInstance2;
              }
              
              var queueValue2 = secondaryEndpointsValue['queue'];
              if (queueValue2 !== null && queueValue2 !== undefined) {
                var queueInstance2 = queueValue2;
                secondaryEndpointsInstance.queue = queueInstance2;
              }
              
              var tableValue2 = secondaryEndpointsValue['table'];
              if (tableValue2 !== null && tableValue2 !== undefined) {
                var tableInstance2 = tableValue2;
                secondaryEndpointsInstance.table = tableInstance2;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return StorageAccountOperations;
})();
