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

var InsightsClient = ( /** @lends InsightsClient */ function() {
  /**
   * @class
   * Initializes a new instance of the InsightsClient 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 InsightsClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    InsightsClient['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 = '2014-04-01';
    }
    if (this.longRunningOperationInitialTimeout === null || this.longRunningOperationInitialTimeout === undefined) {
      this.longRunningOperationInitialTimeout = -1;
    }
    if (this.longRunningOperationRetryTimeout === null || this.longRunningOperationRetryTimeout === undefined) {
      this.longRunningOperationRetryTimeout = -1;
    }
    /**
     * Provides an instance of the [EventOperations](-EventOperations.html)
     * object.
     * @type {object}
     */
    this.eventOperations = new EventOperations(this);
    /**
     * Provides an instance of the
     * [LogDefinitionOperations](-LogDefinitionOperations.html) object.
     * @type {object}
     */
    this.logDefinitionOperations = new LogDefinitionOperations(this);
    /**
     * Provides an instance of the [LogOperations](-LogOperations.html) object.
     * @type {object}
     */
    this.logOperations = new LogOperations(this);
    /**
     * Provides an instance of the
     * [MetricDefinitionOperations](-MetricDefinitionOperations.html) object.
     * @type {object}
     */
    this.metricDefinitionOperations = new MetricDefinitionOperations(this);
    /**
     * Provides an instance of the [MetricOperations](-MetricOperations.html)
     * object.
     * @type {object}
     */
    this.metricOperations = new MetricOperations(this);
    /**
     * Provides an instance of the
     * [UsageMetricsOperations](-UsageMetricsOperations.html) object.
     * @type {object}
     */
    this.usageMetricOperations = new UsageMetricsOperations(this);
  }
  
  util.inherits(InsightsClient, Service);
  
  
  return InsightsClient;
})();
exports.InsightsClient = InsightsClient;

var EventOperations = ( /** @lends EventOperations */ function() {
  /**
   * @class
   * Microsoft Azure event logs and summaries can be retrieved using these
   * operations
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [InsightsClient] {@link InsightsClient~InsightsClient}.
   * See [eventOperations] {@link
   * InsightsClient~InsightsClient#eventOperations}.
   * Initializes a new instance of the EventOperations class.
   * @constructor
   * 
   * @param {InsightsClient} client Reference to the service client.
   */
  function EventOperations(client) {
    this.client = client;
  }
  
  /**
   * The List Digest Event Values operation lists the digest events.
   * 
   * @param {string} filterString The filter string
   * 
   * @param {string} [selectedProperties] The list of property names to be
   * returned. You can save bandwith by selecting only the properties you need.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EventOperations.prototype.listDigestEvents = function(filterString, selectedProperties, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (filterString === null || filterString === undefined) {
      return callback(new Error('filterString 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.insights/eventtypes/management/digestEvents';
    var queryParameters = [];
    queryParameters.push('api-version=2015-04-01');
    var odataFilter = [];
    odataFilter.push(encodeURIComponent(filterString));
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(null));
    }
    if (selectedProperties !== null && selectedProperties !== undefined) {
      queryParameters.push('$select=' + encodeURIComponent(selectedProperties));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    
    // 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 eventDataCollectionInstance = { value: [] };
          result.eventDataCollection = eventDataCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var eventDataInstance = { claims: {}, properties: {} };
              eventDataCollectionInstance.value.push(eventDataInstance);
              
              var authorizationValue = valueValue['authorization'];
              if (authorizationValue !== null && authorizationValue !== undefined) {
                var authorizationInstance = {};
                eventDataInstance.authorization = authorizationInstance;
                
                var actionValue = authorizationValue['action'];
                if (actionValue !== null && actionValue !== undefined) {
                  var actionInstance = actionValue;
                  authorizationInstance.action = actionInstance;
                }
                
                var conditionValue = authorizationValue['condition'];
                if (conditionValue !== null && conditionValue !== undefined) {
                  var conditionInstance = conditionValue;
                  authorizationInstance.condition = conditionInstance;
                }
                
                var roleValue = authorizationValue['role'];
                if (roleValue !== null && roleValue !== undefined) {
                  var roleInstance = roleValue;
                  authorizationInstance.role = roleInstance;
                }
                
                var scopeValue = authorizationValue['scope'];
                if (scopeValue !== null && scopeValue !== undefined) {
                  var scopeInstance = scopeValue;
                  authorizationInstance.scope = scopeInstance;
                }
              }
              
              var channelsValue = valueValue['channels'];
              if (channelsValue !== null && channelsValue !== undefined) {
                var channelsInstance = channelsValue;
                eventDataInstance.eventChannels = channelsInstance;
              }
              
              var claimsSequenceElement = valueValue['claims'];
              if (claimsSequenceElement !== null && claimsSequenceElement !== undefined) {
                for (var property in claimsSequenceElement) {
                  var claimsKey = property;
                  var claimsValue = claimsSequenceElement[property];
                  eventDataInstance.claims[claimsKey] = claimsValue;
                }
              }
              
              var callerValue = valueValue['caller'];
              if (callerValue !== null && callerValue !== undefined) {
                var callerInstance = callerValue;
                eventDataInstance.caller = callerInstance;
              }
              
              var descriptionValue = valueValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                eventDataInstance.description = descriptionInstance;
              }
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                eventDataInstance.id = idInstance;
              }
              
              var eventDataIdValue = valueValue['eventDataId'];
              if (eventDataIdValue !== null && eventDataIdValue !== undefined) {
                var eventDataIdInstance = eventDataIdValue;
                eventDataInstance.eventDataId = eventDataIdInstance;
              }
              
              var correlationIdValue = valueValue['correlationId'];
              if (correlationIdValue !== null && correlationIdValue !== undefined) {
                var correlationIdInstance = correlationIdValue;
                eventDataInstance.correlationId = correlationIdInstance;
              }
              
              var eventNameValue = valueValue['eventName'];
              if (eventNameValue !== null && eventNameValue !== undefined) {
                var eventNameInstance = {};
                eventDataInstance.eventName = eventNameInstance;
                
                var valueValue2 = eventNameValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  eventNameInstance.value = valueInstance;
                }
                
                var localizedValueValue = eventNameValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  eventNameInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var categoryValue = valueValue['category'];
              if (categoryValue !== null && categoryValue !== undefined) {
                var categoryInstance = {};
                eventDataInstance.category = categoryInstance;
                
                var valueValue3 = categoryValue['value'];
                if (valueValue3 !== null && valueValue3 !== undefined) {
                  var valueInstance2 = valueValue3;
                  categoryInstance.value = valueInstance2;
                }
                
                var localizedValueValue2 = categoryValue['localizedValue'];
                if (localizedValueValue2 !== null && localizedValueValue2 !== undefined) {
                  var localizedValueInstance2 = localizedValueValue2;
                  categoryInstance.localizedValue = localizedValueInstance2;
                }
              }
              
              var httpRequestValue = valueValue['httpRequest'];
              if (httpRequestValue !== null && httpRequestValue !== undefined) {
                var httpRequestInstance = {};
                eventDataInstance.httpRequest = httpRequestInstance;
                
                var clientRequestIdValue = httpRequestValue['clientRequestId'];
                if (clientRequestIdValue !== null && clientRequestIdValue !== undefined) {
                  var clientRequestIdInstance = clientRequestIdValue;
                  httpRequestInstance.clientRequestId = clientRequestIdInstance;
                }
                
                var clientIpAddressValue = httpRequestValue['clientIpAddress'];
                if (clientIpAddressValue !== null && clientIpAddressValue !== undefined) {
                  var clientIpAddressInstance = clientIpAddressValue;
                  httpRequestInstance.clientIpAddress = clientIpAddressInstance;
                }
                
                var methodValue = httpRequestValue['method'];
                if (methodValue !== null && methodValue !== undefined) {
                  var methodInstance = methodValue;
                  httpRequestInstance.method = methodInstance;
                }
                
                var uriValue = httpRequestValue['uri'];
                if (uriValue !== null && uriValue !== undefined) {
                  var uriInstance = uriValue;
                  httpRequestInstance.uri = uriInstance;
                }
              }
              
              var levelValue = valueValue['level'];
              if (levelValue !== null && levelValue !== undefined) {
                var levelInstance = levelValue;
                eventDataInstance.level = levelInstance;
              }
              
              var resourceGroupNameValue = valueValue['resourceGroupName'];
              if (resourceGroupNameValue !== null && resourceGroupNameValue !== undefined) {
                var resourceGroupNameInstance = resourceGroupNameValue;
                eventDataInstance.resourceGroupName = resourceGroupNameInstance;
              }
              
              var resourceProviderNameValue = valueValue['resourceProviderName'];
              if (resourceProviderNameValue !== null && resourceProviderNameValue !== undefined) {
                var resourceProviderNameInstance = {};
                eventDataInstance.resourceProviderName = resourceProviderNameInstance;
                
                var valueValue4 = resourceProviderNameValue['value'];
                if (valueValue4 !== null && valueValue4 !== undefined) {
                  var valueInstance3 = valueValue4;
                  resourceProviderNameInstance.value = valueInstance3;
                }
                
                var localizedValueValue3 = resourceProviderNameValue['localizedValue'];
                if (localizedValueValue3 !== null && localizedValueValue3 !== undefined) {
                  var localizedValueInstance3 = localizedValueValue3;
                  resourceProviderNameInstance.localizedValue = localizedValueInstance3;
                }
              }
              
              var resourceIdValue = valueValue['resourceId'];
              if (resourceIdValue !== null && resourceIdValue !== undefined) {
                var resourceIdInstance = resourceIdValue;
                eventDataInstance.resourceId = resourceIdInstance;
              }
              
              var resourceTypeValue = valueValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = {};
                eventDataInstance.resourceType = resourceTypeInstance;
                
                var valueValue5 = resourceTypeValue['value'];
                if (valueValue5 !== null && valueValue5 !== undefined) {
                  var valueInstance4 = valueValue5;
                  resourceTypeInstance.value = valueInstance4;
                }
                
                var localizedValueValue4 = resourceTypeValue['localizedValue'];
                if (localizedValueValue4 !== null && localizedValueValue4 !== undefined) {
                  var localizedValueInstance4 = localizedValueValue4;
                  resourceTypeInstance.localizedValue = localizedValueInstance4;
                }
              }
              
              var operationIdValue = valueValue['operationId'];
              if (operationIdValue !== null && operationIdValue !== undefined) {
                var operationIdInstance = operationIdValue;
                eventDataInstance.operationId = operationIdInstance;
              }
              
              var operationNameValue = valueValue['operationName'];
              if (operationNameValue !== null && operationNameValue !== undefined) {
                var operationNameInstance = {};
                eventDataInstance.operationName = operationNameInstance;
                
                var valueValue6 = operationNameValue['value'];
                if (valueValue6 !== null && valueValue6 !== undefined) {
                  var valueInstance5 = valueValue6;
                  operationNameInstance.value = valueInstance5;
                }
                
                var localizedValueValue5 = operationNameValue['localizedValue'];
                if (localizedValueValue5 !== null && localizedValueValue5 !== undefined) {
                  var localizedValueInstance5 = localizedValueValue5;
                  operationNameInstance.localizedValue = localizedValueInstance5;
                }
              }
              
              var propertiesSequenceElement = valueValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property2 in propertiesSequenceElement) {
                  var propertiesKey = property2;
                  var propertiesValue = propertiesSequenceElement[property2];
                  eventDataInstance.properties[propertiesKey] = propertiesValue;
                }
              }
              
              var statusValue = valueValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = {};
                eventDataInstance.status = statusInstance;
                
                var valueValue7 = statusValue['value'];
                if (valueValue7 !== null && valueValue7 !== undefined) {
                  var valueInstance6 = valueValue7;
                  statusInstance.value = valueInstance6;
                }
                
                var localizedValueValue6 = statusValue['localizedValue'];
                if (localizedValueValue6 !== null && localizedValueValue6 !== undefined) {
                  var localizedValueInstance6 = localizedValueValue6;
                  statusInstance.localizedValue = localizedValueInstance6;
                }
              }
              
              var subStatusValue = valueValue['subStatus'];
              if (subStatusValue !== null && subStatusValue !== undefined) {
                var subStatusInstance = {};
                eventDataInstance.subStatus = subStatusInstance;
                
                var valueValue8 = subStatusValue['value'];
                if (valueValue8 !== null && valueValue8 !== undefined) {
                  var valueInstance7 = valueValue8;
                  subStatusInstance.value = valueInstance7;
                }
                
                var localizedValueValue7 = subStatusValue['localizedValue'];
                if (localizedValueValue7 !== null && localizedValueValue7 !== undefined) {
                  var localizedValueInstance7 = localizedValueValue7;
                  subStatusInstance.localizedValue = localizedValueInstance7;
                }
              }
              
              var eventTimestampValue = valueValue['eventTimestamp'];
              if (eventTimestampValue !== null && eventTimestampValue !== undefined) {
                var eventTimestampInstance = eventTimestampValue;
                eventDataInstance.eventTimestamp = eventTimestampInstance;
              }
              
              var submissionTimestampValue = valueValue['submissionTimestamp'];
              if (submissionTimestampValue !== null && submissionTimestampValue !== undefined) {
                var submissionTimestampInstance = submissionTimestampValue;
                eventDataInstance.submissionTimestamp = submissionTimestampInstance;
              }
              
              var subscriptionIdValue = valueValue['subscriptionId'];
              if (subscriptionIdValue !== null && subscriptionIdValue !== undefined) {
                var subscriptionIdInstance = subscriptionIdValue;
                eventDataInstance.subscriptionId = subscriptionIdInstance;
              }
              
              var tenantIdValue = valueValue['tenantId'];
              if (tenantIdValue !== null && tenantIdValue !== undefined) {
                var tenantIdInstance = tenantIdValue;
                eventDataInstance.tenantId = tenantIdInstance;
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            eventDataCollectionInstance.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Digest Event Next operation lists the next set of digest events.
   * 
   * @param {string} nextLink The next link
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EventOperations.prototype.listDigestEventsNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    
    // 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 eventDataCollectionInstance = { value: [] };
          result.eventDataCollection = eventDataCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var eventDataInstance = { claims: {}, properties: {} };
              eventDataCollectionInstance.value.push(eventDataInstance);
              
              var authorizationValue = valueValue['authorization'];
              if (authorizationValue !== null && authorizationValue !== undefined) {
                var authorizationInstance = {};
                eventDataInstance.authorization = authorizationInstance;
                
                var actionValue = authorizationValue['action'];
                if (actionValue !== null && actionValue !== undefined) {
                  var actionInstance = actionValue;
                  authorizationInstance.action = actionInstance;
                }
                
                var conditionValue = authorizationValue['condition'];
                if (conditionValue !== null && conditionValue !== undefined) {
                  var conditionInstance = conditionValue;
                  authorizationInstance.condition = conditionInstance;
                }
                
                var roleValue = authorizationValue['role'];
                if (roleValue !== null && roleValue !== undefined) {
                  var roleInstance = roleValue;
                  authorizationInstance.role = roleInstance;
                }
                
                var scopeValue = authorizationValue['scope'];
                if (scopeValue !== null && scopeValue !== undefined) {
                  var scopeInstance = scopeValue;
                  authorizationInstance.scope = scopeInstance;
                }
              }
              
              var channelsValue = valueValue['channels'];
              if (channelsValue !== null && channelsValue !== undefined) {
                var channelsInstance = channelsValue;
                eventDataInstance.eventChannels = channelsInstance;
              }
              
              var claimsSequenceElement = valueValue['claims'];
              if (claimsSequenceElement !== null && claimsSequenceElement !== undefined) {
                for (var property in claimsSequenceElement) {
                  var claimsKey = property;
                  var claimsValue = claimsSequenceElement[property];
                  eventDataInstance.claims[claimsKey] = claimsValue;
                }
              }
              
              var callerValue = valueValue['caller'];
              if (callerValue !== null && callerValue !== undefined) {
                var callerInstance = callerValue;
                eventDataInstance.caller = callerInstance;
              }
              
              var descriptionValue = valueValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                eventDataInstance.description = descriptionInstance;
              }
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                eventDataInstance.id = idInstance;
              }
              
              var eventDataIdValue = valueValue['eventDataId'];
              if (eventDataIdValue !== null && eventDataIdValue !== undefined) {
                var eventDataIdInstance = eventDataIdValue;
                eventDataInstance.eventDataId = eventDataIdInstance;
              }
              
              var correlationIdValue = valueValue['correlationId'];
              if (correlationIdValue !== null && correlationIdValue !== undefined) {
                var correlationIdInstance = correlationIdValue;
                eventDataInstance.correlationId = correlationIdInstance;
              }
              
              var eventNameValue = valueValue['eventName'];
              if (eventNameValue !== null && eventNameValue !== undefined) {
                var eventNameInstance = {};
                eventDataInstance.eventName = eventNameInstance;
                
                var valueValue2 = eventNameValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  eventNameInstance.value = valueInstance;
                }
                
                var localizedValueValue = eventNameValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  eventNameInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var categoryValue = valueValue['category'];
              if (categoryValue !== null && categoryValue !== undefined) {
                var categoryInstance = {};
                eventDataInstance.category = categoryInstance;
                
                var valueValue3 = categoryValue['value'];
                if (valueValue3 !== null && valueValue3 !== undefined) {
                  var valueInstance2 = valueValue3;
                  categoryInstance.value = valueInstance2;
                }
                
                var localizedValueValue2 = categoryValue['localizedValue'];
                if (localizedValueValue2 !== null && localizedValueValue2 !== undefined) {
                  var localizedValueInstance2 = localizedValueValue2;
                  categoryInstance.localizedValue = localizedValueInstance2;
                }
              }
              
              var httpRequestValue = valueValue['httpRequest'];
              if (httpRequestValue !== null && httpRequestValue !== undefined) {
                var httpRequestInstance = {};
                eventDataInstance.httpRequest = httpRequestInstance;
                
                var clientRequestIdValue = httpRequestValue['clientRequestId'];
                if (clientRequestIdValue !== null && clientRequestIdValue !== undefined) {
                  var clientRequestIdInstance = clientRequestIdValue;
                  httpRequestInstance.clientRequestId = clientRequestIdInstance;
                }
                
                var clientIpAddressValue = httpRequestValue['clientIpAddress'];
                if (clientIpAddressValue !== null && clientIpAddressValue !== undefined) {
                  var clientIpAddressInstance = clientIpAddressValue;
                  httpRequestInstance.clientIpAddress = clientIpAddressInstance;
                }
                
                var methodValue = httpRequestValue['method'];
                if (methodValue !== null && methodValue !== undefined) {
                  var methodInstance = methodValue;
                  httpRequestInstance.method = methodInstance;
                }
                
                var uriValue = httpRequestValue['uri'];
                if (uriValue !== null && uriValue !== undefined) {
                  var uriInstance = uriValue;
                  httpRequestInstance.uri = uriInstance;
                }
              }
              
              var levelValue = valueValue['level'];
              if (levelValue !== null && levelValue !== undefined) {
                var levelInstance = levelValue;
                eventDataInstance.level = levelInstance;
              }
              
              var resourceGroupNameValue = valueValue['resourceGroupName'];
              if (resourceGroupNameValue !== null && resourceGroupNameValue !== undefined) {
                var resourceGroupNameInstance = resourceGroupNameValue;
                eventDataInstance.resourceGroupName = resourceGroupNameInstance;
              }
              
              var resourceProviderNameValue = valueValue['resourceProviderName'];
              if (resourceProviderNameValue !== null && resourceProviderNameValue !== undefined) {
                var resourceProviderNameInstance = {};
                eventDataInstance.resourceProviderName = resourceProviderNameInstance;
                
                var valueValue4 = resourceProviderNameValue['value'];
                if (valueValue4 !== null && valueValue4 !== undefined) {
                  var valueInstance3 = valueValue4;
                  resourceProviderNameInstance.value = valueInstance3;
                }
                
                var localizedValueValue3 = resourceProviderNameValue['localizedValue'];
                if (localizedValueValue3 !== null && localizedValueValue3 !== undefined) {
                  var localizedValueInstance3 = localizedValueValue3;
                  resourceProviderNameInstance.localizedValue = localizedValueInstance3;
                }
              }
              
              var resourceIdValue = valueValue['resourceId'];
              if (resourceIdValue !== null && resourceIdValue !== undefined) {
                var resourceIdInstance = resourceIdValue;
                eventDataInstance.resourceId = resourceIdInstance;
              }
              
              var resourceTypeValue = valueValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = {};
                eventDataInstance.resourceType = resourceTypeInstance;
                
                var valueValue5 = resourceTypeValue['value'];
                if (valueValue5 !== null && valueValue5 !== undefined) {
                  var valueInstance4 = valueValue5;
                  resourceTypeInstance.value = valueInstance4;
                }
                
                var localizedValueValue4 = resourceTypeValue['localizedValue'];
                if (localizedValueValue4 !== null && localizedValueValue4 !== undefined) {
                  var localizedValueInstance4 = localizedValueValue4;
                  resourceTypeInstance.localizedValue = localizedValueInstance4;
                }
              }
              
              var operationIdValue = valueValue['operationId'];
              if (operationIdValue !== null && operationIdValue !== undefined) {
                var operationIdInstance = operationIdValue;
                eventDataInstance.operationId = operationIdInstance;
              }
              
              var operationNameValue = valueValue['operationName'];
              if (operationNameValue !== null && operationNameValue !== undefined) {
                var operationNameInstance = {};
                eventDataInstance.operationName = operationNameInstance;
                
                var valueValue6 = operationNameValue['value'];
                if (valueValue6 !== null && valueValue6 !== undefined) {
                  var valueInstance5 = valueValue6;
                  operationNameInstance.value = valueInstance5;
                }
                
                var localizedValueValue5 = operationNameValue['localizedValue'];
                if (localizedValueValue5 !== null && localizedValueValue5 !== undefined) {
                  var localizedValueInstance5 = localizedValueValue5;
                  operationNameInstance.localizedValue = localizedValueInstance5;
                }
              }
              
              var propertiesSequenceElement = valueValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property2 in propertiesSequenceElement) {
                  var propertiesKey = property2;
                  var propertiesValue = propertiesSequenceElement[property2];
                  eventDataInstance.properties[propertiesKey] = propertiesValue;
                }
              }
              
              var statusValue = valueValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = {};
                eventDataInstance.status = statusInstance;
                
                var valueValue7 = statusValue['value'];
                if (valueValue7 !== null && valueValue7 !== undefined) {
                  var valueInstance6 = valueValue7;
                  statusInstance.value = valueInstance6;
                }
                
                var localizedValueValue6 = statusValue['localizedValue'];
                if (localizedValueValue6 !== null && localizedValueValue6 !== undefined) {
                  var localizedValueInstance6 = localizedValueValue6;
                  statusInstance.localizedValue = localizedValueInstance6;
                }
              }
              
              var subStatusValue = valueValue['subStatus'];
              if (subStatusValue !== null && subStatusValue !== undefined) {
                var subStatusInstance = {};
                eventDataInstance.subStatus = subStatusInstance;
                
                var valueValue8 = subStatusValue['value'];
                if (valueValue8 !== null && valueValue8 !== undefined) {
                  var valueInstance7 = valueValue8;
                  subStatusInstance.value = valueInstance7;
                }
                
                var localizedValueValue7 = subStatusValue['localizedValue'];
                if (localizedValueValue7 !== null && localizedValueValue7 !== undefined) {
                  var localizedValueInstance7 = localizedValueValue7;
                  subStatusInstance.localizedValue = localizedValueInstance7;
                }
              }
              
              var eventTimestampValue = valueValue['eventTimestamp'];
              if (eventTimestampValue !== null && eventTimestampValue !== undefined) {
                var eventTimestampInstance = eventTimestampValue;
                eventDataInstance.eventTimestamp = eventTimestampInstance;
              }
              
              var submissionTimestampValue = valueValue['submissionTimestamp'];
              if (submissionTimestampValue !== null && submissionTimestampValue !== undefined) {
                var submissionTimestampInstance = submissionTimestampValue;
                eventDataInstance.submissionTimestamp = submissionTimestampInstance;
              }
              
              var subscriptionIdValue = valueValue['subscriptionId'];
              if (subscriptionIdValue !== null && subscriptionIdValue !== undefined) {
                var subscriptionIdInstance = subscriptionIdValue;
                eventDataInstance.subscriptionId = subscriptionIdInstance;
              }
              
              var tenantIdValue = valueValue['tenantId'];
              if (tenantIdValue !== null && tenantIdValue !== undefined) {
                var tenantIdInstance = tenantIdValue;
                eventDataInstance.tenantId = tenantIdInstance;
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            eventDataCollectionInstance.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The list of event categories.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EventOperations.prototype.listEventCategories = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/providers/microsoft.insights/eventtypes/management/eventcategories';
    var queryParameters = [];
    queryParameters.push('api-version=2015-04-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    
    // 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 eventDataCollectionInstance = { value: [] };
          result.eventDataCollection = eventDataCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var localizableStringInstance = {};
              eventDataCollectionInstance.value.push(localizableStringInstance);
              
              var valueValue2 = valueValue['value'];
              if (valueValue2 !== null && valueValue2 !== undefined) {
                var valueInstance = valueValue2;
                localizableStringInstance.value = valueInstance;
              }
              
              var localizedValueValue = valueValue['localizedValue'];
              if (localizedValueValue !== null && localizedValueValue !== undefined) {
                var localizedValueInstance = localizedValueValue;
                localizableStringInstance.localizedValue = localizedValueInstance;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Event Values operation lists the events.
   * 
   * @param {string} filterString The filter string should be generated using
   * Microsoft.WindowsAzure.Common.OData.FilterStringHere is an example:var
   * filterString = FilterString.Generate<GetCountSummaryParameters> (p =>
   * (p.StartTime == startTime) && p.EndTime == endTime);
   * 
   * @param {string} [selectedProperties] The list of property names to be
   * returned. You can save bandwidth by selecting only the properties you
   * need.Here is an example:string selectedProperties = "EventDataId,
   * EventTimestamp, ResourceUri"
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EventOperations.prototype.listEvents = function(filterString, selectedProperties, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (filterString === null || filterString === undefined) {
      return callback(new Error('filterString 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.insights/eventtypes/management/values';
    var queryParameters = [];
    queryParameters.push('api-version=2015-04-01');
    var odataFilter = [];
    odataFilter.push(encodeURIComponent(filterString));
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(null));
    }
    if (selectedProperties !== null && selectedProperties !== undefined) {
      queryParameters.push('$select=' + encodeURIComponent(selectedProperties));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    
    // 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 eventDataCollectionInstance = { value: [] };
          result.eventDataCollection = eventDataCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var eventDataInstance = { claims: {}, properties: {} };
              eventDataCollectionInstance.value.push(eventDataInstance);
              
              var authorizationValue = valueValue['authorization'];
              if (authorizationValue !== null && authorizationValue !== undefined) {
                var authorizationInstance = {};
                eventDataInstance.authorization = authorizationInstance;
                
                var actionValue = authorizationValue['action'];
                if (actionValue !== null && actionValue !== undefined) {
                  var actionInstance = actionValue;
                  authorizationInstance.action = actionInstance;
                }
                
                var conditionValue = authorizationValue['condition'];
                if (conditionValue !== null && conditionValue !== undefined) {
                  var conditionInstance = conditionValue;
                  authorizationInstance.condition = conditionInstance;
                }
                
                var roleValue = authorizationValue['role'];
                if (roleValue !== null && roleValue !== undefined) {
                  var roleInstance = roleValue;
                  authorizationInstance.role = roleInstance;
                }
                
                var scopeValue = authorizationValue['scope'];
                if (scopeValue !== null && scopeValue !== undefined) {
                  var scopeInstance = scopeValue;
                  authorizationInstance.scope = scopeInstance;
                }
              }
              
              var channelsValue = valueValue['channels'];
              if (channelsValue !== null && channelsValue !== undefined) {
                var channelsInstance = channelsValue;
                eventDataInstance.eventChannels = channelsInstance;
              }
              
              var claimsSequenceElement = valueValue['claims'];
              if (claimsSequenceElement !== null && claimsSequenceElement !== undefined) {
                for (var property in claimsSequenceElement) {
                  var claimsKey = property;
                  var claimsValue = claimsSequenceElement[property];
                  eventDataInstance.claims[claimsKey] = claimsValue;
                }
              }
              
              var callerValue = valueValue['caller'];
              if (callerValue !== null && callerValue !== undefined) {
                var callerInstance = callerValue;
                eventDataInstance.caller = callerInstance;
              }
              
              var descriptionValue = valueValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                eventDataInstance.description = descriptionInstance;
              }
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                eventDataInstance.id = idInstance;
              }
              
              var eventDataIdValue = valueValue['eventDataId'];
              if (eventDataIdValue !== null && eventDataIdValue !== undefined) {
                var eventDataIdInstance = eventDataIdValue;
                eventDataInstance.eventDataId = eventDataIdInstance;
              }
              
              var correlationIdValue = valueValue['correlationId'];
              if (correlationIdValue !== null && correlationIdValue !== undefined) {
                var correlationIdInstance = correlationIdValue;
                eventDataInstance.correlationId = correlationIdInstance;
              }
              
              var eventNameValue = valueValue['eventName'];
              if (eventNameValue !== null && eventNameValue !== undefined) {
                var eventNameInstance = {};
                eventDataInstance.eventName = eventNameInstance;
                
                var valueValue2 = eventNameValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  eventNameInstance.value = valueInstance;
                }
                
                var localizedValueValue = eventNameValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  eventNameInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var categoryValue = valueValue['category'];
              if (categoryValue !== null && categoryValue !== undefined) {
                var categoryInstance = {};
                eventDataInstance.category = categoryInstance;
                
                var valueValue3 = categoryValue['value'];
                if (valueValue3 !== null && valueValue3 !== undefined) {
                  var valueInstance2 = valueValue3;
                  categoryInstance.value = valueInstance2;
                }
                
                var localizedValueValue2 = categoryValue['localizedValue'];
                if (localizedValueValue2 !== null && localizedValueValue2 !== undefined) {
                  var localizedValueInstance2 = localizedValueValue2;
                  categoryInstance.localizedValue = localizedValueInstance2;
                }
              }
              
              var httpRequestValue = valueValue['httpRequest'];
              if (httpRequestValue !== null && httpRequestValue !== undefined) {
                var httpRequestInstance = {};
                eventDataInstance.httpRequest = httpRequestInstance;
                
                var clientRequestIdValue = httpRequestValue['clientRequestId'];
                if (clientRequestIdValue !== null && clientRequestIdValue !== undefined) {
                  var clientRequestIdInstance = clientRequestIdValue;
                  httpRequestInstance.clientRequestId = clientRequestIdInstance;
                }
                
                var clientIpAddressValue = httpRequestValue['clientIpAddress'];
                if (clientIpAddressValue !== null && clientIpAddressValue !== undefined) {
                  var clientIpAddressInstance = clientIpAddressValue;
                  httpRequestInstance.clientIpAddress = clientIpAddressInstance;
                }
                
                var methodValue = httpRequestValue['method'];
                if (methodValue !== null && methodValue !== undefined) {
                  var methodInstance = methodValue;
                  httpRequestInstance.method = methodInstance;
                }
                
                var uriValue = httpRequestValue['uri'];
                if (uriValue !== null && uriValue !== undefined) {
                  var uriInstance = uriValue;
                  httpRequestInstance.uri = uriInstance;
                }
              }
              
              var levelValue = valueValue['level'];
              if (levelValue !== null && levelValue !== undefined) {
                var levelInstance = levelValue;
                eventDataInstance.level = levelInstance;
              }
              
              var resourceGroupNameValue = valueValue['resourceGroupName'];
              if (resourceGroupNameValue !== null && resourceGroupNameValue !== undefined) {
                var resourceGroupNameInstance = resourceGroupNameValue;
                eventDataInstance.resourceGroupName = resourceGroupNameInstance;
              }
              
              var resourceProviderNameValue = valueValue['resourceProviderName'];
              if (resourceProviderNameValue !== null && resourceProviderNameValue !== undefined) {
                var resourceProviderNameInstance = {};
                eventDataInstance.resourceProviderName = resourceProviderNameInstance;
                
                var valueValue4 = resourceProviderNameValue['value'];
                if (valueValue4 !== null && valueValue4 !== undefined) {
                  var valueInstance3 = valueValue4;
                  resourceProviderNameInstance.value = valueInstance3;
                }
                
                var localizedValueValue3 = resourceProviderNameValue['localizedValue'];
                if (localizedValueValue3 !== null && localizedValueValue3 !== undefined) {
                  var localizedValueInstance3 = localizedValueValue3;
                  resourceProviderNameInstance.localizedValue = localizedValueInstance3;
                }
              }
              
              var resourceIdValue = valueValue['resourceId'];
              if (resourceIdValue !== null && resourceIdValue !== undefined) {
                var resourceIdInstance = resourceIdValue;
                eventDataInstance.resourceId = resourceIdInstance;
              }
              
              var resourceTypeValue = valueValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = {};
                eventDataInstance.resourceType = resourceTypeInstance;
                
                var valueValue5 = resourceTypeValue['value'];
                if (valueValue5 !== null && valueValue5 !== undefined) {
                  var valueInstance4 = valueValue5;
                  resourceTypeInstance.value = valueInstance4;
                }
                
                var localizedValueValue4 = resourceTypeValue['localizedValue'];
                if (localizedValueValue4 !== null && localizedValueValue4 !== undefined) {
                  var localizedValueInstance4 = localizedValueValue4;
                  resourceTypeInstance.localizedValue = localizedValueInstance4;
                }
              }
              
              var operationIdValue = valueValue['operationId'];
              if (operationIdValue !== null && operationIdValue !== undefined) {
                var operationIdInstance = operationIdValue;
                eventDataInstance.operationId = operationIdInstance;
              }
              
              var operationNameValue = valueValue['operationName'];
              if (operationNameValue !== null && operationNameValue !== undefined) {
                var operationNameInstance = {};
                eventDataInstance.operationName = operationNameInstance;
                
                var valueValue6 = operationNameValue['value'];
                if (valueValue6 !== null && valueValue6 !== undefined) {
                  var valueInstance5 = valueValue6;
                  operationNameInstance.value = valueInstance5;
                }
                
                var localizedValueValue5 = operationNameValue['localizedValue'];
                if (localizedValueValue5 !== null && localizedValueValue5 !== undefined) {
                  var localizedValueInstance5 = localizedValueValue5;
                  operationNameInstance.localizedValue = localizedValueInstance5;
                }
              }
              
              var propertiesSequenceElement = valueValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property2 in propertiesSequenceElement) {
                  var propertiesKey = property2;
                  var propertiesValue = propertiesSequenceElement[property2];
                  eventDataInstance.properties[propertiesKey] = propertiesValue;
                }
              }
              
              var statusValue = valueValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = {};
                eventDataInstance.status = statusInstance;
                
                var valueValue7 = statusValue['value'];
                if (valueValue7 !== null && valueValue7 !== undefined) {
                  var valueInstance6 = valueValue7;
                  statusInstance.value = valueInstance6;
                }
                
                var localizedValueValue6 = statusValue['localizedValue'];
                if (localizedValueValue6 !== null && localizedValueValue6 !== undefined) {
                  var localizedValueInstance6 = localizedValueValue6;
                  statusInstance.localizedValue = localizedValueInstance6;
                }
              }
              
              var subStatusValue = valueValue['subStatus'];
              if (subStatusValue !== null && subStatusValue !== undefined) {
                var subStatusInstance = {};
                eventDataInstance.subStatus = subStatusInstance;
                
                var valueValue8 = subStatusValue['value'];
                if (valueValue8 !== null && valueValue8 !== undefined) {
                  var valueInstance7 = valueValue8;
                  subStatusInstance.value = valueInstance7;
                }
                
                var localizedValueValue7 = subStatusValue['localizedValue'];
                if (localizedValueValue7 !== null && localizedValueValue7 !== undefined) {
                  var localizedValueInstance7 = localizedValueValue7;
                  subStatusInstance.localizedValue = localizedValueInstance7;
                }
              }
              
              var eventTimestampValue = valueValue['eventTimestamp'];
              if (eventTimestampValue !== null && eventTimestampValue !== undefined) {
                var eventTimestampInstance = eventTimestampValue;
                eventDataInstance.eventTimestamp = eventTimestampInstance;
              }
              
              var submissionTimestampValue = valueValue['submissionTimestamp'];
              if (submissionTimestampValue !== null && submissionTimestampValue !== undefined) {
                var submissionTimestampInstance = submissionTimestampValue;
                eventDataInstance.submissionTimestamp = submissionTimestampInstance;
              }
              
              var subscriptionIdValue = valueValue['subscriptionId'];
              if (subscriptionIdValue !== null && subscriptionIdValue !== undefined) {
                var subscriptionIdInstance = subscriptionIdValue;
                eventDataInstance.subscriptionId = subscriptionIdInstance;
              }
              
              var tenantIdValue = valueValue['tenantId'];
              if (tenantIdValue !== null && tenantIdValue !== undefined) {
                var tenantIdInstance = tenantIdValue;
                eventDataInstance.tenantId = tenantIdInstance;
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            eventDataCollectionInstance.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Event Next operation lists the next set of events.
   * 
   * @param {string} nextLink The next link works as a continuation token when
   * all of the events are not returned in the response and a second call is
   * required
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EventOperations.prototype.listEventsNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    
    // 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 eventDataCollectionInstance = { value: [] };
          result.eventDataCollection = eventDataCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var eventDataInstance = { claims: {}, properties: {} };
              eventDataCollectionInstance.value.push(eventDataInstance);
              
              var authorizationValue = valueValue['authorization'];
              if (authorizationValue !== null && authorizationValue !== undefined) {
                var authorizationInstance = {};
                eventDataInstance.authorization = authorizationInstance;
                
                var actionValue = authorizationValue['action'];
                if (actionValue !== null && actionValue !== undefined) {
                  var actionInstance = actionValue;
                  authorizationInstance.action = actionInstance;
                }
                
                var conditionValue = authorizationValue['condition'];
                if (conditionValue !== null && conditionValue !== undefined) {
                  var conditionInstance = conditionValue;
                  authorizationInstance.condition = conditionInstance;
                }
                
                var roleValue = authorizationValue['role'];
                if (roleValue !== null && roleValue !== undefined) {
                  var roleInstance = roleValue;
                  authorizationInstance.role = roleInstance;
                }
                
                var scopeValue = authorizationValue['scope'];
                if (scopeValue !== null && scopeValue !== undefined) {
                  var scopeInstance = scopeValue;
                  authorizationInstance.scope = scopeInstance;
                }
              }
              
              var channelsValue = valueValue['channels'];
              if (channelsValue !== null && channelsValue !== undefined) {
                var channelsInstance = channelsValue;
                eventDataInstance.eventChannels = channelsInstance;
              }
              
              var claimsSequenceElement = valueValue['claims'];
              if (claimsSequenceElement !== null && claimsSequenceElement !== undefined) {
                for (var property in claimsSequenceElement) {
                  var claimsKey = property;
                  var claimsValue = claimsSequenceElement[property];
                  eventDataInstance.claims[claimsKey] = claimsValue;
                }
              }
              
              var callerValue = valueValue['caller'];
              if (callerValue !== null && callerValue !== undefined) {
                var callerInstance = callerValue;
                eventDataInstance.caller = callerInstance;
              }
              
              var descriptionValue = valueValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                eventDataInstance.description = descriptionInstance;
              }
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                eventDataInstance.id = idInstance;
              }
              
              var eventDataIdValue = valueValue['eventDataId'];
              if (eventDataIdValue !== null && eventDataIdValue !== undefined) {
                var eventDataIdInstance = eventDataIdValue;
                eventDataInstance.eventDataId = eventDataIdInstance;
              }
              
              var correlationIdValue = valueValue['correlationId'];
              if (correlationIdValue !== null && correlationIdValue !== undefined) {
                var correlationIdInstance = correlationIdValue;
                eventDataInstance.correlationId = correlationIdInstance;
              }
              
              var eventNameValue = valueValue['eventName'];
              if (eventNameValue !== null && eventNameValue !== undefined) {
                var eventNameInstance = {};
                eventDataInstance.eventName = eventNameInstance;
                
                var valueValue2 = eventNameValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  eventNameInstance.value = valueInstance;
                }
                
                var localizedValueValue = eventNameValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  eventNameInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var categoryValue = valueValue['category'];
              if (categoryValue !== null && categoryValue !== undefined) {
                var categoryInstance = {};
                eventDataInstance.category = categoryInstance;
                
                var valueValue3 = categoryValue['value'];
                if (valueValue3 !== null && valueValue3 !== undefined) {
                  var valueInstance2 = valueValue3;
                  categoryInstance.value = valueInstance2;
                }
                
                var localizedValueValue2 = categoryValue['localizedValue'];
                if (localizedValueValue2 !== null && localizedValueValue2 !== undefined) {
                  var localizedValueInstance2 = localizedValueValue2;
                  categoryInstance.localizedValue = localizedValueInstance2;
                }
              }
              
              var httpRequestValue = valueValue['httpRequest'];
              if (httpRequestValue !== null && httpRequestValue !== undefined) {
                var httpRequestInstance = {};
                eventDataInstance.httpRequest = httpRequestInstance;
                
                var clientRequestIdValue = httpRequestValue['clientRequestId'];
                if (clientRequestIdValue !== null && clientRequestIdValue !== undefined) {
                  var clientRequestIdInstance = clientRequestIdValue;
                  httpRequestInstance.clientRequestId = clientRequestIdInstance;
                }
                
                var clientIpAddressValue = httpRequestValue['clientIpAddress'];
                if (clientIpAddressValue !== null && clientIpAddressValue !== undefined) {
                  var clientIpAddressInstance = clientIpAddressValue;
                  httpRequestInstance.clientIpAddress = clientIpAddressInstance;
                }
                
                var methodValue = httpRequestValue['method'];
                if (methodValue !== null && methodValue !== undefined) {
                  var methodInstance = methodValue;
                  httpRequestInstance.method = methodInstance;
                }
                
                var uriValue = httpRequestValue['uri'];
                if (uriValue !== null && uriValue !== undefined) {
                  var uriInstance = uriValue;
                  httpRequestInstance.uri = uriInstance;
                }
              }
              
              var levelValue = valueValue['level'];
              if (levelValue !== null && levelValue !== undefined) {
                var levelInstance = levelValue;
                eventDataInstance.level = levelInstance;
              }
              
              var resourceGroupNameValue = valueValue['resourceGroupName'];
              if (resourceGroupNameValue !== null && resourceGroupNameValue !== undefined) {
                var resourceGroupNameInstance = resourceGroupNameValue;
                eventDataInstance.resourceGroupName = resourceGroupNameInstance;
              }
              
              var resourceProviderNameValue = valueValue['resourceProviderName'];
              if (resourceProviderNameValue !== null && resourceProviderNameValue !== undefined) {
                var resourceProviderNameInstance = {};
                eventDataInstance.resourceProviderName = resourceProviderNameInstance;
                
                var valueValue4 = resourceProviderNameValue['value'];
                if (valueValue4 !== null && valueValue4 !== undefined) {
                  var valueInstance3 = valueValue4;
                  resourceProviderNameInstance.value = valueInstance3;
                }
                
                var localizedValueValue3 = resourceProviderNameValue['localizedValue'];
                if (localizedValueValue3 !== null && localizedValueValue3 !== undefined) {
                  var localizedValueInstance3 = localizedValueValue3;
                  resourceProviderNameInstance.localizedValue = localizedValueInstance3;
                }
              }
              
              var resourceIdValue = valueValue['resourceId'];
              if (resourceIdValue !== null && resourceIdValue !== undefined) {
                var resourceIdInstance = resourceIdValue;
                eventDataInstance.resourceId = resourceIdInstance;
              }
              
              var resourceTypeValue = valueValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = {};
                eventDataInstance.resourceType = resourceTypeInstance;
                
                var valueValue5 = resourceTypeValue['value'];
                if (valueValue5 !== null && valueValue5 !== undefined) {
                  var valueInstance4 = valueValue5;
                  resourceTypeInstance.value = valueInstance4;
                }
                
                var localizedValueValue4 = resourceTypeValue['localizedValue'];
                if (localizedValueValue4 !== null && localizedValueValue4 !== undefined) {
                  var localizedValueInstance4 = localizedValueValue4;
                  resourceTypeInstance.localizedValue = localizedValueInstance4;
                }
              }
              
              var operationIdValue = valueValue['operationId'];
              if (operationIdValue !== null && operationIdValue !== undefined) {
                var operationIdInstance = operationIdValue;
                eventDataInstance.operationId = operationIdInstance;
              }
              
              var operationNameValue = valueValue['operationName'];
              if (operationNameValue !== null && operationNameValue !== undefined) {
                var operationNameInstance = {};
                eventDataInstance.operationName = operationNameInstance;
                
                var valueValue6 = operationNameValue['value'];
                if (valueValue6 !== null && valueValue6 !== undefined) {
                  var valueInstance5 = valueValue6;
                  operationNameInstance.value = valueInstance5;
                }
                
                var localizedValueValue5 = operationNameValue['localizedValue'];
                if (localizedValueValue5 !== null && localizedValueValue5 !== undefined) {
                  var localizedValueInstance5 = localizedValueValue5;
                  operationNameInstance.localizedValue = localizedValueInstance5;
                }
              }
              
              var propertiesSequenceElement = valueValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property2 in propertiesSequenceElement) {
                  var propertiesKey = property2;
                  var propertiesValue = propertiesSequenceElement[property2];
                  eventDataInstance.properties[propertiesKey] = propertiesValue;
                }
              }
              
              var statusValue = valueValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = {};
                eventDataInstance.status = statusInstance;
                
                var valueValue7 = statusValue['value'];
                if (valueValue7 !== null && valueValue7 !== undefined) {
                  var valueInstance6 = valueValue7;
                  statusInstance.value = valueInstance6;
                }
                
                var localizedValueValue6 = statusValue['localizedValue'];
                if (localizedValueValue6 !== null && localizedValueValue6 !== undefined) {
                  var localizedValueInstance6 = localizedValueValue6;
                  statusInstance.localizedValue = localizedValueInstance6;
                }
              }
              
              var subStatusValue = valueValue['subStatus'];
              if (subStatusValue !== null && subStatusValue !== undefined) {
                var subStatusInstance = {};
                eventDataInstance.subStatus = subStatusInstance;
                
                var valueValue8 = subStatusValue['value'];
                if (valueValue8 !== null && valueValue8 !== undefined) {
                  var valueInstance7 = valueValue8;
                  subStatusInstance.value = valueInstance7;
                }
                
                var localizedValueValue7 = subStatusValue['localizedValue'];
                if (localizedValueValue7 !== null && localizedValueValue7 !== undefined) {
                  var localizedValueInstance7 = localizedValueValue7;
                  subStatusInstance.localizedValue = localizedValueInstance7;
                }
              }
              
              var eventTimestampValue = valueValue['eventTimestamp'];
              if (eventTimestampValue !== null && eventTimestampValue !== undefined) {
                var eventTimestampInstance = eventTimestampValue;
                eventDataInstance.eventTimestamp = eventTimestampInstance;
              }
              
              var submissionTimestampValue = valueValue['submissionTimestamp'];
              if (submissionTimestampValue !== null && submissionTimestampValue !== undefined) {
                var submissionTimestampInstance = submissionTimestampValue;
                eventDataInstance.submissionTimestamp = submissionTimestampInstance;
              }
              
              var subscriptionIdValue = valueValue['subscriptionId'];
              if (subscriptionIdValue !== null && subscriptionIdValue !== undefined) {
                var subscriptionIdInstance = subscriptionIdValue;
                eventDataInstance.subscriptionId = subscriptionIdInstance;
              }
              
              var tenantIdValue = valueValue['tenantId'];
              if (tenantIdValue !== null && tenantIdValue !== undefined) {
                var tenantIdInstance = tenantIdValue;
                eventDataInstance.tenantId = tenantIdInstance;
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            eventDataCollectionInstance.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Tenant Digest Event Values operation lists the tenant-level
   * digest events.
   * 
   * @param {string} filterString The filter string
   * 
   * @param {string} [selectedProperties] The list of property names to be
   * returned. You can save bandwith by selecting only the properties you need.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EventOperations.prototype.listTenantDigestEvents = function(filterString, selectedProperties, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (filterString === null || filterString === undefined) {
      return callback(new Error('filterString cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/providers/microsoft.insights/eventtypes/management/digestEvents';
    var queryParameters = [];
    queryParameters.push('api-version=2015-04-01');
    var odataFilter = [];
    odataFilter.push(encodeURIComponent(filterString));
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(null));
    }
    if (selectedProperties !== null && selectedProperties !== undefined) {
      queryParameters.push('$select=' + encodeURIComponent(selectedProperties));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    
    // 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 eventDataCollectionInstance = { value: [] };
          result.eventDataCollection = eventDataCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var eventDataInstance = { claims: {}, properties: {} };
              eventDataCollectionInstance.value.push(eventDataInstance);
              
              var authorizationValue = valueValue['authorization'];
              if (authorizationValue !== null && authorizationValue !== undefined) {
                var authorizationInstance = {};
                eventDataInstance.authorization = authorizationInstance;
                
                var actionValue = authorizationValue['action'];
                if (actionValue !== null && actionValue !== undefined) {
                  var actionInstance = actionValue;
                  authorizationInstance.action = actionInstance;
                }
                
                var conditionValue = authorizationValue['condition'];
                if (conditionValue !== null && conditionValue !== undefined) {
                  var conditionInstance = conditionValue;
                  authorizationInstance.condition = conditionInstance;
                }
                
                var roleValue = authorizationValue['role'];
                if (roleValue !== null && roleValue !== undefined) {
                  var roleInstance = roleValue;
                  authorizationInstance.role = roleInstance;
                }
                
                var scopeValue = authorizationValue['scope'];
                if (scopeValue !== null && scopeValue !== undefined) {
                  var scopeInstance = scopeValue;
                  authorizationInstance.scope = scopeInstance;
                }
              }
              
              var channelsValue = valueValue['channels'];
              if (channelsValue !== null && channelsValue !== undefined) {
                var channelsInstance = channelsValue;
                eventDataInstance.eventChannels = channelsInstance;
              }
              
              var claimsSequenceElement = valueValue['claims'];
              if (claimsSequenceElement !== null && claimsSequenceElement !== undefined) {
                for (var property in claimsSequenceElement) {
                  var claimsKey = property;
                  var claimsValue = claimsSequenceElement[property];
                  eventDataInstance.claims[claimsKey] = claimsValue;
                }
              }
              
              var callerValue = valueValue['caller'];
              if (callerValue !== null && callerValue !== undefined) {
                var callerInstance = callerValue;
                eventDataInstance.caller = callerInstance;
              }
              
              var descriptionValue = valueValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                eventDataInstance.description = descriptionInstance;
              }
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                eventDataInstance.id = idInstance;
              }
              
              var eventDataIdValue = valueValue['eventDataId'];
              if (eventDataIdValue !== null && eventDataIdValue !== undefined) {
                var eventDataIdInstance = eventDataIdValue;
                eventDataInstance.eventDataId = eventDataIdInstance;
              }
              
              var correlationIdValue = valueValue['correlationId'];
              if (correlationIdValue !== null && correlationIdValue !== undefined) {
                var correlationIdInstance = correlationIdValue;
                eventDataInstance.correlationId = correlationIdInstance;
              }
              
              var eventNameValue = valueValue['eventName'];
              if (eventNameValue !== null && eventNameValue !== undefined) {
                var eventNameInstance = {};
                eventDataInstance.eventName = eventNameInstance;
                
                var valueValue2 = eventNameValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  eventNameInstance.value = valueInstance;
                }
                
                var localizedValueValue = eventNameValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  eventNameInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var categoryValue = valueValue['category'];
              if (categoryValue !== null && categoryValue !== undefined) {
                var categoryInstance = {};
                eventDataInstance.category = categoryInstance;
                
                var valueValue3 = categoryValue['value'];
                if (valueValue3 !== null && valueValue3 !== undefined) {
                  var valueInstance2 = valueValue3;
                  categoryInstance.value = valueInstance2;
                }
                
                var localizedValueValue2 = categoryValue['localizedValue'];
                if (localizedValueValue2 !== null && localizedValueValue2 !== undefined) {
                  var localizedValueInstance2 = localizedValueValue2;
                  categoryInstance.localizedValue = localizedValueInstance2;
                }
              }
              
              var httpRequestValue = valueValue['httpRequest'];
              if (httpRequestValue !== null && httpRequestValue !== undefined) {
                var httpRequestInstance = {};
                eventDataInstance.httpRequest = httpRequestInstance;
                
                var clientRequestIdValue = httpRequestValue['clientRequestId'];
                if (clientRequestIdValue !== null && clientRequestIdValue !== undefined) {
                  var clientRequestIdInstance = clientRequestIdValue;
                  httpRequestInstance.clientRequestId = clientRequestIdInstance;
                }
                
                var clientIpAddressValue = httpRequestValue['clientIpAddress'];
                if (clientIpAddressValue !== null && clientIpAddressValue !== undefined) {
                  var clientIpAddressInstance = clientIpAddressValue;
                  httpRequestInstance.clientIpAddress = clientIpAddressInstance;
                }
                
                var methodValue = httpRequestValue['method'];
                if (methodValue !== null && methodValue !== undefined) {
                  var methodInstance = methodValue;
                  httpRequestInstance.method = methodInstance;
                }
                
                var uriValue = httpRequestValue['uri'];
                if (uriValue !== null && uriValue !== undefined) {
                  var uriInstance = uriValue;
                  httpRequestInstance.uri = uriInstance;
                }
              }
              
              var levelValue = valueValue['level'];
              if (levelValue !== null && levelValue !== undefined) {
                var levelInstance = levelValue;
                eventDataInstance.level = levelInstance;
              }
              
              var resourceGroupNameValue = valueValue['resourceGroupName'];
              if (resourceGroupNameValue !== null && resourceGroupNameValue !== undefined) {
                var resourceGroupNameInstance = resourceGroupNameValue;
                eventDataInstance.resourceGroupName = resourceGroupNameInstance;
              }
              
              var resourceProviderNameValue = valueValue['resourceProviderName'];
              if (resourceProviderNameValue !== null && resourceProviderNameValue !== undefined) {
                var resourceProviderNameInstance = {};
                eventDataInstance.resourceProviderName = resourceProviderNameInstance;
                
                var valueValue4 = resourceProviderNameValue['value'];
                if (valueValue4 !== null && valueValue4 !== undefined) {
                  var valueInstance3 = valueValue4;
                  resourceProviderNameInstance.value = valueInstance3;
                }
                
                var localizedValueValue3 = resourceProviderNameValue['localizedValue'];
                if (localizedValueValue3 !== null && localizedValueValue3 !== undefined) {
                  var localizedValueInstance3 = localizedValueValue3;
                  resourceProviderNameInstance.localizedValue = localizedValueInstance3;
                }
              }
              
              var resourceIdValue = valueValue['resourceId'];
              if (resourceIdValue !== null && resourceIdValue !== undefined) {
                var resourceIdInstance = resourceIdValue;
                eventDataInstance.resourceId = resourceIdInstance;
              }
              
              var resourceTypeValue = valueValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = {};
                eventDataInstance.resourceType = resourceTypeInstance;
                
                var valueValue5 = resourceTypeValue['value'];
                if (valueValue5 !== null && valueValue5 !== undefined) {
                  var valueInstance4 = valueValue5;
                  resourceTypeInstance.value = valueInstance4;
                }
                
                var localizedValueValue4 = resourceTypeValue['localizedValue'];
                if (localizedValueValue4 !== null && localizedValueValue4 !== undefined) {
                  var localizedValueInstance4 = localizedValueValue4;
                  resourceTypeInstance.localizedValue = localizedValueInstance4;
                }
              }
              
              var operationIdValue = valueValue['operationId'];
              if (operationIdValue !== null && operationIdValue !== undefined) {
                var operationIdInstance = operationIdValue;
                eventDataInstance.operationId = operationIdInstance;
              }
              
              var operationNameValue = valueValue['operationName'];
              if (operationNameValue !== null && operationNameValue !== undefined) {
                var operationNameInstance = {};
                eventDataInstance.operationName = operationNameInstance;
                
                var valueValue6 = operationNameValue['value'];
                if (valueValue6 !== null && valueValue6 !== undefined) {
                  var valueInstance5 = valueValue6;
                  operationNameInstance.value = valueInstance5;
                }
                
                var localizedValueValue5 = operationNameValue['localizedValue'];
                if (localizedValueValue5 !== null && localizedValueValue5 !== undefined) {
                  var localizedValueInstance5 = localizedValueValue5;
                  operationNameInstance.localizedValue = localizedValueInstance5;
                }
              }
              
              var propertiesSequenceElement = valueValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property2 in propertiesSequenceElement) {
                  var propertiesKey = property2;
                  var propertiesValue = propertiesSequenceElement[property2];
                  eventDataInstance.properties[propertiesKey] = propertiesValue;
                }
              }
              
              var statusValue = valueValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = {};
                eventDataInstance.status = statusInstance;
                
                var valueValue7 = statusValue['value'];
                if (valueValue7 !== null && valueValue7 !== undefined) {
                  var valueInstance6 = valueValue7;
                  statusInstance.value = valueInstance6;
                }
                
                var localizedValueValue6 = statusValue['localizedValue'];
                if (localizedValueValue6 !== null && localizedValueValue6 !== undefined) {
                  var localizedValueInstance6 = localizedValueValue6;
                  statusInstance.localizedValue = localizedValueInstance6;
                }
              }
              
              var subStatusValue = valueValue['subStatus'];
              if (subStatusValue !== null && subStatusValue !== undefined) {
                var subStatusInstance = {};
                eventDataInstance.subStatus = subStatusInstance;
                
                var valueValue8 = subStatusValue['value'];
                if (valueValue8 !== null && valueValue8 !== undefined) {
                  var valueInstance7 = valueValue8;
                  subStatusInstance.value = valueInstance7;
                }
                
                var localizedValueValue7 = subStatusValue['localizedValue'];
                if (localizedValueValue7 !== null && localizedValueValue7 !== undefined) {
                  var localizedValueInstance7 = localizedValueValue7;
                  subStatusInstance.localizedValue = localizedValueInstance7;
                }
              }
              
              var eventTimestampValue = valueValue['eventTimestamp'];
              if (eventTimestampValue !== null && eventTimestampValue !== undefined) {
                var eventTimestampInstance = eventTimestampValue;
                eventDataInstance.eventTimestamp = eventTimestampInstance;
              }
              
              var submissionTimestampValue = valueValue['submissionTimestamp'];
              if (submissionTimestampValue !== null && submissionTimestampValue !== undefined) {
                var submissionTimestampInstance = submissionTimestampValue;
                eventDataInstance.submissionTimestamp = submissionTimestampInstance;
              }
              
              var subscriptionIdValue = valueValue['subscriptionId'];
              if (subscriptionIdValue !== null && subscriptionIdValue !== undefined) {
                var subscriptionIdInstance = subscriptionIdValue;
                eventDataInstance.subscriptionId = subscriptionIdInstance;
              }
              
              var tenantIdValue = valueValue['tenantId'];
              if (tenantIdValue !== null && tenantIdValue !== undefined) {
                var tenantIdInstance = tenantIdValue;
                eventDataInstance.tenantId = tenantIdInstance;
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            eventDataCollectionInstance.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Tenant Digest Event Next operation lists the next set of
   * tenant-level digest events.
   * 
   * @param {string} nextLink The next link
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EventOperations.prototype.listTenantDigestEventsNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    
    // 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 eventDataCollectionInstance = { value: [] };
          result.eventDataCollection = eventDataCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var eventDataInstance = { claims: {}, properties: {} };
              eventDataCollectionInstance.value.push(eventDataInstance);
              
              var authorizationValue = valueValue['authorization'];
              if (authorizationValue !== null && authorizationValue !== undefined) {
                var authorizationInstance = {};
                eventDataInstance.authorization = authorizationInstance;
                
                var actionValue = authorizationValue['action'];
                if (actionValue !== null && actionValue !== undefined) {
                  var actionInstance = actionValue;
                  authorizationInstance.action = actionInstance;
                }
                
                var conditionValue = authorizationValue['condition'];
                if (conditionValue !== null && conditionValue !== undefined) {
                  var conditionInstance = conditionValue;
                  authorizationInstance.condition = conditionInstance;
                }
                
                var roleValue = authorizationValue['role'];
                if (roleValue !== null && roleValue !== undefined) {
                  var roleInstance = roleValue;
                  authorizationInstance.role = roleInstance;
                }
                
                var scopeValue = authorizationValue['scope'];
                if (scopeValue !== null && scopeValue !== undefined) {
                  var scopeInstance = scopeValue;
                  authorizationInstance.scope = scopeInstance;
                }
              }
              
              var channelsValue = valueValue['channels'];
              if (channelsValue !== null && channelsValue !== undefined) {
                var channelsInstance = channelsValue;
                eventDataInstance.eventChannels = channelsInstance;
              }
              
              var claimsSequenceElement = valueValue['claims'];
              if (claimsSequenceElement !== null && claimsSequenceElement !== undefined) {
                for (var property in claimsSequenceElement) {
                  var claimsKey = property;
                  var claimsValue = claimsSequenceElement[property];
                  eventDataInstance.claims[claimsKey] = claimsValue;
                }
              }
              
              var callerValue = valueValue['caller'];
              if (callerValue !== null && callerValue !== undefined) {
                var callerInstance = callerValue;
                eventDataInstance.caller = callerInstance;
              }
              
              var descriptionValue = valueValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                eventDataInstance.description = descriptionInstance;
              }
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                eventDataInstance.id = idInstance;
              }
              
              var eventDataIdValue = valueValue['eventDataId'];
              if (eventDataIdValue !== null && eventDataIdValue !== undefined) {
                var eventDataIdInstance = eventDataIdValue;
                eventDataInstance.eventDataId = eventDataIdInstance;
              }
              
              var correlationIdValue = valueValue['correlationId'];
              if (correlationIdValue !== null && correlationIdValue !== undefined) {
                var correlationIdInstance = correlationIdValue;
                eventDataInstance.correlationId = correlationIdInstance;
              }
              
              var eventNameValue = valueValue['eventName'];
              if (eventNameValue !== null && eventNameValue !== undefined) {
                var eventNameInstance = {};
                eventDataInstance.eventName = eventNameInstance;
                
                var valueValue2 = eventNameValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  eventNameInstance.value = valueInstance;
                }
                
                var localizedValueValue = eventNameValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  eventNameInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var categoryValue = valueValue['category'];
              if (categoryValue !== null && categoryValue !== undefined) {
                var categoryInstance = {};
                eventDataInstance.category = categoryInstance;
                
                var valueValue3 = categoryValue['value'];
                if (valueValue3 !== null && valueValue3 !== undefined) {
                  var valueInstance2 = valueValue3;
                  categoryInstance.value = valueInstance2;
                }
                
                var localizedValueValue2 = categoryValue['localizedValue'];
                if (localizedValueValue2 !== null && localizedValueValue2 !== undefined) {
                  var localizedValueInstance2 = localizedValueValue2;
                  categoryInstance.localizedValue = localizedValueInstance2;
                }
              }
              
              var httpRequestValue = valueValue['httpRequest'];
              if (httpRequestValue !== null && httpRequestValue !== undefined) {
                var httpRequestInstance = {};
                eventDataInstance.httpRequest = httpRequestInstance;
                
                var clientRequestIdValue = httpRequestValue['clientRequestId'];
                if (clientRequestIdValue !== null && clientRequestIdValue !== undefined) {
                  var clientRequestIdInstance = clientRequestIdValue;
                  httpRequestInstance.clientRequestId = clientRequestIdInstance;
                }
                
                var clientIpAddressValue = httpRequestValue['clientIpAddress'];
                if (clientIpAddressValue !== null && clientIpAddressValue !== undefined) {
                  var clientIpAddressInstance = clientIpAddressValue;
                  httpRequestInstance.clientIpAddress = clientIpAddressInstance;
                }
                
                var methodValue = httpRequestValue['method'];
                if (methodValue !== null && methodValue !== undefined) {
                  var methodInstance = methodValue;
                  httpRequestInstance.method = methodInstance;
                }
                
                var uriValue = httpRequestValue['uri'];
                if (uriValue !== null && uriValue !== undefined) {
                  var uriInstance = uriValue;
                  httpRequestInstance.uri = uriInstance;
                }
              }
              
              var levelValue = valueValue['level'];
              if (levelValue !== null && levelValue !== undefined) {
                var levelInstance = levelValue;
                eventDataInstance.level = levelInstance;
              }
              
              var resourceGroupNameValue = valueValue['resourceGroupName'];
              if (resourceGroupNameValue !== null && resourceGroupNameValue !== undefined) {
                var resourceGroupNameInstance = resourceGroupNameValue;
                eventDataInstance.resourceGroupName = resourceGroupNameInstance;
              }
              
              var resourceProviderNameValue = valueValue['resourceProviderName'];
              if (resourceProviderNameValue !== null && resourceProviderNameValue !== undefined) {
                var resourceProviderNameInstance = {};
                eventDataInstance.resourceProviderName = resourceProviderNameInstance;
                
                var valueValue4 = resourceProviderNameValue['value'];
                if (valueValue4 !== null && valueValue4 !== undefined) {
                  var valueInstance3 = valueValue4;
                  resourceProviderNameInstance.value = valueInstance3;
                }
                
                var localizedValueValue3 = resourceProviderNameValue['localizedValue'];
                if (localizedValueValue3 !== null && localizedValueValue3 !== undefined) {
                  var localizedValueInstance3 = localizedValueValue3;
                  resourceProviderNameInstance.localizedValue = localizedValueInstance3;
                }
              }
              
              var resourceIdValue = valueValue['resourceId'];
              if (resourceIdValue !== null && resourceIdValue !== undefined) {
                var resourceIdInstance = resourceIdValue;
                eventDataInstance.resourceId = resourceIdInstance;
              }
              
              var resourceTypeValue = valueValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = {};
                eventDataInstance.resourceType = resourceTypeInstance;
                
                var valueValue5 = resourceTypeValue['value'];
                if (valueValue5 !== null && valueValue5 !== undefined) {
                  var valueInstance4 = valueValue5;
                  resourceTypeInstance.value = valueInstance4;
                }
                
                var localizedValueValue4 = resourceTypeValue['localizedValue'];
                if (localizedValueValue4 !== null && localizedValueValue4 !== undefined) {
                  var localizedValueInstance4 = localizedValueValue4;
                  resourceTypeInstance.localizedValue = localizedValueInstance4;
                }
              }
              
              var operationIdValue = valueValue['operationId'];
              if (operationIdValue !== null && operationIdValue !== undefined) {
                var operationIdInstance = operationIdValue;
                eventDataInstance.operationId = operationIdInstance;
              }
              
              var operationNameValue = valueValue['operationName'];
              if (operationNameValue !== null && operationNameValue !== undefined) {
                var operationNameInstance = {};
                eventDataInstance.operationName = operationNameInstance;
                
                var valueValue6 = operationNameValue['value'];
                if (valueValue6 !== null && valueValue6 !== undefined) {
                  var valueInstance5 = valueValue6;
                  operationNameInstance.value = valueInstance5;
                }
                
                var localizedValueValue5 = operationNameValue['localizedValue'];
                if (localizedValueValue5 !== null && localizedValueValue5 !== undefined) {
                  var localizedValueInstance5 = localizedValueValue5;
                  operationNameInstance.localizedValue = localizedValueInstance5;
                }
              }
              
              var propertiesSequenceElement = valueValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property2 in propertiesSequenceElement) {
                  var propertiesKey = property2;
                  var propertiesValue = propertiesSequenceElement[property2];
                  eventDataInstance.properties[propertiesKey] = propertiesValue;
                }
              }
              
              var statusValue = valueValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = {};
                eventDataInstance.status = statusInstance;
                
                var valueValue7 = statusValue['value'];
                if (valueValue7 !== null && valueValue7 !== undefined) {
                  var valueInstance6 = valueValue7;
                  statusInstance.value = valueInstance6;
                }
                
                var localizedValueValue6 = statusValue['localizedValue'];
                if (localizedValueValue6 !== null && localizedValueValue6 !== undefined) {
                  var localizedValueInstance6 = localizedValueValue6;
                  statusInstance.localizedValue = localizedValueInstance6;
                }
              }
              
              var subStatusValue = valueValue['subStatus'];
              if (subStatusValue !== null && subStatusValue !== undefined) {
                var subStatusInstance = {};
                eventDataInstance.subStatus = subStatusInstance;
                
                var valueValue8 = subStatusValue['value'];
                if (valueValue8 !== null && valueValue8 !== undefined) {
                  var valueInstance7 = valueValue8;
                  subStatusInstance.value = valueInstance7;
                }
                
                var localizedValueValue7 = subStatusValue['localizedValue'];
                if (localizedValueValue7 !== null && localizedValueValue7 !== undefined) {
                  var localizedValueInstance7 = localizedValueValue7;
                  subStatusInstance.localizedValue = localizedValueInstance7;
                }
              }
              
              var eventTimestampValue = valueValue['eventTimestamp'];
              if (eventTimestampValue !== null && eventTimestampValue !== undefined) {
                var eventTimestampInstance = eventTimestampValue;
                eventDataInstance.eventTimestamp = eventTimestampInstance;
              }
              
              var submissionTimestampValue = valueValue['submissionTimestamp'];
              if (submissionTimestampValue !== null && submissionTimestampValue !== undefined) {
                var submissionTimestampInstance = submissionTimestampValue;
                eventDataInstance.submissionTimestamp = submissionTimestampInstance;
              }
              
              var subscriptionIdValue = valueValue['subscriptionId'];
              if (subscriptionIdValue !== null && subscriptionIdValue !== undefined) {
                var subscriptionIdInstance = subscriptionIdValue;
                eventDataInstance.subscriptionId = subscriptionIdInstance;
              }
              
              var tenantIdValue = valueValue['tenantId'];
              if (tenantIdValue !== null && tenantIdValue !== undefined) {
                var tenantIdInstance = tenantIdValue;
                eventDataInstance.tenantId = tenantIdInstance;
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            eventDataCollectionInstance.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The list tenant event values operation lists the tenant events.
   * 
   * @param {string} filterString The filter string should be generated using
   * Microsoft.WindowsAzure.Common.OData.FilterStringHere is an example:var
   * filterString = FilterString.Generate<GetCountSummaryParameters> (p =>
   * (p.StartTime == startTime) && p.EndTime == endTime);
   * 
   * @param {string} [selectedProperties] The list of property names to be
   * returned. You can save bandwidth by selecting only the properties you
   * need.Here is an example:string selectedProperties = "EventDataId,
   * EventTimestamp, ResourceUri"
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EventOperations.prototype.listTenantEvents = function(filterString, selectedProperties, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (filterString === null || filterString === undefined) {
      return callback(new Error('filterString cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/providers/microsoft.insights/eventtypes/management/values';
    var queryParameters = [];
    queryParameters.push('api-version=2015-04-01');
    var odataFilter = [];
    odataFilter.push(encodeURIComponent(filterString));
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(null));
    }
    if (selectedProperties !== null && selectedProperties !== undefined) {
      queryParameters.push('$select=' + encodeURIComponent(selectedProperties));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    
    // 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 eventDataCollectionInstance = { value: [] };
          result.eventDataCollection = eventDataCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var eventDataInstance = { claims: {}, properties: {} };
              eventDataCollectionInstance.value.push(eventDataInstance);
              
              var authorizationValue = valueValue['authorization'];
              if (authorizationValue !== null && authorizationValue !== undefined) {
                var authorizationInstance = {};
                eventDataInstance.authorization = authorizationInstance;
                
                var actionValue = authorizationValue['action'];
                if (actionValue !== null && actionValue !== undefined) {
                  var actionInstance = actionValue;
                  authorizationInstance.action = actionInstance;
                }
                
                var conditionValue = authorizationValue['condition'];
                if (conditionValue !== null && conditionValue !== undefined) {
                  var conditionInstance = conditionValue;
                  authorizationInstance.condition = conditionInstance;
                }
                
                var roleValue = authorizationValue['role'];
                if (roleValue !== null && roleValue !== undefined) {
                  var roleInstance = roleValue;
                  authorizationInstance.role = roleInstance;
                }
                
                var scopeValue = authorizationValue['scope'];
                if (scopeValue !== null && scopeValue !== undefined) {
                  var scopeInstance = scopeValue;
                  authorizationInstance.scope = scopeInstance;
                }
              }
              
              var channelsValue = valueValue['channels'];
              if (channelsValue !== null && channelsValue !== undefined) {
                var channelsInstance = channelsValue;
                eventDataInstance.eventChannels = channelsInstance;
              }
              
              var claimsSequenceElement = valueValue['claims'];
              if (claimsSequenceElement !== null && claimsSequenceElement !== undefined) {
                for (var property in claimsSequenceElement) {
                  var claimsKey = property;
                  var claimsValue = claimsSequenceElement[property];
                  eventDataInstance.claims[claimsKey] = claimsValue;
                }
              }
              
              var callerValue = valueValue['caller'];
              if (callerValue !== null && callerValue !== undefined) {
                var callerInstance = callerValue;
                eventDataInstance.caller = callerInstance;
              }
              
              var descriptionValue = valueValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                eventDataInstance.description = descriptionInstance;
              }
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                eventDataInstance.id = idInstance;
              }
              
              var eventDataIdValue = valueValue['eventDataId'];
              if (eventDataIdValue !== null && eventDataIdValue !== undefined) {
                var eventDataIdInstance = eventDataIdValue;
                eventDataInstance.eventDataId = eventDataIdInstance;
              }
              
              var correlationIdValue = valueValue['correlationId'];
              if (correlationIdValue !== null && correlationIdValue !== undefined) {
                var correlationIdInstance = correlationIdValue;
                eventDataInstance.correlationId = correlationIdInstance;
              }
              
              var eventNameValue = valueValue['eventName'];
              if (eventNameValue !== null && eventNameValue !== undefined) {
                var eventNameInstance = {};
                eventDataInstance.eventName = eventNameInstance;
                
                var valueValue2 = eventNameValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  eventNameInstance.value = valueInstance;
                }
                
                var localizedValueValue = eventNameValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  eventNameInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var categoryValue = valueValue['category'];
              if (categoryValue !== null && categoryValue !== undefined) {
                var categoryInstance = {};
                eventDataInstance.category = categoryInstance;
                
                var valueValue3 = categoryValue['value'];
                if (valueValue3 !== null && valueValue3 !== undefined) {
                  var valueInstance2 = valueValue3;
                  categoryInstance.value = valueInstance2;
                }
                
                var localizedValueValue2 = categoryValue['localizedValue'];
                if (localizedValueValue2 !== null && localizedValueValue2 !== undefined) {
                  var localizedValueInstance2 = localizedValueValue2;
                  categoryInstance.localizedValue = localizedValueInstance2;
                }
              }
              
              var httpRequestValue = valueValue['httpRequest'];
              if (httpRequestValue !== null && httpRequestValue !== undefined) {
                var httpRequestInstance = {};
                eventDataInstance.httpRequest = httpRequestInstance;
                
                var clientRequestIdValue = httpRequestValue['clientRequestId'];
                if (clientRequestIdValue !== null && clientRequestIdValue !== undefined) {
                  var clientRequestIdInstance = clientRequestIdValue;
                  httpRequestInstance.clientRequestId = clientRequestIdInstance;
                }
                
                var clientIpAddressValue = httpRequestValue['clientIpAddress'];
                if (clientIpAddressValue !== null && clientIpAddressValue !== undefined) {
                  var clientIpAddressInstance = clientIpAddressValue;
                  httpRequestInstance.clientIpAddress = clientIpAddressInstance;
                }
                
                var methodValue = httpRequestValue['method'];
                if (methodValue !== null && methodValue !== undefined) {
                  var methodInstance = methodValue;
                  httpRequestInstance.method = methodInstance;
                }
                
                var uriValue = httpRequestValue['uri'];
                if (uriValue !== null && uriValue !== undefined) {
                  var uriInstance = uriValue;
                  httpRequestInstance.uri = uriInstance;
                }
              }
              
              var levelValue = valueValue['level'];
              if (levelValue !== null && levelValue !== undefined) {
                var levelInstance = levelValue;
                eventDataInstance.level = levelInstance;
              }
              
              var resourceGroupNameValue = valueValue['resourceGroupName'];
              if (resourceGroupNameValue !== null && resourceGroupNameValue !== undefined) {
                var resourceGroupNameInstance = resourceGroupNameValue;
                eventDataInstance.resourceGroupName = resourceGroupNameInstance;
              }
              
              var resourceProviderNameValue = valueValue['resourceProviderName'];
              if (resourceProviderNameValue !== null && resourceProviderNameValue !== undefined) {
                var resourceProviderNameInstance = {};
                eventDataInstance.resourceProviderName = resourceProviderNameInstance;
                
                var valueValue4 = resourceProviderNameValue['value'];
                if (valueValue4 !== null && valueValue4 !== undefined) {
                  var valueInstance3 = valueValue4;
                  resourceProviderNameInstance.value = valueInstance3;
                }
                
                var localizedValueValue3 = resourceProviderNameValue['localizedValue'];
                if (localizedValueValue3 !== null && localizedValueValue3 !== undefined) {
                  var localizedValueInstance3 = localizedValueValue3;
                  resourceProviderNameInstance.localizedValue = localizedValueInstance3;
                }
              }
              
              var resourceIdValue = valueValue['resourceId'];
              if (resourceIdValue !== null && resourceIdValue !== undefined) {
                var resourceIdInstance = resourceIdValue;
                eventDataInstance.resourceId = resourceIdInstance;
              }
              
              var resourceTypeValue = valueValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = {};
                eventDataInstance.resourceType = resourceTypeInstance;
                
                var valueValue5 = resourceTypeValue['value'];
                if (valueValue5 !== null && valueValue5 !== undefined) {
                  var valueInstance4 = valueValue5;
                  resourceTypeInstance.value = valueInstance4;
                }
                
                var localizedValueValue4 = resourceTypeValue['localizedValue'];
                if (localizedValueValue4 !== null && localizedValueValue4 !== undefined) {
                  var localizedValueInstance4 = localizedValueValue4;
                  resourceTypeInstance.localizedValue = localizedValueInstance4;
                }
              }
              
              var operationIdValue = valueValue['operationId'];
              if (operationIdValue !== null && operationIdValue !== undefined) {
                var operationIdInstance = operationIdValue;
                eventDataInstance.operationId = operationIdInstance;
              }
              
              var operationNameValue = valueValue['operationName'];
              if (operationNameValue !== null && operationNameValue !== undefined) {
                var operationNameInstance = {};
                eventDataInstance.operationName = operationNameInstance;
                
                var valueValue6 = operationNameValue['value'];
                if (valueValue6 !== null && valueValue6 !== undefined) {
                  var valueInstance5 = valueValue6;
                  operationNameInstance.value = valueInstance5;
                }
                
                var localizedValueValue5 = operationNameValue['localizedValue'];
                if (localizedValueValue5 !== null && localizedValueValue5 !== undefined) {
                  var localizedValueInstance5 = localizedValueValue5;
                  operationNameInstance.localizedValue = localizedValueInstance5;
                }
              }
              
              var propertiesSequenceElement = valueValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property2 in propertiesSequenceElement) {
                  var propertiesKey = property2;
                  var propertiesValue = propertiesSequenceElement[property2];
                  eventDataInstance.properties[propertiesKey] = propertiesValue;
                }
              }
              
              var statusValue = valueValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = {};
                eventDataInstance.status = statusInstance;
                
                var valueValue7 = statusValue['value'];
                if (valueValue7 !== null && valueValue7 !== undefined) {
                  var valueInstance6 = valueValue7;
                  statusInstance.value = valueInstance6;
                }
                
                var localizedValueValue6 = statusValue['localizedValue'];
                if (localizedValueValue6 !== null && localizedValueValue6 !== undefined) {
                  var localizedValueInstance6 = localizedValueValue6;
                  statusInstance.localizedValue = localizedValueInstance6;
                }
              }
              
              var subStatusValue = valueValue['subStatus'];
              if (subStatusValue !== null && subStatusValue !== undefined) {
                var subStatusInstance = {};
                eventDataInstance.subStatus = subStatusInstance;
                
                var valueValue8 = subStatusValue['value'];
                if (valueValue8 !== null && valueValue8 !== undefined) {
                  var valueInstance7 = valueValue8;
                  subStatusInstance.value = valueInstance7;
                }
                
                var localizedValueValue7 = subStatusValue['localizedValue'];
                if (localizedValueValue7 !== null && localizedValueValue7 !== undefined) {
                  var localizedValueInstance7 = localizedValueValue7;
                  subStatusInstance.localizedValue = localizedValueInstance7;
                }
              }
              
              var eventTimestampValue = valueValue['eventTimestamp'];
              if (eventTimestampValue !== null && eventTimestampValue !== undefined) {
                var eventTimestampInstance = eventTimestampValue;
                eventDataInstance.eventTimestamp = eventTimestampInstance;
              }
              
              var submissionTimestampValue = valueValue['submissionTimestamp'];
              if (submissionTimestampValue !== null && submissionTimestampValue !== undefined) {
                var submissionTimestampInstance = submissionTimestampValue;
                eventDataInstance.submissionTimestamp = submissionTimestampInstance;
              }
              
              var subscriptionIdValue = valueValue['subscriptionId'];
              if (subscriptionIdValue !== null && subscriptionIdValue !== undefined) {
                var subscriptionIdInstance = subscriptionIdValue;
                eventDataInstance.subscriptionId = subscriptionIdInstance;
              }
              
              var tenantIdValue = valueValue['tenantId'];
              if (tenantIdValue !== null && tenantIdValue !== undefined) {
                var tenantIdInstance = tenantIdValue;
                eventDataInstance.tenantId = tenantIdInstance;
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            eventDataCollectionInstance.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List Event Next operation lists the next set of events.
   * 
   * @param {string} nextLink The next link works as a continuation token when
   * all of the events are not returned in the response and a second call is
   * required
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EventOperations.prototype.listTenantEventsNext = function(nextLink, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (nextLink === null || nextLink === undefined) {
      return callback(new Error('nextLink cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + nextLink;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    
    // 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 eventDataCollectionInstance = { value: [] };
          result.eventDataCollection = eventDataCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var eventDataInstance = { claims: {}, properties: {} };
              eventDataCollectionInstance.value.push(eventDataInstance);
              
              var authorizationValue = valueValue['authorization'];
              if (authorizationValue !== null && authorizationValue !== undefined) {
                var authorizationInstance = {};
                eventDataInstance.authorization = authorizationInstance;
                
                var actionValue = authorizationValue['action'];
                if (actionValue !== null && actionValue !== undefined) {
                  var actionInstance = actionValue;
                  authorizationInstance.action = actionInstance;
                }
                
                var conditionValue = authorizationValue['condition'];
                if (conditionValue !== null && conditionValue !== undefined) {
                  var conditionInstance = conditionValue;
                  authorizationInstance.condition = conditionInstance;
                }
                
                var roleValue = authorizationValue['role'];
                if (roleValue !== null && roleValue !== undefined) {
                  var roleInstance = roleValue;
                  authorizationInstance.role = roleInstance;
                }
                
                var scopeValue = authorizationValue['scope'];
                if (scopeValue !== null && scopeValue !== undefined) {
                  var scopeInstance = scopeValue;
                  authorizationInstance.scope = scopeInstance;
                }
              }
              
              var channelsValue = valueValue['channels'];
              if (channelsValue !== null && channelsValue !== undefined) {
                var channelsInstance = channelsValue;
                eventDataInstance.eventChannels = channelsInstance;
              }
              
              var claimsSequenceElement = valueValue['claims'];
              if (claimsSequenceElement !== null && claimsSequenceElement !== undefined) {
                for (var property in claimsSequenceElement) {
                  var claimsKey = property;
                  var claimsValue = claimsSequenceElement[property];
                  eventDataInstance.claims[claimsKey] = claimsValue;
                }
              }
              
              var callerValue = valueValue['caller'];
              if (callerValue !== null && callerValue !== undefined) {
                var callerInstance = callerValue;
                eventDataInstance.caller = callerInstance;
              }
              
              var descriptionValue = valueValue['description'];
              if (descriptionValue !== null && descriptionValue !== undefined) {
                var descriptionInstance = descriptionValue;
                eventDataInstance.description = descriptionInstance;
              }
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                eventDataInstance.id = idInstance;
              }
              
              var eventDataIdValue = valueValue['eventDataId'];
              if (eventDataIdValue !== null && eventDataIdValue !== undefined) {
                var eventDataIdInstance = eventDataIdValue;
                eventDataInstance.eventDataId = eventDataIdInstance;
              }
              
              var correlationIdValue = valueValue['correlationId'];
              if (correlationIdValue !== null && correlationIdValue !== undefined) {
                var correlationIdInstance = correlationIdValue;
                eventDataInstance.correlationId = correlationIdInstance;
              }
              
              var eventNameValue = valueValue['eventName'];
              if (eventNameValue !== null && eventNameValue !== undefined) {
                var eventNameInstance = {};
                eventDataInstance.eventName = eventNameInstance;
                
                var valueValue2 = eventNameValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  eventNameInstance.value = valueInstance;
                }
                
                var localizedValueValue = eventNameValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  eventNameInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var categoryValue = valueValue['category'];
              if (categoryValue !== null && categoryValue !== undefined) {
                var categoryInstance = {};
                eventDataInstance.category = categoryInstance;
                
                var valueValue3 = categoryValue['value'];
                if (valueValue3 !== null && valueValue3 !== undefined) {
                  var valueInstance2 = valueValue3;
                  categoryInstance.value = valueInstance2;
                }
                
                var localizedValueValue2 = categoryValue['localizedValue'];
                if (localizedValueValue2 !== null && localizedValueValue2 !== undefined) {
                  var localizedValueInstance2 = localizedValueValue2;
                  categoryInstance.localizedValue = localizedValueInstance2;
                }
              }
              
              var httpRequestValue = valueValue['httpRequest'];
              if (httpRequestValue !== null && httpRequestValue !== undefined) {
                var httpRequestInstance = {};
                eventDataInstance.httpRequest = httpRequestInstance;
                
                var clientRequestIdValue = httpRequestValue['clientRequestId'];
                if (clientRequestIdValue !== null && clientRequestIdValue !== undefined) {
                  var clientRequestIdInstance = clientRequestIdValue;
                  httpRequestInstance.clientRequestId = clientRequestIdInstance;
                }
                
                var clientIpAddressValue = httpRequestValue['clientIpAddress'];
                if (clientIpAddressValue !== null && clientIpAddressValue !== undefined) {
                  var clientIpAddressInstance = clientIpAddressValue;
                  httpRequestInstance.clientIpAddress = clientIpAddressInstance;
                }
                
                var methodValue = httpRequestValue['method'];
                if (methodValue !== null && methodValue !== undefined) {
                  var methodInstance = methodValue;
                  httpRequestInstance.method = methodInstance;
                }
                
                var uriValue = httpRequestValue['uri'];
                if (uriValue !== null && uriValue !== undefined) {
                  var uriInstance = uriValue;
                  httpRequestInstance.uri = uriInstance;
                }
              }
              
              var levelValue = valueValue['level'];
              if (levelValue !== null && levelValue !== undefined) {
                var levelInstance = levelValue;
                eventDataInstance.level = levelInstance;
              }
              
              var resourceGroupNameValue = valueValue['resourceGroupName'];
              if (resourceGroupNameValue !== null && resourceGroupNameValue !== undefined) {
                var resourceGroupNameInstance = resourceGroupNameValue;
                eventDataInstance.resourceGroupName = resourceGroupNameInstance;
              }
              
              var resourceProviderNameValue = valueValue['resourceProviderName'];
              if (resourceProviderNameValue !== null && resourceProviderNameValue !== undefined) {
                var resourceProviderNameInstance = {};
                eventDataInstance.resourceProviderName = resourceProviderNameInstance;
                
                var valueValue4 = resourceProviderNameValue['value'];
                if (valueValue4 !== null && valueValue4 !== undefined) {
                  var valueInstance3 = valueValue4;
                  resourceProviderNameInstance.value = valueInstance3;
                }
                
                var localizedValueValue3 = resourceProviderNameValue['localizedValue'];
                if (localizedValueValue3 !== null && localizedValueValue3 !== undefined) {
                  var localizedValueInstance3 = localizedValueValue3;
                  resourceProviderNameInstance.localizedValue = localizedValueInstance3;
                }
              }
              
              var resourceIdValue = valueValue['resourceId'];
              if (resourceIdValue !== null && resourceIdValue !== undefined) {
                var resourceIdInstance = resourceIdValue;
                eventDataInstance.resourceId = resourceIdInstance;
              }
              
              var resourceTypeValue = valueValue['resourceType'];
              if (resourceTypeValue !== null && resourceTypeValue !== undefined) {
                var resourceTypeInstance = {};
                eventDataInstance.resourceType = resourceTypeInstance;
                
                var valueValue5 = resourceTypeValue['value'];
                if (valueValue5 !== null && valueValue5 !== undefined) {
                  var valueInstance4 = valueValue5;
                  resourceTypeInstance.value = valueInstance4;
                }
                
                var localizedValueValue4 = resourceTypeValue['localizedValue'];
                if (localizedValueValue4 !== null && localizedValueValue4 !== undefined) {
                  var localizedValueInstance4 = localizedValueValue4;
                  resourceTypeInstance.localizedValue = localizedValueInstance4;
                }
              }
              
              var operationIdValue = valueValue['operationId'];
              if (operationIdValue !== null && operationIdValue !== undefined) {
                var operationIdInstance = operationIdValue;
                eventDataInstance.operationId = operationIdInstance;
              }
              
              var operationNameValue = valueValue['operationName'];
              if (operationNameValue !== null && operationNameValue !== undefined) {
                var operationNameInstance = {};
                eventDataInstance.operationName = operationNameInstance;
                
                var valueValue6 = operationNameValue['value'];
                if (valueValue6 !== null && valueValue6 !== undefined) {
                  var valueInstance5 = valueValue6;
                  operationNameInstance.value = valueInstance5;
                }
                
                var localizedValueValue5 = operationNameValue['localizedValue'];
                if (localizedValueValue5 !== null && localizedValueValue5 !== undefined) {
                  var localizedValueInstance5 = localizedValueValue5;
                  operationNameInstance.localizedValue = localizedValueInstance5;
                }
              }
              
              var propertiesSequenceElement = valueValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property2 in propertiesSequenceElement) {
                  var propertiesKey = property2;
                  var propertiesValue = propertiesSequenceElement[property2];
                  eventDataInstance.properties[propertiesKey] = propertiesValue;
                }
              }
              
              var statusValue = valueValue['status'];
              if (statusValue !== null && statusValue !== undefined) {
                var statusInstance = {};
                eventDataInstance.status = statusInstance;
                
                var valueValue7 = statusValue['value'];
                if (valueValue7 !== null && valueValue7 !== undefined) {
                  var valueInstance6 = valueValue7;
                  statusInstance.value = valueInstance6;
                }
                
                var localizedValueValue6 = statusValue['localizedValue'];
                if (localizedValueValue6 !== null && localizedValueValue6 !== undefined) {
                  var localizedValueInstance6 = localizedValueValue6;
                  statusInstance.localizedValue = localizedValueInstance6;
                }
              }
              
              var subStatusValue = valueValue['subStatus'];
              if (subStatusValue !== null && subStatusValue !== undefined) {
                var subStatusInstance = {};
                eventDataInstance.subStatus = subStatusInstance;
                
                var valueValue8 = subStatusValue['value'];
                if (valueValue8 !== null && valueValue8 !== undefined) {
                  var valueInstance7 = valueValue8;
                  subStatusInstance.value = valueInstance7;
                }
                
                var localizedValueValue7 = subStatusValue['localizedValue'];
                if (localizedValueValue7 !== null && localizedValueValue7 !== undefined) {
                  var localizedValueInstance7 = localizedValueValue7;
                  subStatusInstance.localizedValue = localizedValueInstance7;
                }
              }
              
              var eventTimestampValue = valueValue['eventTimestamp'];
              if (eventTimestampValue !== null && eventTimestampValue !== undefined) {
                var eventTimestampInstance = eventTimestampValue;
                eventDataInstance.eventTimestamp = eventTimestampInstance;
              }
              
              var submissionTimestampValue = valueValue['submissionTimestamp'];
              if (submissionTimestampValue !== null && submissionTimestampValue !== undefined) {
                var submissionTimestampInstance = submissionTimestampValue;
                eventDataInstance.submissionTimestamp = submissionTimestampInstance;
              }
              
              var subscriptionIdValue = valueValue['subscriptionId'];
              if (subscriptionIdValue !== null && subscriptionIdValue !== undefined) {
                var subscriptionIdInstance = subscriptionIdValue;
                eventDataInstance.subscriptionId = subscriptionIdInstance;
              }
              
              var tenantIdValue = valueValue['tenantId'];
              if (tenantIdValue !== null && tenantIdValue !== undefined) {
                var tenantIdInstance = tenantIdValue;
                eventDataInstance.tenantId = tenantIdInstance;
              }
            }
          }
          
          var nextLinkValue = responseDoc['nextLink'];
          if (nextLinkValue !== null && nextLinkValue !== undefined) {
            var nextLinkInstance = nextLinkValue;
            eventDataCollectionInstance.nextLink = nextLinkInstance;
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return EventOperations;
})();

var LogDefinitionOperations = ( /** @lends LogDefinitionOperations */ function() {
  /**
   * @class
   * Operations for log definitions.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [InsightsClient] {@link InsightsClient~InsightsClient}.
   * See [logDefinitionOperations] {@link
   * InsightsClient~InsightsClient#logDefinitionOperations}.
   * Initializes a new instance of the LogDefinitionOperations class.
   * @constructor
   * 
   * @param {InsightsClient} client Reference to the service client.
   */
  function LogDefinitionOperations(client) {
    this.client = client;
  }
  
  /**
   * The List Log Definitions operation lists the log definitions for the
   * resource.
   * 
   * @param {string} resourceUri The resource identifier of the target resource
   * to get logs for.
   * 
   * @param {string} [filterString] An OData $filter expression that supports
   * querying by the name of the log definition. For example, "name.value eq
   * 'Percentage CPU'". Name is optional, meaning the expression may be "".
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  LogDefinitionOperations.prototype.getLogDefinitions = function(resourceUri, filterString, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceUri === null || resourceUri === undefined) {
      return callback(new Error('resourceUri cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(resourceUri);
    url2 = url2 + '/providers/microsoft.insights/logDefinitions';
    var queryParameters = [];
    queryParameters.push('api-version=2015-07-01');
    var odataFilter = [];
    if (filterString !== null && filterString !== undefined) {
      odataFilter.push(encodeURIComponent(filterString));
    }
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(null));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['x-ms-version'] = '2014-04-01';
    
    // 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 logDefinitionCollectionInstance = { value: [] };
          result.logDefinitionCollection = logDefinitionCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var logDefinitionInstance = {};
              logDefinitionCollectionInstance.value.push(logDefinitionInstance);
              
              var categoryValue = valueValue['category'];
              if (categoryValue !== null && categoryValue !== undefined) {
                var categoryInstance = {};
                logDefinitionInstance.category = categoryInstance;
                
                var valueValue2 = categoryValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  categoryInstance.value = valueInstance;
                }
                
                var localizedValueValue = categoryValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  categoryInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var resourceIdValue = valueValue['resourceId'];
              if (resourceIdValue !== null && resourceIdValue !== undefined) {
                var resourceIdInstance = resourceIdValue;
                logDefinitionInstance.resourceId = resourceIdInstance;
              }
              
              var retentionValue = valueValue['retention'];
              if (retentionValue !== null && retentionValue !== undefined) {
                var retentionInstance = moment.duration(retentionValue);
                logDefinitionInstance.retention = retentionInstance;
              }
              
              var blobLocationValue = valueValue['blobLocation'];
              if (blobLocationValue !== null && blobLocationValue !== undefined) {
                var blobLocationInstance = { blobInfo: [] };
                logDefinitionInstance.blobLocation = blobLocationInstance;
                
                var blobEndpointValue = blobLocationValue['blobEndpoint'];
                if (blobEndpointValue !== null && blobEndpointValue !== undefined) {
                  var blobEndpointInstance = blobEndpointValue;
                  blobLocationInstance.blobEndpoint = blobEndpointInstance;
                }
                
                var blobInfoArray = blobLocationValue['blobInfo'];
                if (blobInfoArray !== null && blobInfoArray !== undefined) {
                  for (var loweredIndex2 = 0; loweredIndex2 < blobInfoArray.length; loweredIndex2 = loweredIndex2 + 1) {
                    var blobInfoValue = blobInfoArray[loweredIndex2];
                    var blobInfoInstance = {};
                    blobLocationInstance.blobInfo.push(blobInfoInstance);
                    
                    var blobUriValue = blobInfoValue['blobUri'];
                    if (blobUriValue !== null && blobUriValue !== undefined) {
                      var blobUriInstance = blobUriValue;
                      blobInfoInstance.blobUri = blobUriInstance;
                    }
                    
                    var startTimeValue = blobInfoValue['startTime'];
                    if (startTimeValue !== null && startTimeValue !== undefined) {
                      var startTimeInstance = startTimeValue;
                      blobInfoInstance.startTime = startTimeInstance;
                    }
                    
                    var endTimeValue = blobInfoValue['endTime'];
                    if (endTimeValue !== null && endTimeValue !== undefined) {
                      var endTimeInstance = endTimeValue;
                      blobInfoInstance.endTime = endTimeInstance;
                    }
                    
                    var sasTokenValue = blobInfoValue['sasToken'];
                    if (sasTokenValue !== null && sasTokenValue !== undefined) {
                      var sasTokenInstance = sasTokenValue;
                      blobInfoInstance.sasToken = sasTokenInstance;
                    }
                  }
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return LogDefinitionOperations;
})();

var LogOperations = ( /** @lends LogOperations */ function() {
  /**
   * @class
   * Operations for logs.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [InsightsClient] {@link InsightsClient~InsightsClient}.
   * See [logOperations] {@link InsightsClient~InsightsClient#logOperations}.
   * Initializes a new instance of the LogOperations class.
   * @constructor
   * 
   * @param {InsightsClient} client Reference to the service client.
   */
  function LogOperations(client) {
    this.client = client;
  }
  
  /**
   * The List Log operation lists the logs for the resource.
   * 
   * @param {string} [resourceUri]
   * 
   * @param {string} [filterString]
   * 
   * @param {Array} [definitions]
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  LogOperations.prototype.getLogs = function(resourceUri, filterString, definitions, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/providers/microsoft.insights/logs';
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['x-ms-version'] = '2014-04-01';
    
    // 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 logCollectionInstance = { value: [] };
          result.logCollection = logCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var logInstance = { value: [] };
              logCollectionInstance.value.push(logInstance);
              
              var categoryValue = valueValue['category'];
              if (categoryValue !== null && categoryValue !== undefined) {
                var categoryInstance = {};
                logInstance.category = categoryInstance;
                
                var valueValue2 = categoryValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  categoryInstance.value = valueInstance;
                }
                
                var localizedValueValue = categoryValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  categoryInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var startTimeValue = valueValue['startTime'];
              if (startTimeValue !== null && startTimeValue !== undefined) {
                var startTimeInstance = startTimeValue;
                logInstance.startTime = startTimeInstance;
              }
              
              var endTimeValue = valueValue['endTime'];
              if (endTimeValue !== null && endTimeValue !== undefined) {
                var endTimeInstance = endTimeValue;
                logInstance.endTime = endTimeInstance;
              }
              
              var valueArray2 = valueValue['value'];
              if (valueArray2 !== null && valueArray2 !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < valueArray2.length; loweredIndex2 = loweredIndex2 + 1) {
                  var valueValue3 = valueArray2[loweredIndex2];
                  var logValueInstance = { properties: {} };
                  logInstance.value.push(logValueInstance);
                  
                  var timeValue = valueValue3['time'];
                  if (timeValue !== null && timeValue !== undefined) {
                    var timeInstance = timeValue;
                    logValueInstance.time = timeInstance;
                  }
                  
                  var resourceIdValue = valueValue3['resourceId'];
                  if (resourceIdValue !== null && resourceIdValue !== undefined) {
                    var resourceIdInstance = resourceIdValue;
                    logValueInstance.resourceId = resourceIdInstance;
                  }
                  
                  var operationNameValue = valueValue3['operationName'];
                  if (operationNameValue !== null && operationNameValue !== undefined) {
                    var operationNameInstance = operationNameValue;
                    logValueInstance.operationName = operationNameInstance;
                  }
                  
                  var operationVersionValue = valueValue3['operationVersion'];
                  if (operationVersionValue !== null && operationVersionValue !== undefined) {
                    var operationVersionInstance = operationVersionValue;
                    logValueInstance.operationVersion = operationVersionInstance;
                  }
                  
                  var categoryValue2 = valueValue3['category'];
                  if (categoryValue2 !== null && categoryValue2 !== undefined) {
                    var categoryInstance2 = categoryValue2;
                    logValueInstance.category = categoryInstance2;
                  }
                  
                  var resultTypeValue = valueValue3['resultType'];
                  if (resultTypeValue !== null && resultTypeValue !== undefined) {
                    var resultTypeInstance = resultTypeValue;
                    logValueInstance.resultType = resultTypeInstance;
                  }
                  
                  var resultSignatureValue = valueValue3['resultSignature'];
                  if (resultSignatureValue !== null && resultSignatureValue !== undefined) {
                    var resultSignatureInstance = resultSignatureValue;
                    logValueInstance.resultSignature = resultSignatureInstance;
                  }
                  
                  var resultDescriptionValue = valueValue3['resultDescription'];
                  if (resultDescriptionValue !== null && resultDescriptionValue !== undefined) {
                    var resultDescriptionInstance = resultDescriptionValue;
                    logValueInstance.resultDescription = resultDescriptionInstance;
                  }
                  
                  var durationMsValue = valueValue3['durationMs'];
                  if (durationMsValue !== null && durationMsValue !== undefined) {
                    var durationMsInstance = durationMsValue;
                    logValueInstance.durationMs = durationMsInstance;
                  }
                  
                  var callerIpAddressValue = valueValue3['callerIpAddress'];
                  if (callerIpAddressValue !== null && callerIpAddressValue !== undefined) {
                    var callerIpAddressInstance = callerIpAddressValue;
                    logValueInstance.callerIpAddress = callerIpAddressInstance;
                  }
                  
                  var correlationIdValue = valueValue3['correlationId'];
                  if (correlationIdValue !== null && correlationIdValue !== undefined) {
                    var correlationIdInstance = correlationIdValue;
                    logValueInstance.correlationId = correlationIdInstance;
                  }
                  
                  var identityValue = valueValue3['identity'];
                  if (identityValue !== null && identityValue !== undefined) {
                    var identityInstance = identityValue;
                    logValueInstance.identity = identityInstance;
                  }
                  
                  var levelValue = valueValue3['level'];
                  if (levelValue !== null && levelValue !== undefined) {
                    var levelInstance = levelValue;
                    logValueInstance.level = levelInstance;
                  }
                  
                  var locationValue = valueValue3['location'];
                  if (locationValue !== null && locationValue !== undefined) {
                    var locationInstance = locationValue;
                    logValueInstance.location = locationInstance;
                  }
                  
                  var propertiesSequenceElement = valueValue3['properties'];
                  if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                    for (var property in propertiesSequenceElement) {
                      var propertiesKey = property;
                      var propertiesValue = propertiesSequenceElement[property];
                      logValueInstance.properties[propertiesKey] = propertiesValue;
                    }
                  }
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return LogOperations;
})();

var MetricDefinitionOperations = ( /** @lends MetricDefinitionOperations */ function() {
  /**
   * @class
   * Operations for metric definitions.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [InsightsClient] {@link InsightsClient~InsightsClient}.
   * See [metricDefinitionOperations] {@link
   * InsightsClient~InsightsClient#metricDefinitionOperations}.
   * Initializes a new instance of the MetricDefinitionOperations class.
   * @constructor
   * 
   * @param {InsightsClient} client Reference to the service client.
   */
  function MetricDefinitionOperations(client) {
    this.client = client;
  }
  
  /**
   * The List Metric Definitions operation lists the metric definitions for the
   * resource.
   * 
   * @param {string} resourceUri The resource identifier of the target resource
   * to get metrics for.
   * 
   * @param {string} [filterString] An OData $filter expression that supports
   * querying by the name of the metric definition. For example, "name.value
   * eq 'Percentage CPU'". Name is optional, meaning the expression may be "".
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  MetricDefinitionOperations.prototype.getMetricDefinitions = function(resourceUri, filterString, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceUri === null || resourceUri === undefined) {
      return callback(new Error('resourceUri cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    url2 = url2 + resourceUri;
    url2 = url2 + '/metricDefinitions';
    var queryParameters = [];
    queryParameters.push('api-version=2015-07-01');
    var odataFilter = [];
    if (filterString !== null && filterString !== undefined) {
      odataFilter.push(encodeURIComponent(filterString));
    }
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(null));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['x-ms-version'] = '2014-04-01';
    
    // 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 metricDefinitionCollectionInstance = { value: [] };
          result.metricDefinitionCollection = metricDefinitionCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var metricDefinitionInstance = { dimensions: [], metricAvailabilities: [], properties: {} };
              metricDefinitionCollectionInstance.value.push(metricDefinitionInstance);
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = {};
                metricDefinitionInstance.name = nameInstance;
                
                var valueValue2 = nameValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  nameInstance.value = valueInstance;
                }
                
                var localizedValueValue = nameValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  nameInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var unitValue = valueValue['unit'];
              if (unitValue !== null && unitValue !== undefined) {
                var unitInstance = unitValue;
                metricDefinitionInstance.unit = unitInstance;
              }
              
              var primaryAggregationTypeValue = valueValue['primaryAggregationType'];
              if (primaryAggregationTypeValue !== null && primaryAggregationTypeValue !== undefined) {
                var primaryAggregationTypeInstance = primaryAggregationTypeValue;
                metricDefinitionInstance.primaryAggregationType = primaryAggregationTypeInstance;
              }
              
              var resourceIdValue = valueValue['resourceId'];
              if (resourceIdValue !== null && resourceIdValue !== undefined) {
                var resourceIdInstance = resourceIdValue;
                metricDefinitionInstance.resourceId = resourceIdInstance;
              }
              
              var metricAvailabilitiesArray = valueValue['metricAvailabilities'];
              if (metricAvailabilitiesArray !== null && metricAvailabilitiesArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < metricAvailabilitiesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var metricAvailabilitiesValue = metricAvailabilitiesArray[loweredIndex2];
                  var metricAvailabilityInstance = {};
                  metricDefinitionInstance.metricAvailabilities.push(metricAvailabilityInstance);
                  
                  var timeGrainValue = metricAvailabilitiesValue['timeGrain'];
                  if (timeGrainValue !== null && timeGrainValue !== undefined) {
                    var timeGrainInstance = moment.duration(timeGrainValue);
                    metricAvailabilityInstance.timeGrain = timeGrainInstance;
                  }
                  
                  var retentionValue = metricAvailabilitiesValue['retention'];
                  if (retentionValue !== null && retentionValue !== undefined) {
                    var retentionInstance = moment.duration(retentionValue);
                    metricAvailabilityInstance.retention = retentionInstance;
                  }
                  
                  var locationValue = metricAvailabilitiesValue['location'];
                  if (locationValue !== null && locationValue !== undefined) {
                    var locationInstance = { tableInfo: [] };
                    metricAvailabilityInstance.location = locationInstance;
                    
                    var tableEndpointValue = locationValue['tableEndpoint'];
                    if (tableEndpointValue !== null && tableEndpointValue !== undefined) {
                      var tableEndpointInstance = tableEndpointValue;
                      locationInstance.tableEndpoint = tableEndpointInstance;
                    }
                    
                    var tableInfoArray = locationValue['tableInfo'];
                    if (tableInfoArray !== null && tableInfoArray !== undefined) {
                      for (var loweredIndex3 = 0; loweredIndex3 < tableInfoArray.length; loweredIndex3 = loweredIndex3 + 1) {
                        var tableInfoValue = tableInfoArray[loweredIndex3];
                        var metricTableInfoInstance = {};
                        locationInstance.tableInfo.push(metricTableInfoInstance);
                        
                        var tableNameValue = tableInfoValue['tableName'];
                        if (tableNameValue !== null && tableNameValue !== undefined) {
                          var tableNameInstance = tableNameValue;
                          metricTableInfoInstance.tableName = tableNameInstance;
                        }
                        
                        var startTimeValue = tableInfoValue['startTime'];
                        if (startTimeValue !== null && startTimeValue !== undefined) {
                          var startTimeInstance = startTimeValue;
                          metricTableInfoInstance.startTime = startTimeInstance;
                        }
                        
                        var endTimeValue = tableInfoValue['endTime'];
                        if (endTimeValue !== null && endTimeValue !== undefined) {
                          var endTimeInstance = endTimeValue;
                          metricTableInfoInstance.endTime = endTimeInstance;
                        }
                        
                        var sasTokenValue = tableInfoValue['sasToken'];
                        if (sasTokenValue !== null && sasTokenValue !== undefined) {
                          var sasTokenInstance = sasTokenValue;
                          metricTableInfoInstance.sasToken = sasTokenInstance;
                        }
                        
                        var sasTokenExpirationTimeValue = tableInfoValue['sasTokenExpirationTime'];
                        if (sasTokenExpirationTimeValue !== null && sasTokenExpirationTimeValue !== undefined) {
                          var sasTokenExpirationTimeInstance = sasTokenExpirationTimeValue;
                          metricTableInfoInstance.sasTokenExpirationTime = sasTokenExpirationTimeInstance;
                        }
                      }
                    }
                    
                    var partitionKeyValue = locationValue['partitionKey'];
                    if (partitionKeyValue !== null && partitionKeyValue !== undefined) {
                      var partitionKeyInstance = partitionKeyValue;
                      locationInstance.partitionKey = partitionKeyInstance;
                    }
                  }
                  
                  var blobLocationValue = metricAvailabilitiesValue['blobLocation'];
                  if (blobLocationValue !== null && blobLocationValue !== undefined) {
                    var blobLocationInstance = { blobInfo: [] };
                    metricAvailabilityInstance.blobLocation = blobLocationInstance;
                    
                    var blobEndpointValue = blobLocationValue['blobEndpoint'];
                    if (blobEndpointValue !== null && blobEndpointValue !== undefined) {
                      var blobEndpointInstance = blobEndpointValue;
                      blobLocationInstance.blobEndpoint = blobEndpointInstance;
                    }
                    
                    var blobInfoArray = blobLocationValue['blobInfo'];
                    if (blobInfoArray !== null && blobInfoArray !== undefined) {
                      for (var loweredIndex4 = 0; loweredIndex4 < blobInfoArray.length; loweredIndex4 = loweredIndex4 + 1) {
                        var blobInfoValue = blobInfoArray[loweredIndex4];
                        var blobInfoInstance = {};
                        blobLocationInstance.blobInfo.push(blobInfoInstance);
                        
                        var blobUriValue = blobInfoValue['blobUri'];
                        if (blobUriValue !== null && blobUriValue !== undefined) {
                          var blobUriInstance = blobUriValue;
                          blobInfoInstance.blobUri = blobUriInstance;
                        }
                        
                        var startTimeValue2 = blobInfoValue['startTime'];
                        if (startTimeValue2 !== null && startTimeValue2 !== undefined) {
                          var startTimeInstance2 = startTimeValue2;
                          blobInfoInstance.startTime = startTimeInstance2;
                        }
                        
                        var endTimeValue2 = blobInfoValue['endTime'];
                        if (endTimeValue2 !== null && endTimeValue2 !== undefined) {
                          var endTimeInstance2 = endTimeValue2;
                          blobInfoInstance.endTime = endTimeInstance2;
                        }
                        
                        var sasTokenValue2 = blobInfoValue['sasToken'];
                        if (sasTokenValue2 !== null && sasTokenValue2 !== undefined) {
                          var sasTokenInstance2 = sasTokenValue2;
                          blobInfoInstance.sasToken = sasTokenInstance2;
                        }
                      }
                    }
                  }
                }
              }
              
              var propertiesSequenceElement = valueValue['properties'];
              if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                for (var property in propertiesSequenceElement) {
                  var propertiesKey = property;
                  var propertiesValue = propertiesSequenceElement[property];
                  metricDefinitionInstance.properties[propertiesKey] = propertiesValue;
                }
              }
              
              var dimensionsArray = valueValue['dimensions'];
              if (dimensionsArray !== null && dimensionsArray !== undefined) {
                for (var loweredIndex5 = 0; loweredIndex5 < dimensionsArray.length; loweredIndex5 = loweredIndex5 + 1) {
                  var dimensionsValue = dimensionsArray[loweredIndex5];
                  var dimensionInstance = { values: [] };
                  metricDefinitionInstance.dimensions.push(dimensionInstance);
                  
                  var nameValue2 = dimensionsValue['name'];
                  if (nameValue2 !== null && nameValue2 !== undefined) {
                    var nameInstance2 = {};
                    dimensionInstance.name = nameInstance2;
                    
                    var valueValue3 = nameValue2['value'];
                    if (valueValue3 !== null && valueValue3 !== undefined) {
                      var valueInstance2 = valueValue3;
                      nameInstance2.value = valueInstance2;
                    }
                    
                    var localizedValueValue2 = nameValue2['localizedValue'];
                    if (localizedValueValue2 !== null && localizedValueValue2 !== undefined) {
                      var localizedValueInstance2 = localizedValueValue2;
                      nameInstance2.localizedValue = localizedValueInstance2;
                    }
                  }
                  
                  var valuesArray = dimensionsValue['values'];
                  if (valuesArray !== null && valuesArray !== undefined) {
                    for (var loweredIndex6 = 0; loweredIndex6 < valuesArray.length; loweredIndex6 = loweredIndex6 + 1) {
                      var valuesValue = valuesArray[loweredIndex6];
                      var localizableStringInstance = {};
                      dimensionInstance.values.push(localizableStringInstance);
                      
                      var valueValue4 = valuesValue['value'];
                      if (valueValue4 !== null && valueValue4 !== undefined) {
                        var valueInstance3 = valueValue4;
                        localizableStringInstance.value = valueInstance3;
                      }
                      
                      var localizedValueValue3 = valuesValue['localizedValue'];
                      if (localizedValueValue3 !== null && localizedValueValue3 !== undefined) {
                        var localizedValueInstance3 = localizedValueValue3;
                        localizableStringInstance.localizedValue = localizedValueInstance3;
                      }
                    }
                  }
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return MetricDefinitionOperations;
})();

var MetricOperations = ( /** @lends MetricOperations */ function() {
  /**
   * @class
   * Operations for metric values.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [InsightsClient] {@link InsightsClient~InsightsClient}.
   * See [metricOperations] {@link
   * InsightsClient~InsightsClient#metricOperations}.
   * Initializes a new instance of the MetricOperations class.
   * @constructor
   * 
   * @param {InsightsClient} client Reference to the service client.
   */
  function MetricOperations(client) {
    this.client = client;
  }
  
  /**
   * The List Metric operation lists the metric value sets for the resource
   * metrics.
   * 
   * @param {string} resourceUri The resource identifier of the target resource
   * to get metrics for.
   * 
   * @param {string} [filterString] An OData $filter expression that supports
   * querying by the name, startTime, endTime and timeGrain of the metric
   * value sets. For example, "(name.value eq 'Percentage CPU') and startTime
   * eq 2014-07-02T01:00Z and endTime eq 2014-08-21T01:00:00Z and timeGrain eq
   * duration'PT1H'". In the expression, startTime, endTime and timeGrain are
   * required. Name is optional.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  MetricOperations.prototype.getMetrics = function(resourceUri, filterString, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceUri === null || resourceUri === undefined) {
      return callback(new Error('resourceUri cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    url2 = url2 + resourceUri;
    url2 = url2 + '/metrics';
    var queryParameters = [];
    queryParameters.push('api-version=2014-04-01');
    var odataFilter = [];
    if (filterString !== null && filterString !== undefined) {
      odataFilter.push(encodeURIComponent(filterString));
    }
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(null));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    httpRequest.headers['x-ms-version'] = '2014-04-01';
    
    // 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 metricCollectionInstance = { value: [] };
          result.metricCollection = metricCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var metricInstance = { metricValues: [], properties: {} };
              metricCollectionInstance.value.push(metricInstance);
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = {};
                metricInstance.name = nameInstance;
                
                var valueValue2 = nameValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  nameInstance.value = valueInstance;
                }
                
                var localizedValueValue = nameValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  nameInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var unitValue = valueValue['unit'];
              if (unitValue !== null && unitValue !== undefined) {
                var unitInstance = unitValue;
                metricInstance.unit = unitInstance;
              }
              
              var timeGrainValue = valueValue['timeGrain'];
              if (timeGrainValue !== null && timeGrainValue !== undefined) {
                var timeGrainInstance = moment.duration(timeGrainValue);
                metricInstance.timeGrain = timeGrainInstance;
              }
              
              var startTimeValue = valueValue['startTime'];
              if (startTimeValue !== null && startTimeValue !== undefined) {
                var startTimeInstance = startTimeValue;
                metricInstance.startTime = startTimeInstance;
              }
              
              var endTimeValue = valueValue['endTime'];
              if (endTimeValue !== null && endTimeValue !== undefined) {
                var endTimeInstance = endTimeValue;
                metricInstance.endTime = endTimeInstance;
              }
              
              var metricValuesArray = valueValue['metricValues'];
              if (metricValuesArray !== null && metricValuesArray !== undefined) {
                for (var loweredIndex2 = 0; loweredIndex2 < metricValuesArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var metricValuesValue = metricValuesArray[loweredIndex2];
                  var metricValueInstance = { properties: {} };
                  metricInstance.metricValues.push(metricValueInstance);
                  
                  var timestampValue = metricValuesValue['timestamp'];
                  if (timestampValue !== null && timestampValue !== undefined) {
                    var timestampInstance = timestampValue;
                    metricValueInstance.timestamp = timestampInstance;
                  }
                  
                  var averageValue = metricValuesValue['average'];
                  if (averageValue !== null && averageValue !== undefined) {
                    var averageInstance = averageValue;
                    metricValueInstance.average = averageInstance;
                  }
                  
                  var minimumValue = metricValuesValue['minimum'];
                  if (minimumValue !== null && minimumValue !== undefined) {
                    var minimumInstance = minimumValue;
                    metricValueInstance.minimum = minimumInstance;
                  }
                  
                  var maximumValue = metricValuesValue['maximum'];
                  if (maximumValue !== null && maximumValue !== undefined) {
                    var maximumInstance = maximumValue;
                    metricValueInstance.maximum = maximumInstance;
                  }
                  
                  var totalValue = metricValuesValue['total'];
                  if (totalValue !== null && totalValue !== undefined) {
                    var totalInstance = totalValue;
                    metricValueInstance.total = totalInstance;
                  }
                  
                  var countValue = metricValuesValue['count'];
                  if (countValue !== null && countValue !== undefined) {
                    var countInstance = countValue;
                    metricValueInstance.count = countInstance;
                  }
                  
                  var lastValue = metricValuesValue['last'];
                  if (lastValue !== null && lastValue !== undefined) {
                    var lastInstance = lastValue;
                    metricValueInstance.last = lastInstance;
                  }
                  
                  var propertiesSequenceElement = metricValuesValue['properties'];
                  if (propertiesSequenceElement !== null && propertiesSequenceElement !== undefined) {
                    for (var property in propertiesSequenceElement) {
                      var propertiesKey = property;
                      var propertiesValue = propertiesSequenceElement[property];
                      metricValueInstance.properties[propertiesKey] = propertiesValue;
                    }
                  }
                }
              }
              
              var resourceIdValue = valueValue['resourceId'];
              if (resourceIdValue !== null && resourceIdValue !== undefined) {
                var resourceIdInstance = resourceIdValue;
                metricInstance.resourceId = resourceIdInstance;
              }
              
              var propertiesSequenceElement2 = valueValue['properties'];
              if (propertiesSequenceElement2 !== null && propertiesSequenceElement2 !== undefined) {
                for (var property2 in propertiesSequenceElement2) {
                  var propertiesKey2 = property2;
                  var propertiesValue2 = propertiesSequenceElement2[property2];
                  metricInstance.properties[propertiesKey2] = propertiesValue2;
                }
              }
              
              var dimensionNameValue = valueValue['dimensionName'];
              if (dimensionNameValue !== null && dimensionNameValue !== undefined) {
                var dimensionNameInstance = {};
                metricInstance.dimensionName = dimensionNameInstance;
                
                var valueValue3 = dimensionNameValue['value'];
                if (valueValue3 !== null && valueValue3 !== undefined) {
                  var valueInstance2 = valueValue3;
                  dimensionNameInstance.value = valueInstance2;
                }
                
                var localizedValueValue2 = dimensionNameValue['localizedValue'];
                if (localizedValueValue2 !== null && localizedValueValue2 !== undefined) {
                  var localizedValueInstance2 = localizedValueValue2;
                  dimensionNameInstance.localizedValue = localizedValueInstance2;
                }
              }
              
              var dimensionValueValue = valueValue['dimensionValue'];
              if (dimensionValueValue !== null && dimensionValueValue !== undefined) {
                var dimensionValueInstance = {};
                metricInstance.dimensionValue = dimensionValueInstance;
                
                var valueValue4 = dimensionValueValue['value'];
                if (valueValue4 !== null && valueValue4 !== undefined) {
                  var valueInstance3 = valueValue4;
                  dimensionValueInstance.value = valueInstance3;
                }
                
                var localizedValueValue3 = dimensionValueValue['localizedValue'];
                if (localizedValueValue3 !== null && localizedValueValue3 !== undefined) {
                  var localizedValueInstance3 = localizedValueValue3;
                  dimensionValueInstance.localizedValue = localizedValueInstance3;
                }
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return MetricOperations;
})();

var UsageMetricsOperations = ( /** @lends UsageMetricsOperations */ function() {
  /**
   * @class
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [InsightsClient] {@link InsightsClient~InsightsClient}.
   * See [usageMetricOperations] {@link
   * InsightsClient~InsightsClient#usageMetricOperations}.
   * Initializes a new instance of the UsageMetricsOperations class.
   * @constructor
   * 
   * @param {InsightsClient} client Reference to the service client.
   */
  function UsageMetricsOperations(client) {
    this.client = client;
  }
  
  /**
   * The List operation lists the usage metrics for the resource.
   * 
   * @param {string} resourceUri The resource identifier of the target resource
   * to get usages for.
   * 
   * @param {string} [filterString] An OData $filter expression that supports
   * querying by the name of the usage. For example, "name.value eq
   * 'Percentage CPU'". Name is optional, meaning the expression may be "".
   * 
   * @param {string} apiVersion The resource provider api version.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  UsageMetricsOperations.prototype.list = function(resourceUri, filterString, apiVersion, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceUri === null || resourceUri === undefined) {
      return callback(new Error('resourceUri cannot be null.'));
    }
    if (apiVersion === null || apiVersion === undefined) {
      return callback(new Error('apiVersion cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(resourceUri);
    url2 = url2 + '/usages';
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
    var odataFilter = [];
    if (filterString !== null && filterString !== undefined) {
      odataFilter.push(encodeURIComponent(filterString));
    }
    if (odataFilter.length > 0) {
      queryParameters.push('$filter=' + odataFilter.join(null));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    if (apiVersion !== null && apiVersion !== undefined) {
      httpRequest.headers['x-ms-version'] = apiVersion;
    }
    
    // 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 usageMetricCollectionInstance = { value: [] };
          result.usageMetricCollection = usageMetricCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var usageMetricInstance = {};
              usageMetricCollectionInstance.value.push(usageMetricInstance);
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = {};
                usageMetricInstance.name = nameInstance;
                
                var valueValue2 = nameValue['value'];
                if (valueValue2 !== null && valueValue2 !== undefined) {
                  var valueInstance = valueValue2;
                  nameInstance.value = valueInstance;
                }
                
                var localizedValueValue = nameValue['localizedValue'];
                if (localizedValueValue !== null && localizedValueValue !== undefined) {
                  var localizedValueInstance = localizedValueValue;
                  nameInstance.localizedValue = localizedValueInstance;
                }
              }
              
              var currentValueValue = valueValue['currentValue'];
              if (currentValueValue !== null && currentValueValue !== undefined) {
                var currentValueInstance = currentValueValue;
                usageMetricInstance.currentValue = currentValueInstance;
              }
              
              var idValue = valueValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                usageMetricInstance.id = idInstance;
              }
              
              var limitValue = valueValue['limit'];
              if (limitValue !== null && limitValue !== undefined) {
                var limitInstance = limitValue;
                usageMetricInstance.limit = limitInstance;
              }
              
              var unitValue = valueValue['unit'];
              if (unitValue !== null && unitValue !== undefined) {
                var unitInstance = unitValue;
                usageMetricInstance.unit = unitInstance;
              }
              
              var nextResetTimeValue = valueValue['nextResetTime'];
              if (nextResetTimeValue !== null && nextResetTimeValue !== undefined) {
                var nextResetTimeInstance = nextResetTimeValue;
                usageMetricInstance.nextResetTime = nextResetTimeInstance;
              }
              
              var quotaPeriodValue = valueValue['quotaPeriod'];
              if (quotaPeriodValue !== null && quotaPeriodValue !== undefined) {
                var quotaPeriodInstance = moment.duration(quotaPeriodValue);
                usageMetricInstance.quotaPeriod = quotaPeriodInstance;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * The List operation lists the usage metrics for the resource.
   * 
   * @param {string} resourceUri The resource identifier of the target resource
   * to get usages for.
   * 
   * @param {Array} metricNames metric names to return.
   * 
   * @param {string} apiVersion The resource provider api version.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  UsageMetricsOperations.prototype.listDeprecated = function(resourceUri, metricNames, apiVersion, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceUri === null || resourceUri === undefined) {
      return callback(new Error('resourceUri cannot be null.'));
    }
    if (metricNames === null || metricNames === undefined) {
      return callback(new Error('metricNames cannot be null.'));
    }
    if (apiVersion === null || apiVersion === undefined) {
      return callback(new Error('apiVersion cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(resourceUri);
    url2 = url2 + '/usages';
    var queryParameters = [];
    queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
    if (metricNames.length > 0) {
      queryParameters.push('names=' + encodeURIComponent(metricNames.join(',')));
    }
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Accept'] = 'application/json';
    if (apiVersion !== null && apiVersion !== undefined) {
      httpRequest.headers['x-ms-version'] = apiVersion;
    }
    
    // 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 usageMetricCollectionInstance = { properties: [], value: [] };
          result.usageMetricCollection = usageMetricCollectionInstance;
          
          var valueArray = responseDoc['value'];
          if (valueArray !== null && valueArray !== undefined) {
            for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var valueValue = valueArray[loweredIndex1];
              var usageMetricDeprecatedInstance = {};
              usageMetricCollectionInstance.value.push(usageMetricDeprecatedInstance);
              
              var nameValue = valueValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                usageMetricDeprecatedInstance.name = nameInstance;
              }
              
              var displayNameValue = valueValue['displayName'];
              if (displayNameValue !== null && displayNameValue !== undefined) {
                var displayNameInstance = displayNameValue;
                usageMetricDeprecatedInstance.displayName = displayNameInstance;
              }
              
              var currentValueValue = valueValue['currentValue'];
              if (currentValueValue !== null && currentValueValue !== undefined) {
                var currentValueInstance = currentValueValue;
                usageMetricDeprecatedInstance.currentValue = currentValueInstance;
              }
              
              var limitValue = valueValue['limit'];
              if (limitValue !== null && limitValue !== undefined) {
                var limitInstance = limitValue;
                usageMetricDeprecatedInstance.limit = limitInstance;
              }
              
              var unitValue = valueValue['unit'];
              if (unitValue !== null && unitValue !== undefined) {
                var unitInstance = unitValue;
                usageMetricDeprecatedInstance.unit = unitInstance;
              }
              
              var nextResetTimeValue = valueValue['nextResetTime'];
              if (nextResetTimeValue !== null && nextResetTimeValue !== undefined) {
                var nextResetTimeInstance = nextResetTimeValue;
                usageMetricDeprecatedInstance.nextResetTime = nextResetTimeInstance;
              }
              
              var quotaPeriodValue = valueValue['quotaPeriod'];
              if (quotaPeriodValue !== null && quotaPeriodValue !== undefined) {
                var quotaPeriodInstance = moment.duration(quotaPeriodValue);
                usageMetricDeprecatedInstance.quotaPeriod = quotaPeriodInstance;
              }
            }
          }
          
          var propertiesArray = responseDoc['properties'];
          if (propertiesArray !== null && propertiesArray !== undefined) {
            for (var loweredIndex2 = 0; loweredIndex2 < propertiesArray.length; loweredIndex2 = loweredIndex2 + 1) {
              var propertiesValue = propertiesArray[loweredIndex2];
              var usageMetricDeprecatedInstance2 = {};
              usageMetricCollectionInstance.properties.push(usageMetricDeprecatedInstance2);
              
              var nameValue2 = propertiesValue['name'];
              if (nameValue2 !== null && nameValue2 !== undefined) {
                var nameInstance2 = nameValue2;
                usageMetricDeprecatedInstance2.name = nameInstance2;
              }
              
              var displayNameValue2 = propertiesValue['displayName'];
              if (displayNameValue2 !== null && displayNameValue2 !== undefined) {
                var displayNameInstance2 = displayNameValue2;
                usageMetricDeprecatedInstance2.displayName = displayNameInstance2;
              }
              
              var currentValueValue2 = propertiesValue['currentValue'];
              if (currentValueValue2 !== null && currentValueValue2 !== undefined) {
                var currentValueInstance2 = currentValueValue2;
                usageMetricDeprecatedInstance2.currentValue = currentValueInstance2;
              }
              
              var limitValue2 = propertiesValue['limit'];
              if (limitValue2 !== null && limitValue2 !== undefined) {
                var limitInstance2 = limitValue2;
                usageMetricDeprecatedInstance2.limit = limitInstance2;
              }
              
              var unitValue2 = propertiesValue['unit'];
              if (unitValue2 !== null && unitValue2 !== undefined) {
                var unitInstance2 = unitValue2;
                usageMetricDeprecatedInstance2.unit = unitInstance2;
              }
              
              var nextResetTimeValue2 = propertiesValue['nextResetTime'];
              if (nextResetTimeValue2 !== null && nextResetTimeValue2 !== undefined) {
                var nextResetTimeInstance2 = nextResetTimeValue2;
                usageMetricDeprecatedInstance2.nextResetTime = nextResetTimeInstance2;
              }
              
              var quotaPeriodValue2 = propertiesValue['quotaPeriod'];
              if (quotaPeriodValue2 !== null && quotaPeriodValue2 !== undefined) {
                var quotaPeriodInstance2 = moment.duration(quotaPeriodValue2);
                usageMetricDeprecatedInstance2.quotaPeriod = quotaPeriodInstance2;
              }
            }
          }
        }
        
      }
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return UsageMetricsOperations;
})();
