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

var TrafficManagerManagementClient = ( /** @lends TrafficManagerManagementClient */ function() {
  /**
   * @class
   * Client for creating, updating, listing and deleting Azure Traffic Manager
   * profiles  (see
   * http://azure.microsoft.com/en-gb/documentation/articles/traffic-manager-overview/
   * for more information)
   * Initializes a new instance of the TrafficManagerManagementClient 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 TrafficManagerManagementClient(credentials, baseUri, filters) {
    if (credentials === null || credentials === undefined) {
      throw new Error('credentials cannot be null.');
    }
    
    TrafficManagerManagementClient['super_'].call(this, credentials, filters);
    
    this.credentials = credentials;
    this.baseUri = baseUri;
    if (this.baseUri === null || this.baseUri === undefined) {
      this.baseUri = 'https://management.azure.com';
    }
    if (this.apiVersion === null || this.apiVersion === undefined) {
      this.apiVersion = '2015-11-01';
    }
    if (this.longRunningOperationInitialTimeout === null || this.longRunningOperationInitialTimeout === undefined) {
      this.longRunningOperationInitialTimeout = -1;
    }
    if (this.longRunningOperationRetryTimeout === null || this.longRunningOperationRetryTimeout === undefined) {
      this.longRunningOperationRetryTimeout = -1;
    }
    /**
     * Provides an instance of the
     * [EndpointOperations](-EndpointOperations.html) object.
     * @type {object}
     */
    this.endpoints = new EndpointOperations(this);
    /**
     * Provides an instance of the [ProfileOperations](-ProfileOperations.html)
     * object.
     * @type {object}
     */
    this.profiles = new ProfileOperations(this);
  }
  
  util.inherits(TrafficManagerManagementClient, Service);
  
  
  return TrafficManagerManagementClient;
})();
exports.TrafficManagerManagementClient = TrafficManagerManagementClient;

var EndpointOperations = ( /** @lends EndpointOperations */ function() {
  /**
   * @class
   * Operations for managing Traffic Manager endpoints.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [TrafficManagerManagementClient] {@link
   * TrafficManagerManagementClient~TrafficManagerManagementClient}.
   * See [endpoints] {@link
   * TrafficManagerManagementClient~TrafficManagerManagementClient#endpoints}.
   * Initializes a new instance of the EndpointOperations class.
   * @constructor
   * 
   * @param {TrafficManagerManagementClient} client Reference to the service
   * client.
   */
  function EndpointOperations(client) {
    this.client = client;
  }
  
  /**
   * Create or update a Traffic Manager endpoint.
   * 
   * @param {string} resourceGroupName The name of the resource group
   * containing the Traffic Manager endpoint to be created or updated.
   * 
   * @param {string} profileName The name of the Traffic Manager endpoint to be
   * created or updated.
   * 
   * @param {string} endpointType The type of the Traffic Manager endpoint to
   * be created or updated.
   * 
   * @param {string} endpointName The name of the Traffic Manager endpoint to
   * be created or updated.
   * 
   * @param {EndpointCreateOrUpdateParameters} parameters The Traffic Manager
   * endpoint parameters supplied to the CreateOrUpdate operation.
   * 
   * @param {Endpoint} parameters.endpoint Gets or sets parameters for the
   * Traffic Manager endpoint being created or updated.
   * 
   * @param {string} [parameters.endpoint.id] Gets or sets the ID of the
   * Traffic Manager endpoint.
   * 
   * @param {string} [parameters.endpoint.name] Gets or sets the name of the
   * Traffic Manager endpoint.
   * 
   * @param {string} [parameters.endpoint.type] Gets or sets the endpoint type
   * of the Traffic Manager endpoint.
   * 
   * @param {EndpointProperties} [parameters.endpoint.properties] Gets or sets
   * the properties of the Traffic Manager endpoint.
   * 
   * @param {string} [parameters.endpoint.properties.targetResourceId] Gets or
   * sets the Azure Resource URI of the of the endpoint.  Not applicable to
   * endpoints of type 'ExternalEndpoints'.
   * 
   * @param {string} [parameters.endpoint.properties.target] Gets or sets the
   * fully-qualified DNS name of the endpoint.  Traffic Manager returns this
   * value in DNS responses to direct traffic to this endpoint.
   * 
   * @param {string} [parameters.endpoint.properties.endpointStatus] Gets or
   * sets the status of the endpoint..  If the endpoint is Enabled, it is
   * probed for endpoint health and is included in the traffic routing method.
   * Possible values are 'Enabled' and 'Disabled'.
   * 
   * @param {number} [parameters.endpoint.properties.weight] Gets or sets the
   * weight of this endpoint when using the 'Weighted' traffic routing method.
   * Possible values are from 1 to 1000.
   * 
   * @param {number} [parameters.endpoint.properties.priority] Gets or sets the
   * priority of this endpoint when using the ‘Priority’ traffic routing
   * method. Possible values are from 1 to 1000, lower values represent higher
   * priority. This is an optional parameter.  If specified, it must be
   * specified on all endpoints, and no two endpoints can share the same
   * priority value.
   * 
   * @param {string} [parameters.endpoint.properties.endpointLocation]
   * Specifies the location of the external or nested endpoints when using the
   * ‘Performance’ traffic routing method.
   * 
   * @param {string} [parameters.endpoint.properties.endpointMonitorStatus]
   * Gets or sets the monitoring status of the endpoint.
   * 
   * @param {number} [parameters.endpoint.properties.minChildEndpoints] Gets or
   * sets the minimum number of endpoints that must be available in the child
   * profile in order for the parent profile to be considered available. Only
   * applicable to endpoint of type 'NestedEndpoints'.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EndpointOperations.prototype.createOrUpdate = function(resourceGroupName, profileName, endpointType, endpointName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName cannot be null.'));
    }
    if (endpointType === null || endpointType === undefined) {
      return callback(new Error('endpointType cannot be null.'));
    }
    if (endpointName === null || endpointName === undefined) {
      return callback(new Error('endpointName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.endpoint === null || parameters.endpoint === undefined) {
      return callback(new Error('parameters.endpoint cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.Network';
    url2 = url2 + '/trafficmanagerprofiles/';
    url2 = url2 + encodeURIComponent(profileName);
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(endpointType);
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(endpointName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var endpointCreateOrUpdateParametersValue = {};
    requestDoc = endpointCreateOrUpdateParametersValue;
    
    if (parameters.endpoint.id !== null && parameters.endpoint.id !== undefined) {
      endpointCreateOrUpdateParametersValue['id'] = parameters.endpoint.id;
    }
    
    if (parameters.endpoint.name !== null && parameters.endpoint.name !== undefined) {
      endpointCreateOrUpdateParametersValue['name'] = parameters.endpoint.name;
    }
    
    if (parameters.endpoint.type !== null && parameters.endpoint.type !== undefined) {
      endpointCreateOrUpdateParametersValue['type'] = parameters.endpoint.type;
    }
    
    if (parameters.endpoint.properties !== null && parameters.endpoint.properties !== undefined) {
      var propertiesValue = {};
      endpointCreateOrUpdateParametersValue['properties'] = propertiesValue;
      
      if (parameters.endpoint.properties.targetResourceId !== null && parameters.endpoint.properties.targetResourceId !== undefined) {
        propertiesValue['targetResourceId'] = parameters.endpoint.properties.targetResourceId;
      }
      
      if (parameters.endpoint.properties.target !== null && parameters.endpoint.properties.target !== undefined) {
        propertiesValue['target'] = parameters.endpoint.properties.target;
      }
      
      if (parameters.endpoint.properties.endpointStatus !== null && parameters.endpoint.properties.endpointStatus !== undefined) {
        propertiesValue['endpointStatus'] = parameters.endpoint.properties.endpointStatus;
      }
      
      if (parameters.endpoint.properties.weight !== null && parameters.endpoint.properties.weight !== undefined) {
        propertiesValue['weight'] = parameters.endpoint.properties.weight;
      }
      
      if (parameters.endpoint.properties.priority !== null && parameters.endpoint.properties.priority !== undefined) {
        propertiesValue['priority'] = parameters.endpoint.properties.priority;
      }
      
      if (parameters.endpoint.properties.endpointLocation !== null && parameters.endpoint.properties.endpointLocation !== undefined) {
        propertiesValue['endpointLocation'] = parameters.endpoint.properties.endpointLocation;
      }
      
      if (parameters.endpoint.properties.endpointMonitorStatus !== null && parameters.endpoint.properties.endpointMonitorStatus !== undefined) {
        propertiesValue['endpointMonitorStatus'] = parameters.endpoint.properties.endpointMonitorStatus;
      }
      
      if (parameters.endpoint.properties.minChildEndpoints !== null && parameters.endpoint.properties.minChildEndpoints !== undefined) {
        propertiesValue['minChildEndpoints'] = parameters.endpoint.properties.minChildEndpoints;
      }
    }
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = null;
      if (responseContent) {
        responseDoc = JSON.parse(responseContent);
      }
      
      if (responseDoc !== null && responseDoc !== undefined) {
        var endpointInstance = {};
        result.endpoint = endpointInstance;
        
        var idValue = responseDoc['id'];
        if (idValue !== null && idValue !== undefined) {
          var idInstance = idValue;
          endpointInstance.id = idInstance;
        }
        
        var nameValue = responseDoc['name'];
        if (nameValue !== null && nameValue !== undefined) {
          var nameInstance = nameValue;
          endpointInstance.name = nameInstance;
        }
        
        var typeValue = responseDoc['type'];
        if (typeValue !== null && typeValue !== undefined) {
          var typeInstance = typeValue;
          endpointInstance.type = typeInstance;
        }
        
        var propertiesValue2 = responseDoc['properties'];
        if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
          var propertiesInstance = {};
          endpointInstance.properties = propertiesInstance;
          
          var targetResourceIdValue = propertiesValue2['targetResourceId'];
          if (targetResourceIdValue !== null && targetResourceIdValue !== undefined) {
            var targetResourceIdInstance = targetResourceIdValue;
            propertiesInstance.targetResourceId = targetResourceIdInstance;
          }
          
          var targetValue = propertiesValue2['target'];
          if (targetValue !== null && targetValue !== undefined) {
            var targetInstance = targetValue;
            propertiesInstance.target = targetInstance;
          }
          
          var endpointStatusValue = propertiesValue2['endpointStatus'];
          if (endpointStatusValue !== null && endpointStatusValue !== undefined) {
            var endpointStatusInstance = endpointStatusValue;
            propertiesInstance.endpointStatus = endpointStatusInstance;
          }
          
          var weightValue = propertiesValue2['weight'];
          if (weightValue !== null && weightValue !== undefined) {
            var weightInstance = weightValue;
            propertiesInstance.weight = weightInstance;
          }
          
          var priorityValue = propertiesValue2['priority'];
          if (priorityValue !== null && priorityValue !== undefined) {
            var priorityInstance = priorityValue;
            propertiesInstance.priority = priorityInstance;
          }
          
          var endpointLocationValue = propertiesValue2['endpointLocation'];
          if (endpointLocationValue !== null && endpointLocationValue !== undefined) {
            var endpointLocationInstance = endpointLocationValue;
            propertiesInstance.endpointLocation = endpointLocationInstance;
          }
          
          var endpointMonitorStatusValue = propertiesValue2['endpointMonitorStatus'];
          if (endpointMonitorStatusValue !== null && endpointMonitorStatusValue !== undefined) {
            var endpointMonitorStatusInstance = endpointMonitorStatusValue;
            propertiesInstance.endpointMonitorStatus = endpointMonitorStatusInstance;
          }
          
          var minChildEndpointsValue = propertiesValue2['minChildEndpoints'];
          if (minChildEndpointsValue !== null && minChildEndpointsValue !== undefined) {
            var minChildEndpointsInstance = minChildEndpointsValue;
            propertiesInstance.minChildEndpoints = minChildEndpointsInstance;
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Deletes a Traffic Manager endpoint.
   * 
   * @param {string} resourceGroupName The name of the resource group
   * containing the Traffic Manager endpoint to be deleted.
   * 
   * @param {string} profileName The name of the Traffic Manager endpoint to be
   * deleted.
   * 
   * @param {string} endpointType The type of the Traffic Manager endpoint to
   * be deleted.
   * 
   * @param {string} endpointName The name of the Traffic Manager endpoint to
   * be deleted.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EndpointOperations.prototype.deleteMethod = function(resourceGroupName, profileName, endpointType, endpointName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName cannot be null.'));
    }
    if (endpointType === null || endpointType === undefined) {
      return callback(new Error('endpointType cannot be null.'));
    }
    if (endpointName === null || endpointName === undefined) {
      return callback(new Error('endpointName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.Network';
    url2 = url2 + '/trafficmanagerprofiles/';
    url2 = url2 + encodeURIComponent(profileName);
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(endpointType);
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(endpointName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets a Traffic Manager endpoint.
   * 
   * @param {string} resourceGroupName The name of the resource group
   * containing the Traffic Manager endpoint.
   * 
   * @param {string} profileName The name of the Traffic Manager endpoint.
   * 
   * @param {string} endpointType The type of the Traffic Manager endpoint.
   * 
   * @param {string} endpointName The name of the Traffic Manager endpoint.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EndpointOperations.prototype.get = function(resourceGroupName, profileName, endpointType, endpointName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName cannot be null.'));
    }
    if (endpointType === null || endpointType === undefined) {
      return callback(new Error('endpointType cannot be null.'));
    }
    if (endpointName === null || endpointName === undefined) {
      return callback(new Error('endpointName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.Network';
    url2 = url2 + '/trafficmanagerprofiles/';
    url2 = url2 + encodeURIComponent(profileName);
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(endpointType);
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(endpointName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = null;
      if (responseContent) {
        responseDoc = JSON.parse(responseContent);
      }
      
      if (responseDoc !== null && responseDoc !== undefined) {
        var endpointInstance = {};
        result.endpoint = endpointInstance;
        
        var idValue = responseDoc['id'];
        if (idValue !== null && idValue !== undefined) {
          var idInstance = idValue;
          endpointInstance.id = idInstance;
        }
        
        var nameValue = responseDoc['name'];
        if (nameValue !== null && nameValue !== undefined) {
          var nameInstance = nameValue;
          endpointInstance.name = nameInstance;
        }
        
        var typeValue = responseDoc['type'];
        if (typeValue !== null && typeValue !== undefined) {
          var typeInstance = typeValue;
          endpointInstance.type = typeInstance;
        }
        
        var propertiesValue = responseDoc['properties'];
        if (propertiesValue !== null && propertiesValue !== undefined) {
          var propertiesInstance = {};
          endpointInstance.properties = propertiesInstance;
          
          var targetResourceIdValue = propertiesValue['targetResourceId'];
          if (targetResourceIdValue !== null && targetResourceIdValue !== undefined) {
            var targetResourceIdInstance = targetResourceIdValue;
            propertiesInstance.targetResourceId = targetResourceIdInstance;
          }
          
          var targetValue = propertiesValue['target'];
          if (targetValue !== null && targetValue !== undefined) {
            var targetInstance = targetValue;
            propertiesInstance.target = targetInstance;
          }
          
          var endpointStatusValue = propertiesValue['endpointStatus'];
          if (endpointStatusValue !== null && endpointStatusValue !== undefined) {
            var endpointStatusInstance = endpointStatusValue;
            propertiesInstance.endpointStatus = endpointStatusInstance;
          }
          
          var weightValue = propertiesValue['weight'];
          if (weightValue !== null && weightValue !== undefined) {
            var weightInstance = weightValue;
            propertiesInstance.weight = weightInstance;
          }
          
          var priorityValue = propertiesValue['priority'];
          if (priorityValue !== null && priorityValue !== undefined) {
            var priorityInstance = priorityValue;
            propertiesInstance.priority = priorityInstance;
          }
          
          var endpointLocationValue = propertiesValue['endpointLocation'];
          if (endpointLocationValue !== null && endpointLocationValue !== undefined) {
            var endpointLocationInstance = endpointLocationValue;
            propertiesInstance.endpointLocation = endpointLocationInstance;
          }
          
          var endpointMonitorStatusValue = propertiesValue['endpointMonitorStatus'];
          if (endpointMonitorStatusValue !== null && endpointMonitorStatusValue !== undefined) {
            var endpointMonitorStatusInstance = endpointMonitorStatusValue;
            propertiesInstance.endpointMonitorStatus = endpointMonitorStatusInstance;
          }
          
          var minChildEndpointsValue = propertiesValue['minChildEndpoints'];
          if (minChildEndpointsValue !== null && minChildEndpointsValue !== undefined) {
            var minChildEndpointsInstance = minChildEndpointsValue;
            propertiesInstance.minChildEndpoints = minChildEndpointsInstance;
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Create or update a Traffic Manager endpoint.
   * 
   * @param {string} resourceGroupName The name of the resource group
   * containing the Traffic Manager endpoint to be created or updated.
   * 
   * @param {string} profileName The name of the Traffic Manager endpoint to be
   * created or updated.
   * 
   * @param {string} endpointType The type of the Traffic Manager endpoint to
   * be created or updated.
   * 
   * @param {string} endpointName The name of the Traffic Manager endpoint to
   * be created or updated.
   * 
   * @param {EndpointUpdateParameters} parameters The Traffic Manager endpoint
   * parameters supplied to the Update operation.
   * 
   * @param {Endpoint} parameters.endpoint Gets or sets parameters for the
   * Traffic Manager endpoint being created or updated.
   * 
   * @param {string} [parameters.endpoint.id] Gets or sets the ID of the
   * Traffic Manager endpoint.
   * 
   * @param {string} [parameters.endpoint.name] Gets or sets the name of the
   * Traffic Manager endpoint.
   * 
   * @param {string} [parameters.endpoint.type] Gets or sets the endpoint type
   * of the Traffic Manager endpoint.
   * 
   * @param {EndpointProperties} [parameters.endpoint.properties] Gets or sets
   * the properties of the Traffic Manager endpoint.
   * 
   * @param {string} [parameters.endpoint.properties.targetResourceId] Gets or
   * sets the Azure Resource URI of the of the endpoint.  Not applicable to
   * endpoints of type 'ExternalEndpoints'.
   * 
   * @param {string} [parameters.endpoint.properties.target] Gets or sets the
   * fully-qualified DNS name of the endpoint.  Traffic Manager returns this
   * value in DNS responses to direct traffic to this endpoint.
   * 
   * @param {string} [parameters.endpoint.properties.endpointStatus] Gets or
   * sets the status of the endpoint..  If the endpoint is Enabled, it is
   * probed for endpoint health and is included in the traffic routing method.
   * Possible values are 'Enabled' and 'Disabled'.
   * 
   * @param {number} [parameters.endpoint.properties.weight] Gets or sets the
   * weight of this endpoint when using the 'Weighted' traffic routing method.
   * Possible values are from 1 to 1000.
   * 
   * @param {number} [parameters.endpoint.properties.priority] Gets or sets the
   * priority of this endpoint when using the ‘Priority’ traffic routing
   * method. Possible values are from 1 to 1000, lower values represent higher
   * priority. This is an optional parameter.  If specified, it must be
   * specified on all endpoints, and no two endpoints can share the same
   * priority value.
   * 
   * @param {string} [parameters.endpoint.properties.endpointLocation]
   * Specifies the location of the external or nested endpoints when using the
   * ‘Performance’ traffic routing method.
   * 
   * @param {string} [parameters.endpoint.properties.endpointMonitorStatus]
   * Gets or sets the monitoring status of the endpoint.
   * 
   * @param {number} [parameters.endpoint.properties.minChildEndpoints] Gets or
   * sets the minimum number of endpoints that must be available in the child
   * profile in order for the parent profile to be considered available. Only
   * applicable to endpoint of type 'NestedEndpoints'.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  EndpointOperations.prototype.update = function(resourceGroupName, profileName, endpointType, endpointName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName cannot be null.'));
    }
    if (endpointType === null || endpointType === undefined) {
      return callback(new Error('endpointType cannot be null.'));
    }
    if (endpointName === null || endpointName === undefined) {
      return callback(new Error('endpointName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.endpoint === null || parameters.endpoint === undefined) {
      return callback(new Error('parameters.endpoint cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.Network';
    url2 = url2 + '/trafficmanagerprofiles/';
    url2 = url2 + encodeURIComponent(profileName);
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(endpointType);
    url2 = url2 + '/';
    url2 = url2 + encodeURIComponent(endpointName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var endpointUpdateParametersValue = {};
    requestDoc = endpointUpdateParametersValue;
    
    if (parameters.endpoint.id !== null && parameters.endpoint.id !== undefined) {
      endpointUpdateParametersValue['id'] = parameters.endpoint.id;
    }
    
    if (parameters.endpoint.name !== null && parameters.endpoint.name !== undefined) {
      endpointUpdateParametersValue['name'] = parameters.endpoint.name;
    }
    
    if (parameters.endpoint.type !== null && parameters.endpoint.type !== undefined) {
      endpointUpdateParametersValue['type'] = parameters.endpoint.type;
    }
    
    if (parameters.endpoint.properties !== null && parameters.endpoint.properties !== undefined) {
      var propertiesValue = {};
      endpointUpdateParametersValue['properties'] = propertiesValue;
      
      if (parameters.endpoint.properties.targetResourceId !== null && parameters.endpoint.properties.targetResourceId !== undefined) {
        propertiesValue['targetResourceId'] = parameters.endpoint.properties.targetResourceId;
      }
      
      if (parameters.endpoint.properties.target !== null && parameters.endpoint.properties.target !== undefined) {
        propertiesValue['target'] = parameters.endpoint.properties.target;
      }
      
      if (parameters.endpoint.properties.endpointStatus !== null && parameters.endpoint.properties.endpointStatus !== undefined) {
        propertiesValue['endpointStatus'] = parameters.endpoint.properties.endpointStatus;
      }
      
      if (parameters.endpoint.properties.weight !== null && parameters.endpoint.properties.weight !== undefined) {
        propertiesValue['weight'] = parameters.endpoint.properties.weight;
      }
      
      if (parameters.endpoint.properties.priority !== null && parameters.endpoint.properties.priority !== undefined) {
        propertiesValue['priority'] = parameters.endpoint.properties.priority;
      }
      
      if (parameters.endpoint.properties.endpointLocation !== null && parameters.endpoint.properties.endpointLocation !== undefined) {
        propertiesValue['endpointLocation'] = parameters.endpoint.properties.endpointLocation;
      }
      
      if (parameters.endpoint.properties.endpointMonitorStatus !== null && parameters.endpoint.properties.endpointMonitorStatus !== undefined) {
        propertiesValue['endpointMonitorStatus'] = parameters.endpoint.properties.endpointMonitorStatus;
      }
      
      if (parameters.endpoint.properties.minChildEndpoints !== null && parameters.endpoint.properties.minChildEndpoints !== undefined) {
        propertiesValue['minChildEndpoints'] = parameters.endpoint.properties.minChildEndpoints;
      }
    }
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = null;
      if (responseContent) {
        responseDoc = JSON.parse(responseContent);
      }
      
      if (responseDoc !== null && responseDoc !== undefined) {
        var endpointInstance = {};
        result.endpoint = endpointInstance;
        
        var idValue = responseDoc['id'];
        if (idValue !== null && idValue !== undefined) {
          var idInstance = idValue;
          endpointInstance.id = idInstance;
        }
        
        var nameValue = responseDoc['name'];
        if (nameValue !== null && nameValue !== undefined) {
          var nameInstance = nameValue;
          endpointInstance.name = nameInstance;
        }
        
        var typeValue = responseDoc['type'];
        if (typeValue !== null && typeValue !== undefined) {
          var typeInstance = typeValue;
          endpointInstance.type = typeInstance;
        }
        
        var propertiesValue2 = responseDoc['properties'];
        if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
          var propertiesInstance = {};
          endpointInstance.properties = propertiesInstance;
          
          var targetResourceIdValue = propertiesValue2['targetResourceId'];
          if (targetResourceIdValue !== null && targetResourceIdValue !== undefined) {
            var targetResourceIdInstance = targetResourceIdValue;
            propertiesInstance.targetResourceId = targetResourceIdInstance;
          }
          
          var targetValue = propertiesValue2['target'];
          if (targetValue !== null && targetValue !== undefined) {
            var targetInstance = targetValue;
            propertiesInstance.target = targetInstance;
          }
          
          var endpointStatusValue = propertiesValue2['endpointStatus'];
          if (endpointStatusValue !== null && endpointStatusValue !== undefined) {
            var endpointStatusInstance = endpointStatusValue;
            propertiesInstance.endpointStatus = endpointStatusInstance;
          }
          
          var weightValue = propertiesValue2['weight'];
          if (weightValue !== null && weightValue !== undefined) {
            var weightInstance = weightValue;
            propertiesInstance.weight = weightInstance;
          }
          
          var priorityValue = propertiesValue2['priority'];
          if (priorityValue !== null && priorityValue !== undefined) {
            var priorityInstance = priorityValue;
            propertiesInstance.priority = priorityInstance;
          }
          
          var endpointLocationValue = propertiesValue2['endpointLocation'];
          if (endpointLocationValue !== null && endpointLocationValue !== undefined) {
            var endpointLocationInstance = endpointLocationValue;
            propertiesInstance.endpointLocation = endpointLocationInstance;
          }
          
          var endpointMonitorStatusValue = propertiesValue2['endpointMonitorStatus'];
          if (endpointMonitorStatusValue !== null && endpointMonitorStatusValue !== undefined) {
            var endpointMonitorStatusInstance = endpointMonitorStatusValue;
            propertiesInstance.endpointMonitorStatus = endpointMonitorStatusInstance;
          }
          
          var minChildEndpointsValue = propertiesValue2['minChildEndpoints'];
          if (minChildEndpointsValue !== null && minChildEndpointsValue !== undefined) {
            var minChildEndpointsInstance = minChildEndpointsValue;
            propertiesInstance.minChildEndpoints = minChildEndpointsInstance;
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return EndpointOperations;
})();

var ProfileOperations = ( /** @lends ProfileOperations */ function() {
  /**
   * @class
   * Operations for managing Traffic Manager profiles.
   * __NOTE__: An instance of this class is automatically created for an
   * instance of the [TrafficManagerManagementClient] {@link
   * TrafficManagerManagementClient~TrafficManagerManagementClient}.
   * See [profiles] {@link
   * TrafficManagerManagementClient~TrafficManagerManagementClient#profiles}.
   * Initializes a new instance of the ProfileOperations class.
   * @constructor
   * 
   * @param {TrafficManagerManagementClient} client Reference to the service
   * client.
   */
  function ProfileOperations(client) {
    this.client = client;
  }
  
  /**
   * Create or update a Traffic Manager endpoint.
   * 
   * @param {CheckTrafficManagerRelativeDnsNameAvailabilityParameters}
   * parameters The Traffic Manager name parameters supplied to the
   * CheckTrafficManagerNameAvailability operation.
   * 
   * @param {string} parameters.name Gets or sets the name of the resource.
   * 
   * @param {string} parameters.type Gets or sets the type of the resource.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.checkTrafficManagerRelativeDnsNameAvailability = function(parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.name === null || parameters.name === undefined) {
      return callback(new Error('parameters.name cannot be null.'));
    }
    if (parameters.type === null || parameters.type === undefined) {
      return callback(new Error('parameters.type cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + 'providers/';
    url2 = url2 + 'Microsoft.Network';
    url2 = url2 + '/checkTrafficManagerNameAvailability';
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var checkTrafficManagerRelativeDnsNameAvailabilityParametersValue = {};
    requestDoc = checkTrafficManagerRelativeDnsNameAvailabilityParametersValue;
    
    checkTrafficManagerRelativeDnsNameAvailabilityParametersValue['name'] = parameters.name;
    
    checkTrafficManagerRelativeDnsNameAvailabilityParametersValue['type'] = parameters.type;
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = null;
      if (responseContent) {
        responseDoc = JSON.parse(responseContent);
      }
      
      if (responseDoc !== null && responseDoc !== undefined) {
        var nameValue = responseDoc['name'];
        if (nameValue !== null && nameValue !== undefined) {
          var nameInstance = nameValue;
          result.name = nameInstance;
        }
        
        var typeValue = responseDoc['type'];
        if (typeValue !== null && typeValue !== undefined) {
          var typeInstance = typeValue;
          result.type = typeInstance;
        }
        
        var nameAvailableValue = responseDoc['nameAvailable'];
        if (nameAvailableValue !== null && nameAvailableValue !== undefined) {
          var nameAvailableInstance = nameAvailableValue;
          result.nameAvailable = nameAvailableInstance;
        }
        
        var reasonValue = responseDoc['reason'];
        if (reasonValue !== null && reasonValue !== undefined) {
          var reasonInstance = reasonValue;
          result.reason = reasonInstance;
        }
        
        var messageValue = responseDoc['message'];
        if (messageValue !== null && messageValue !== undefined) {
          var messageInstance = messageValue;
          result.message = messageInstance;
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Create or update a Traffic Manager profile.
   * 
   * @param {string} resourceGroupName The name of the resource group
   * containing the Traffic Manager profile.
   * 
   * @param {string} profileName The name of the Traffic Manager profile.
   * 
   * @param {ProfileCreateOrUpdateParameters} parameters The Traffic Manager
   * profile parameters supplied to the CreateOrUpdate operation.
   * 
   * @param {Profile} parameters.profile Gets or sets parameters for the
   * Traffic Manager profile being created or updated.
   * 
   * @param {ProfileProperties} [parameters.profile.properties] Gets or sets
   * the properties of the profile.
   * 
   * @param {string} [parameters.profile.properties.profileStatus] Gets or sets
   * the status of the Traffic Manager profile.  Possible values are 'Enabled'
   * and 'Disabled'.
   * 
   * @param {string} [parameters.profile.properties.trafficRoutingMethod] Gets
   * or sets the traffic routing method of the Traffic Manager profile.
   * Possible values are 'Performance', 'Weighted', or 'Priority'.
   * 
   * @param {DnsConfig} [parameters.profile.properties.dnsConfig] Gets or sets
   * the DNS settings of the Traffic Manager profile.
   * 
   * @param {string} [parameters.profile.properties.dnsConfig.relativeName]
   * Gets or sets the relative DNS name provided by this Traffic Manager
   * profile.  This value is combined with the DNS domain name used by Azure
   * Traffic Manager to form the fully-qualified domain name (FQDN) of the
   * profile.
   * 
   * @param {string} [parameters.profile.properties.dnsConfig.fqdn] Gets or
   * sets the fully-qualified domain name (FQDN) of the Traffic Manager
   * profile.  This is formed from the concatenation of the RelativeName with
   * the DNS domain used by Azure Traffic Manager.
   * 
   * @param {number} [parameters.profile.properties.dnsConfig.ttl] Gets or sets
   * the DNS Ttime-To-Live (TTL), in seconds.  This informs the local DNS
   * resolvers and DNS clients how long to cache DNS responses provided by
   * this Traffic Manager profile.
   * 
   * @param {MonitorConfig} [parameters.profile.properties.monitorConfig] Gets
   * or sets the endpoint monitoring settings of the Traffic Manager profile.
   * 
   * @param {string}
   * [parameters.profile.properties.monitorConfig.profileMonitorStatus] Gets
   * or sets the profile-level monitoring status of the Traffic Manager
   * profile.
   * 
   * @param {string} [parameters.profile.properties.monitorConfig.protocol]
   * Gets or sets the protocol (HTTP or HTTPS) used to probe for endpoint
   * health.
   * 
   * @param {number} [parameters.profile.properties.monitorConfig.port] Gets or
   * sets the TCP port used to probe for endpoint health.
   * 
   * @param {string} [parameters.profile.properties.monitorConfig.path] Gets or
   * sets the path relative to the endpoint domain name used to probe for
   * endpoint health.
   * 
   * @param {array} [parameters.profile.properties.endpoints] Gets or sets the
   * list of endpoints in the Traffic Manager profile.
   * 
   * @param {string} [parameters.profile.id] Gets or sets the ID of the
   * resource.
   * 
   * @param {string} [parameters.profile.name] Gets or sets the name of the
   * resource.
   * 
   * @param {string} [parameters.profile.type] Gets or sets the type of the
   * resource.
   * 
   * @param {string} parameters.profile.location Gets or sets the location of
   * the resource.
   * 
   * @param {object} [parameters.profile.tags] Gets or sets the tags attached
   * to the resource.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.createOrUpdate = function(resourceGroupName, profileName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.profile === null || parameters.profile === undefined) {
      return callback(new Error('parameters.profile cannot be null.'));
    }
    if (parameters.profile.location === null || parameters.profile.location === undefined) {
      return callback(new Error('parameters.profile.location cannot be null.'));
    }
    if (parameters.profile.properties !== null && parameters.profile.properties !== undefined) {
      if (parameters.profile.properties.dnsConfig !== null && parameters.profile.properties.dnsConfig !== undefined) {
        if (parameters.profile.properties.dnsConfig.relativeName === null || parameters.profile.properties.dnsConfig.relativeName === undefined) {
          return callback(new Error('parameters.profile.properties.dnsConfig.relativeName cannot be null.'));
        }
        if (parameters.profile.properties.dnsConfig.ttl === null || parameters.profile.properties.dnsConfig.ttl === undefined) {
          return callback(new Error('parameters.profile.properties.dnsConfig.ttl cannot be null.'));
        }
      }
      if (parameters.profile.properties.monitorConfig !== null && parameters.profile.properties.monitorConfig !== undefined) {
        if (parameters.profile.properties.monitorConfig.path === null || parameters.profile.properties.monitorConfig.path === undefined) {
          return callback(new Error('parameters.profile.properties.monitorConfig.path cannot be null.'));
        }
        if (parameters.profile.properties.monitorConfig.port === null || parameters.profile.properties.monitorConfig.port === undefined) {
          return callback(new Error('parameters.profile.properties.monitorConfig.port cannot be null.'));
        }
        if (parameters.profile.properties.monitorConfig.protocol === null || parameters.profile.properties.monitorConfig.protocol === undefined) {
          return callback(new Error('parameters.profile.properties.monitorConfig.protocol cannot be null.'));
        }
      }
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.Network';
    url2 = url2 + '/trafficmanagerprofiles/';
    url2 = url2 + encodeURIComponent(profileName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PUT';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var profileCreateOrUpdateParametersValue = {};
    requestDoc = profileCreateOrUpdateParametersValue;
    
    if (parameters.profile.properties !== null && parameters.profile.properties !== undefined) {
      var propertiesValue = {};
      profileCreateOrUpdateParametersValue['properties'] = propertiesValue;
      
      if (parameters.profile.properties.profileStatus !== null && parameters.profile.properties.profileStatus !== undefined) {
        propertiesValue['profileStatus'] = parameters.profile.properties.profileStatus;
      }
      
      if (parameters.profile.properties.trafficRoutingMethod !== null && parameters.profile.properties.trafficRoutingMethod !== undefined) {
        propertiesValue['trafficRoutingMethod'] = parameters.profile.properties.trafficRoutingMethod;
      }
      
      if (parameters.profile.properties.dnsConfig !== null && parameters.profile.properties.dnsConfig !== undefined) {
        var dnsConfigValue = {};
        propertiesValue['dnsConfig'] = dnsConfigValue;
        
        dnsConfigValue['relativeName'] = parameters.profile.properties.dnsConfig.relativeName;
        
        if (parameters.profile.properties.dnsConfig.fqdn !== null && parameters.profile.properties.dnsConfig.fqdn !== undefined) {
          dnsConfigValue['fqdn'] = parameters.profile.properties.dnsConfig.fqdn;
        }
        
        dnsConfigValue['ttl'] = parameters.profile.properties.dnsConfig.ttl;
      }
      
      if (parameters.profile.properties.monitorConfig !== null && parameters.profile.properties.monitorConfig !== undefined) {
        var monitorConfigValue = {};
        propertiesValue['monitorConfig'] = monitorConfigValue;
        
        if (parameters.profile.properties.monitorConfig.profileMonitorStatus !== null && parameters.profile.properties.monitorConfig.profileMonitorStatus !== undefined) {
          monitorConfigValue['profileMonitorStatus'] = parameters.profile.properties.monitorConfig.profileMonitorStatus;
        }
        
        monitorConfigValue['protocol'] = parameters.profile.properties.monitorConfig.protocol;
        
        monitorConfigValue['port'] = parameters.profile.properties.monitorConfig.port;
        
        monitorConfigValue['path'] = parameters.profile.properties.monitorConfig.path;
      }
      
      if (parameters.profile.properties.endpoints !== null && parameters.profile.properties.endpoints !== undefined) {
        var endpointsArray = [];
        for (var loweredIndex1 = 0; loweredIndex1 < parameters.profile.properties.endpoints.length; loweredIndex1 = loweredIndex1 + 1) {
          var endpointsItem = parameters.profile.properties.endpoints[loweredIndex1];
          var endpointValue = {};
          endpointsArray.push(endpointValue);
          
          if (endpointsItem.id !== null && endpointsItem.id !== undefined) {
            endpointValue['id'] = endpointsItem.id;
          }
          
          if (endpointsItem.name !== null && endpointsItem.name !== undefined) {
            endpointValue['name'] = endpointsItem.name;
          }
          
          if (endpointsItem.type !== null && endpointsItem.type !== undefined) {
            endpointValue['type'] = endpointsItem.type;
          }
          
          if (endpointsItem.properties !== null && endpointsItem.properties !== undefined) {
            var propertiesValue2 = {};
            endpointValue['properties'] = propertiesValue2;
            
            if (endpointsItem.properties.targetResourceId !== null && endpointsItem.properties.targetResourceId !== undefined) {
              propertiesValue2['targetResourceId'] = endpointsItem.properties.targetResourceId;
            }
            
            if (endpointsItem.properties.target !== null && endpointsItem.properties.target !== undefined) {
              propertiesValue2['target'] = endpointsItem.properties.target;
            }
            
            if (endpointsItem.properties.endpointStatus !== null && endpointsItem.properties.endpointStatus !== undefined) {
              propertiesValue2['endpointStatus'] = endpointsItem.properties.endpointStatus;
            }
            
            if (endpointsItem.properties.weight !== null && endpointsItem.properties.weight !== undefined) {
              propertiesValue2['weight'] = endpointsItem.properties.weight;
            }
            
            if (endpointsItem.properties.priority !== null && endpointsItem.properties.priority !== undefined) {
              propertiesValue2['priority'] = endpointsItem.properties.priority;
            }
            
            if (endpointsItem.properties.endpointLocation !== null && endpointsItem.properties.endpointLocation !== undefined) {
              propertiesValue2['endpointLocation'] = endpointsItem.properties.endpointLocation;
            }
            
            if (endpointsItem.properties.endpointMonitorStatus !== null && endpointsItem.properties.endpointMonitorStatus !== undefined) {
              propertiesValue2['endpointMonitorStatus'] = endpointsItem.properties.endpointMonitorStatus;
            }
            
            if (endpointsItem.properties.minChildEndpoints !== null && endpointsItem.properties.minChildEndpoints !== undefined) {
              propertiesValue2['minChildEndpoints'] = endpointsItem.properties.minChildEndpoints;
            }
          }
        }
        propertiesValue['endpoints'] = endpointsArray;
      }
    }
    
    if (parameters.profile.id !== null && parameters.profile.id !== undefined) {
      profileCreateOrUpdateParametersValue['id'] = parameters.profile.id;
    }
    
    if (parameters.profile.name !== null && parameters.profile.name !== undefined) {
      profileCreateOrUpdateParametersValue['name'] = parameters.profile.name;
    }
    
    if (parameters.profile.type !== null && parameters.profile.type !== undefined) {
      profileCreateOrUpdateParametersValue['type'] = parameters.profile.type;
    }
    
    profileCreateOrUpdateParametersValue['location'] = parameters.profile.location;
    
    if (parameters.profile.tags !== null && parameters.profile.tags !== undefined) {
      var tagsDictionary = {};
      for (var tagsKey in parameters.profile.tags) {
        var tagsValue = parameters.profile.tags[tagsKey];
        tagsDictionary[tagsKey] = tagsValue;
      }
      profileCreateOrUpdateParametersValue['tags'] = tagsDictionary;
    }
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = null;
      if (responseContent) {
        responseDoc = JSON.parse(responseContent);
      }
      
      if (responseDoc !== null && responseDoc !== undefined) {
        var profileInstance = { tags: {} };
        result.profile = profileInstance;
        
        var propertiesValue3 = responseDoc['properties'];
        if (propertiesValue3 !== null && propertiesValue3 !== undefined) {
          var propertiesInstance = { endpoints: [] };
          profileInstance.properties = propertiesInstance;
          
          var profileStatusValue = propertiesValue3['profileStatus'];
          if (profileStatusValue !== null && profileStatusValue !== undefined) {
            var profileStatusInstance = profileStatusValue;
            propertiesInstance.profileStatus = profileStatusInstance;
          }
          
          var trafficRoutingMethodValue = propertiesValue3['trafficRoutingMethod'];
          if (trafficRoutingMethodValue !== null && trafficRoutingMethodValue !== undefined) {
            var trafficRoutingMethodInstance = trafficRoutingMethodValue;
            propertiesInstance.trafficRoutingMethod = trafficRoutingMethodInstance;
          }
          
          var dnsConfigValue2 = propertiesValue3['dnsConfig'];
          if (dnsConfigValue2 !== null && dnsConfigValue2 !== undefined) {
            var dnsConfigInstance = {};
            propertiesInstance.dnsConfig = dnsConfigInstance;
            
            var relativeNameValue = dnsConfigValue2['relativeName'];
            if (relativeNameValue !== null && relativeNameValue !== undefined) {
              var relativeNameInstance = relativeNameValue;
              dnsConfigInstance.relativeName = relativeNameInstance;
            }
            
            var fqdnValue = dnsConfigValue2['fqdn'];
            if (fqdnValue !== null && fqdnValue !== undefined) {
              var fqdnInstance = fqdnValue;
              dnsConfigInstance.fqdn = fqdnInstance;
            }
            
            var ttlValue = dnsConfigValue2['ttl'];
            if (ttlValue !== null && ttlValue !== undefined) {
              var ttlInstance = ttlValue;
              dnsConfigInstance.ttl = ttlInstance;
            }
          }
          
          var monitorConfigValue2 = propertiesValue3['monitorConfig'];
          if (monitorConfigValue2 !== null && monitorConfigValue2 !== undefined) {
            var monitorConfigInstance = {};
            propertiesInstance.monitorConfig = monitorConfigInstance;
            
            var profileMonitorStatusValue = monitorConfigValue2['profileMonitorStatus'];
            if (profileMonitorStatusValue !== null && profileMonitorStatusValue !== undefined) {
              var profileMonitorStatusInstance = profileMonitorStatusValue;
              monitorConfigInstance.profileMonitorStatus = profileMonitorStatusInstance;
            }
            
            var protocolValue = monitorConfigValue2['protocol'];
            if (protocolValue !== null && protocolValue !== undefined) {
              var protocolInstance = protocolValue;
              monitorConfigInstance.protocol = protocolInstance;
            }
            
            var portValue = monitorConfigValue2['port'];
            if (portValue !== null && portValue !== undefined) {
              var portInstance = portValue;
              monitorConfigInstance.port = portInstance;
            }
            
            var pathValue = monitorConfigValue2['path'];
            if (pathValue !== null && pathValue !== undefined) {
              var pathInstance = pathValue;
              monitorConfigInstance.path = pathInstance;
            }
          }
          
          var endpointsArray2 = propertiesValue3['endpoints'];
          if (endpointsArray2 !== null && endpointsArray2 !== undefined) {
            propertiesInstance.endpoints = [];
            for (var loweredIndex2 = 0; loweredIndex2 < endpointsArray2.length; loweredIndex2 = loweredIndex2 + 1) {
              var endpointsValue = endpointsArray2[loweredIndex2];
              var endpointInstance = {};
              propertiesInstance.endpoints.push(endpointInstance);
              
              var idValue = endpointsValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                endpointInstance.id = idInstance;
              }
              
              var nameValue = endpointsValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                endpointInstance.name = nameInstance;
              }
              
              var typeValue = endpointsValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                endpointInstance.type = typeInstance;
              }
              
              var propertiesValue4 = endpointsValue['properties'];
              if (propertiesValue4 !== null && propertiesValue4 !== undefined) {
                var propertiesInstance2 = {};
                endpointInstance.properties = propertiesInstance2;
                
                var targetResourceIdValue = propertiesValue4['targetResourceId'];
                if (targetResourceIdValue !== null && targetResourceIdValue !== undefined) {
                  var targetResourceIdInstance = targetResourceIdValue;
                  propertiesInstance2.targetResourceId = targetResourceIdInstance;
                }
                
                var targetValue = propertiesValue4['target'];
                if (targetValue !== null && targetValue !== undefined) {
                  var targetInstance = targetValue;
                  propertiesInstance2.target = targetInstance;
                }
                
                var endpointStatusValue = propertiesValue4['endpointStatus'];
                if (endpointStatusValue !== null && endpointStatusValue !== undefined) {
                  var endpointStatusInstance = endpointStatusValue;
                  propertiesInstance2.endpointStatus = endpointStatusInstance;
                }
                
                var weightValue = propertiesValue4['weight'];
                if (weightValue !== null && weightValue !== undefined) {
                  var weightInstance = weightValue;
                  propertiesInstance2.weight = weightInstance;
                }
                
                var priorityValue = propertiesValue4['priority'];
                if (priorityValue !== null && priorityValue !== undefined) {
                  var priorityInstance = priorityValue;
                  propertiesInstance2.priority = priorityInstance;
                }
                
                var endpointLocationValue = propertiesValue4['endpointLocation'];
                if (endpointLocationValue !== null && endpointLocationValue !== undefined) {
                  var endpointLocationInstance = endpointLocationValue;
                  propertiesInstance2.endpointLocation = endpointLocationInstance;
                }
                
                var endpointMonitorStatusValue = propertiesValue4['endpointMonitorStatus'];
                if (endpointMonitorStatusValue !== null && endpointMonitorStatusValue !== undefined) {
                  var endpointMonitorStatusInstance = endpointMonitorStatusValue;
                  propertiesInstance2.endpointMonitorStatus = endpointMonitorStatusInstance;
                }
                
                var minChildEndpointsValue = propertiesValue4['minChildEndpoints'];
                if (minChildEndpointsValue !== null && minChildEndpointsValue !== undefined) {
                  var minChildEndpointsInstance = minChildEndpointsValue;
                  propertiesInstance2.minChildEndpoints = minChildEndpointsInstance;
                }
              }
            }
          }
        }
        
        var idValue2 = responseDoc['id'];
        if (idValue2 !== null && idValue2 !== undefined) {
          var idInstance2 = idValue2;
          profileInstance.id = idInstance2;
        }
        
        var nameValue2 = responseDoc['name'];
        if (nameValue2 !== null && nameValue2 !== undefined) {
          var nameInstance2 = nameValue2;
          profileInstance.name = nameInstance2;
        }
        
        var typeValue2 = responseDoc['type'];
        if (typeValue2 !== null && typeValue2 !== undefined) {
          var typeInstance2 = typeValue2;
          profileInstance.type = typeInstance2;
        }
        
        var locationValue = responseDoc['location'];
        if (locationValue !== null && locationValue !== undefined) {
          var locationInstance = locationValue;
          profileInstance.location = locationInstance;
        }
        
        var tagsSequenceElement = responseDoc['tags'];
        if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
          for (var property in tagsSequenceElement) {
            var tagsKey2 = property;
            var tagsValue2 = tagsSequenceElement[property];
            profileInstance.tags[tagsKey2] = tagsValue2;
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Deletes a Traffic Manager profile.
   * 
   * @param {string} resourceGroupName The name of the resource group
   * containing the Traffic Manager profile to be deleted.
   * 
   * @param {string} profileName The name of the Traffic Manager profile to be
   * deleted.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.deleteMethod = function(resourceGroupName, profileName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.Network';
    url2 = url2 + '/trafficmanagerprofiles/';
    url2 = url2 + encodeURIComponent(profileName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'DELETE';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      result = {};
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Gets a Traffic Manager profile.
   * 
   * @param {string} resourceGroupName The name of the resource group
   * containing the Traffic Manager profile.
   * 
   * @param {string} profileName The name of the Traffic Manager profile.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.get = function(resourceGroupName, profileName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.Network';
    url2 = url2 + '/trafficmanagerprofiles/';
    url2 = url2 + encodeURIComponent(profileName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = null;
      if (responseContent) {
        responseDoc = JSON.parse(responseContent);
      }
      
      if (responseDoc !== null && responseDoc !== undefined) {
        var profileInstance = { tags: {} };
        result.profile = profileInstance;
        
        var propertiesValue = responseDoc['properties'];
        if (propertiesValue !== null && propertiesValue !== undefined) {
          var propertiesInstance = { endpoints: [] };
          profileInstance.properties = propertiesInstance;
          
          var profileStatusValue = propertiesValue['profileStatus'];
          if (profileStatusValue !== null && profileStatusValue !== undefined) {
            var profileStatusInstance = profileStatusValue;
            propertiesInstance.profileStatus = profileStatusInstance;
          }
          
          var trafficRoutingMethodValue = propertiesValue['trafficRoutingMethod'];
          if (trafficRoutingMethodValue !== null && trafficRoutingMethodValue !== undefined) {
            var trafficRoutingMethodInstance = trafficRoutingMethodValue;
            propertiesInstance.trafficRoutingMethod = trafficRoutingMethodInstance;
          }
          
          var dnsConfigValue = propertiesValue['dnsConfig'];
          if (dnsConfigValue !== null && dnsConfigValue !== undefined) {
            var dnsConfigInstance = {};
            propertiesInstance.dnsConfig = dnsConfigInstance;
            
            var relativeNameValue = dnsConfigValue['relativeName'];
            if (relativeNameValue !== null && relativeNameValue !== undefined) {
              var relativeNameInstance = relativeNameValue;
              dnsConfigInstance.relativeName = relativeNameInstance;
            }
            
            var fqdnValue = dnsConfigValue['fqdn'];
            if (fqdnValue !== null && fqdnValue !== undefined) {
              var fqdnInstance = fqdnValue;
              dnsConfigInstance.fqdn = fqdnInstance;
            }
            
            var ttlValue = dnsConfigValue['ttl'];
            if (ttlValue !== null && ttlValue !== undefined) {
              var ttlInstance = ttlValue;
              dnsConfigInstance.ttl = ttlInstance;
            }
          }
          
          var monitorConfigValue = propertiesValue['monitorConfig'];
          if (monitorConfigValue !== null && monitorConfigValue !== undefined) {
            var monitorConfigInstance = {};
            propertiesInstance.monitorConfig = monitorConfigInstance;
            
            var profileMonitorStatusValue = monitorConfigValue['profileMonitorStatus'];
            if (profileMonitorStatusValue !== null && profileMonitorStatusValue !== undefined) {
              var profileMonitorStatusInstance = profileMonitorStatusValue;
              monitorConfigInstance.profileMonitorStatus = profileMonitorStatusInstance;
            }
            
            var protocolValue = monitorConfigValue['protocol'];
            if (protocolValue !== null && protocolValue !== undefined) {
              var protocolInstance = protocolValue;
              monitorConfigInstance.protocol = protocolInstance;
            }
            
            var portValue = monitorConfigValue['port'];
            if (portValue !== null && portValue !== undefined) {
              var portInstance = portValue;
              monitorConfigInstance.port = portInstance;
            }
            
            var pathValue = monitorConfigValue['path'];
            if (pathValue !== null && pathValue !== undefined) {
              var pathInstance = pathValue;
              monitorConfigInstance.path = pathInstance;
            }
          }
          
          var endpointsArray = propertiesValue['endpoints'];
          if (endpointsArray !== null && endpointsArray !== undefined) {
            propertiesInstance.endpoints = [];
            for (var loweredIndex1 = 0; loweredIndex1 < endpointsArray.length; loweredIndex1 = loweredIndex1 + 1) {
              var endpointsValue = endpointsArray[loweredIndex1];
              var endpointInstance = {};
              propertiesInstance.endpoints.push(endpointInstance);
              
              var idValue = endpointsValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                endpointInstance.id = idInstance;
              }
              
              var nameValue = endpointsValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                endpointInstance.name = nameInstance;
              }
              
              var typeValue = endpointsValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                endpointInstance.type = typeInstance;
              }
              
              var propertiesValue2 = endpointsValue['properties'];
              if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
                var propertiesInstance2 = {};
                endpointInstance.properties = propertiesInstance2;
                
                var targetResourceIdValue = propertiesValue2['targetResourceId'];
                if (targetResourceIdValue !== null && targetResourceIdValue !== undefined) {
                  var targetResourceIdInstance = targetResourceIdValue;
                  propertiesInstance2.targetResourceId = targetResourceIdInstance;
                }
                
                var targetValue = propertiesValue2['target'];
                if (targetValue !== null && targetValue !== undefined) {
                  var targetInstance = targetValue;
                  propertiesInstance2.target = targetInstance;
                }
                
                var endpointStatusValue = propertiesValue2['endpointStatus'];
                if (endpointStatusValue !== null && endpointStatusValue !== undefined) {
                  var endpointStatusInstance = endpointStatusValue;
                  propertiesInstance2.endpointStatus = endpointStatusInstance;
                }
                
                var weightValue = propertiesValue2['weight'];
                if (weightValue !== null && weightValue !== undefined) {
                  var weightInstance = weightValue;
                  propertiesInstance2.weight = weightInstance;
                }
                
                var priorityValue = propertiesValue2['priority'];
                if (priorityValue !== null && priorityValue !== undefined) {
                  var priorityInstance = priorityValue;
                  propertiesInstance2.priority = priorityInstance;
                }
                
                var endpointLocationValue = propertiesValue2['endpointLocation'];
                if (endpointLocationValue !== null && endpointLocationValue !== undefined) {
                  var endpointLocationInstance = endpointLocationValue;
                  propertiesInstance2.endpointLocation = endpointLocationInstance;
                }
                
                var endpointMonitorStatusValue = propertiesValue2['endpointMonitorStatus'];
                if (endpointMonitorStatusValue !== null && endpointMonitorStatusValue !== undefined) {
                  var endpointMonitorStatusInstance = endpointMonitorStatusValue;
                  propertiesInstance2.endpointMonitorStatus = endpointMonitorStatusInstance;
                }
                
                var minChildEndpointsValue = propertiesValue2['minChildEndpoints'];
                if (minChildEndpointsValue !== null && minChildEndpointsValue !== undefined) {
                  var minChildEndpointsInstance = minChildEndpointsValue;
                  propertiesInstance2.minChildEndpoints = minChildEndpointsInstance;
                }
              }
            }
          }
        }
        
        var idValue2 = responseDoc['id'];
        if (idValue2 !== null && idValue2 !== undefined) {
          var idInstance2 = idValue2;
          profileInstance.id = idInstance2;
        }
        
        var nameValue2 = responseDoc['name'];
        if (nameValue2 !== null && nameValue2 !== undefined) {
          var nameInstance2 = nameValue2;
          profileInstance.name = nameInstance2;
        }
        
        var typeValue2 = responseDoc['type'];
        if (typeValue2 !== null && typeValue2 !== undefined) {
          var typeInstance2 = typeValue2;
          profileInstance.type = typeInstance2;
        }
        
        var locationValue = responseDoc['location'];
        if (locationValue !== null && locationValue !== undefined) {
          var locationInstance = locationValue;
          profileInstance.location = locationInstance;
        }
        
        var tagsSequenceElement = responseDoc['tags'];
        if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
          for (var property in tagsSequenceElement) {
            var tagsKey = property;
            var tagsValue = tagsSequenceElement[property];
            profileInstance.tags[tagsKey] = tagsValue;
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Lists all Traffic Manager profiles within a subscription.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.listAll = function(callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.Network';
    url2 = url2 + '/trafficmanagerprofiles';
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = { profiles: [] };
      var responseDoc = null;
      if (responseContent) {
        responseDoc = JSON.parse(responseContent);
      }
      
      if (responseDoc !== null && responseDoc !== undefined) {
        var valueArray = responseDoc['value'];
        if (valueArray !== null && valueArray !== undefined) {
          for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
            var valueValue = valueArray[loweredIndex1];
            var profileInstance = { tags: {} };
            result.profiles.push(profileInstance);
            
            var propertiesValue = valueValue['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = { endpoints: [] };
              profileInstance.properties = propertiesInstance;
              
              var profileStatusValue = propertiesValue['profileStatus'];
              if (profileStatusValue !== null && profileStatusValue !== undefined) {
                var profileStatusInstance = profileStatusValue;
                propertiesInstance.profileStatus = profileStatusInstance;
              }
              
              var trafficRoutingMethodValue = propertiesValue['trafficRoutingMethod'];
              if (trafficRoutingMethodValue !== null && trafficRoutingMethodValue !== undefined) {
                var trafficRoutingMethodInstance = trafficRoutingMethodValue;
                propertiesInstance.trafficRoutingMethod = trafficRoutingMethodInstance;
              }
              
              var dnsConfigValue = propertiesValue['dnsConfig'];
              if (dnsConfigValue !== null && dnsConfigValue !== undefined) {
                var dnsConfigInstance = {};
                propertiesInstance.dnsConfig = dnsConfigInstance;
                
                var relativeNameValue = dnsConfigValue['relativeName'];
                if (relativeNameValue !== null && relativeNameValue !== undefined) {
                  var relativeNameInstance = relativeNameValue;
                  dnsConfigInstance.relativeName = relativeNameInstance;
                }
                
                var fqdnValue = dnsConfigValue['fqdn'];
                if (fqdnValue !== null && fqdnValue !== undefined) {
                  var fqdnInstance = fqdnValue;
                  dnsConfigInstance.fqdn = fqdnInstance;
                }
                
                var ttlValue = dnsConfigValue['ttl'];
                if (ttlValue !== null && ttlValue !== undefined) {
                  var ttlInstance = ttlValue;
                  dnsConfigInstance.ttl = ttlInstance;
                }
              }
              
              var monitorConfigValue = propertiesValue['monitorConfig'];
              if (monitorConfigValue !== null && monitorConfigValue !== undefined) {
                var monitorConfigInstance = {};
                propertiesInstance.monitorConfig = monitorConfigInstance;
                
                var profileMonitorStatusValue = monitorConfigValue['profileMonitorStatus'];
                if (profileMonitorStatusValue !== null && profileMonitorStatusValue !== undefined) {
                  var profileMonitorStatusInstance = profileMonitorStatusValue;
                  monitorConfigInstance.profileMonitorStatus = profileMonitorStatusInstance;
                }
                
                var protocolValue = monitorConfigValue['protocol'];
                if (protocolValue !== null && protocolValue !== undefined) {
                  var protocolInstance = protocolValue;
                  monitorConfigInstance.protocol = protocolInstance;
                }
                
                var portValue = monitorConfigValue['port'];
                if (portValue !== null && portValue !== undefined) {
                  var portInstance = portValue;
                  monitorConfigInstance.port = portInstance;
                }
                
                var pathValue = monitorConfigValue['path'];
                if (pathValue !== null && pathValue !== undefined) {
                  var pathInstance = pathValue;
                  monitorConfigInstance.path = pathInstance;
                }
              }
              
              var endpointsArray = propertiesValue['endpoints'];
              if (endpointsArray !== null && endpointsArray !== undefined) {
                propertiesInstance.endpoints = [];
                for (var loweredIndex2 = 0; loweredIndex2 < endpointsArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var endpointsValue = endpointsArray[loweredIndex2];
                  var endpointInstance = {};
                  propertiesInstance.endpoints.push(endpointInstance);
                  
                  var idValue = endpointsValue['id'];
                  if (idValue !== null && idValue !== undefined) {
                    var idInstance = idValue;
                    endpointInstance.id = idInstance;
                  }
                  
                  var nameValue = endpointsValue['name'];
                  if (nameValue !== null && nameValue !== undefined) {
                    var nameInstance = nameValue;
                    endpointInstance.name = nameInstance;
                  }
                  
                  var typeValue = endpointsValue['type'];
                  if (typeValue !== null && typeValue !== undefined) {
                    var typeInstance = typeValue;
                    endpointInstance.type = typeInstance;
                  }
                  
                  var propertiesValue2 = endpointsValue['properties'];
                  if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
                    var propertiesInstance2 = {};
                    endpointInstance.properties = propertiesInstance2;
                    
                    var targetResourceIdValue = propertiesValue2['targetResourceId'];
                    if (targetResourceIdValue !== null && targetResourceIdValue !== undefined) {
                      var targetResourceIdInstance = targetResourceIdValue;
                      propertiesInstance2.targetResourceId = targetResourceIdInstance;
                    }
                    
                    var targetValue = propertiesValue2['target'];
                    if (targetValue !== null && targetValue !== undefined) {
                      var targetInstance = targetValue;
                      propertiesInstance2.target = targetInstance;
                    }
                    
                    var endpointStatusValue = propertiesValue2['endpointStatus'];
                    if (endpointStatusValue !== null && endpointStatusValue !== undefined) {
                      var endpointStatusInstance = endpointStatusValue;
                      propertiesInstance2.endpointStatus = endpointStatusInstance;
                    }
                    
                    var weightValue = propertiesValue2['weight'];
                    if (weightValue !== null && weightValue !== undefined) {
                      var weightInstance = weightValue;
                      propertiesInstance2.weight = weightInstance;
                    }
                    
                    var priorityValue = propertiesValue2['priority'];
                    if (priorityValue !== null && priorityValue !== undefined) {
                      var priorityInstance = priorityValue;
                      propertiesInstance2.priority = priorityInstance;
                    }
                    
                    var endpointLocationValue = propertiesValue2['endpointLocation'];
                    if (endpointLocationValue !== null && endpointLocationValue !== undefined) {
                      var endpointLocationInstance = endpointLocationValue;
                      propertiesInstance2.endpointLocation = endpointLocationInstance;
                    }
                    
                    var endpointMonitorStatusValue = propertiesValue2['endpointMonitorStatus'];
                    if (endpointMonitorStatusValue !== null && endpointMonitorStatusValue !== undefined) {
                      var endpointMonitorStatusInstance = endpointMonitorStatusValue;
                      propertiesInstance2.endpointMonitorStatus = endpointMonitorStatusInstance;
                    }
                    
                    var minChildEndpointsValue = propertiesValue2['minChildEndpoints'];
                    if (minChildEndpointsValue !== null && minChildEndpointsValue !== undefined) {
                      var minChildEndpointsInstance = minChildEndpointsValue;
                      propertiesInstance2.minChildEndpoints = minChildEndpointsInstance;
                    }
                  }
                }
              }
            }
            
            var idValue2 = valueValue['id'];
            if (idValue2 !== null && idValue2 !== undefined) {
              var idInstance2 = idValue2;
              profileInstance.id = idInstance2;
            }
            
            var nameValue2 = valueValue['name'];
            if (nameValue2 !== null && nameValue2 !== undefined) {
              var nameInstance2 = nameValue2;
              profileInstance.name = nameInstance2;
            }
            
            var typeValue2 = valueValue['type'];
            if (typeValue2 !== null && typeValue2 !== undefined) {
              var typeInstance2 = typeValue2;
              profileInstance.type = typeInstance2;
            }
            
            var locationValue = valueValue['location'];
            if (locationValue !== null && locationValue !== undefined) {
              var locationInstance = locationValue;
              profileInstance.location = locationInstance;
            }
            
            var tagsSequenceElement = valueValue['tags'];
            if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
              for (var property in tagsSequenceElement) {
                var tagsKey = property;
                var tagsValue = tagsSequenceElement[property];
                profileInstance.tags[tagsKey] = tagsValue;
              }
            }
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Lists all Traffic Manager profiles within a resource group.
   * 
   * @param {string} resourceGroupName The name of the resource group
   * containing the Traffic Manager profiles to be listed.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.listAllInResourceGroup = function(resourceGroupName, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.Network';
    url2 = url2 + '/trafficmanagerprofiles';
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = { profiles: [] };
      var responseDoc = null;
      if (responseContent) {
        responseDoc = JSON.parse(responseContent);
      }
      
      if (responseDoc !== null && responseDoc !== undefined) {
        var valueArray = responseDoc['value'];
        if (valueArray !== null && valueArray !== undefined) {
          for (var loweredIndex1 = 0; loweredIndex1 < valueArray.length; loweredIndex1 = loweredIndex1 + 1) {
            var valueValue = valueArray[loweredIndex1];
            var profileInstance = { tags: {} };
            result.profiles.push(profileInstance);
            
            var propertiesValue = valueValue['properties'];
            if (propertiesValue !== null && propertiesValue !== undefined) {
              var propertiesInstance = { endpoints: [] };
              profileInstance.properties = propertiesInstance;
              
              var profileStatusValue = propertiesValue['profileStatus'];
              if (profileStatusValue !== null && profileStatusValue !== undefined) {
                var profileStatusInstance = profileStatusValue;
                propertiesInstance.profileStatus = profileStatusInstance;
              }
              
              var trafficRoutingMethodValue = propertiesValue['trafficRoutingMethod'];
              if (trafficRoutingMethodValue !== null && trafficRoutingMethodValue !== undefined) {
                var trafficRoutingMethodInstance = trafficRoutingMethodValue;
                propertiesInstance.trafficRoutingMethod = trafficRoutingMethodInstance;
              }
              
              var dnsConfigValue = propertiesValue['dnsConfig'];
              if (dnsConfigValue !== null && dnsConfigValue !== undefined) {
                var dnsConfigInstance = {};
                propertiesInstance.dnsConfig = dnsConfigInstance;
                
                var relativeNameValue = dnsConfigValue['relativeName'];
                if (relativeNameValue !== null && relativeNameValue !== undefined) {
                  var relativeNameInstance = relativeNameValue;
                  dnsConfigInstance.relativeName = relativeNameInstance;
                }
                
                var fqdnValue = dnsConfigValue['fqdn'];
                if (fqdnValue !== null && fqdnValue !== undefined) {
                  var fqdnInstance = fqdnValue;
                  dnsConfigInstance.fqdn = fqdnInstance;
                }
                
                var ttlValue = dnsConfigValue['ttl'];
                if (ttlValue !== null && ttlValue !== undefined) {
                  var ttlInstance = ttlValue;
                  dnsConfigInstance.ttl = ttlInstance;
                }
              }
              
              var monitorConfigValue = propertiesValue['monitorConfig'];
              if (monitorConfigValue !== null && monitorConfigValue !== undefined) {
                var monitorConfigInstance = {};
                propertiesInstance.monitorConfig = monitorConfigInstance;
                
                var profileMonitorStatusValue = monitorConfigValue['profileMonitorStatus'];
                if (profileMonitorStatusValue !== null && profileMonitorStatusValue !== undefined) {
                  var profileMonitorStatusInstance = profileMonitorStatusValue;
                  monitorConfigInstance.profileMonitorStatus = profileMonitorStatusInstance;
                }
                
                var protocolValue = monitorConfigValue['protocol'];
                if (protocolValue !== null && protocolValue !== undefined) {
                  var protocolInstance = protocolValue;
                  monitorConfigInstance.protocol = protocolInstance;
                }
                
                var portValue = monitorConfigValue['port'];
                if (portValue !== null && portValue !== undefined) {
                  var portInstance = portValue;
                  monitorConfigInstance.port = portInstance;
                }
                
                var pathValue = monitorConfigValue['path'];
                if (pathValue !== null && pathValue !== undefined) {
                  var pathInstance = pathValue;
                  monitorConfigInstance.path = pathInstance;
                }
              }
              
              var endpointsArray = propertiesValue['endpoints'];
              if (endpointsArray !== null && endpointsArray !== undefined) {
                propertiesInstance.endpoints = [];
                for (var loweredIndex2 = 0; loweredIndex2 < endpointsArray.length; loweredIndex2 = loweredIndex2 + 1) {
                  var endpointsValue = endpointsArray[loweredIndex2];
                  var endpointInstance = {};
                  propertiesInstance.endpoints.push(endpointInstance);
                  
                  var idValue = endpointsValue['id'];
                  if (idValue !== null && idValue !== undefined) {
                    var idInstance = idValue;
                    endpointInstance.id = idInstance;
                  }
                  
                  var nameValue = endpointsValue['name'];
                  if (nameValue !== null && nameValue !== undefined) {
                    var nameInstance = nameValue;
                    endpointInstance.name = nameInstance;
                  }
                  
                  var typeValue = endpointsValue['type'];
                  if (typeValue !== null && typeValue !== undefined) {
                    var typeInstance = typeValue;
                    endpointInstance.type = typeInstance;
                  }
                  
                  var propertiesValue2 = endpointsValue['properties'];
                  if (propertiesValue2 !== null && propertiesValue2 !== undefined) {
                    var propertiesInstance2 = {};
                    endpointInstance.properties = propertiesInstance2;
                    
                    var targetResourceIdValue = propertiesValue2['targetResourceId'];
                    if (targetResourceIdValue !== null && targetResourceIdValue !== undefined) {
                      var targetResourceIdInstance = targetResourceIdValue;
                      propertiesInstance2.targetResourceId = targetResourceIdInstance;
                    }
                    
                    var targetValue = propertiesValue2['target'];
                    if (targetValue !== null && targetValue !== undefined) {
                      var targetInstance = targetValue;
                      propertiesInstance2.target = targetInstance;
                    }
                    
                    var endpointStatusValue = propertiesValue2['endpointStatus'];
                    if (endpointStatusValue !== null && endpointStatusValue !== undefined) {
                      var endpointStatusInstance = endpointStatusValue;
                      propertiesInstance2.endpointStatus = endpointStatusInstance;
                    }
                    
                    var weightValue = propertiesValue2['weight'];
                    if (weightValue !== null && weightValue !== undefined) {
                      var weightInstance = weightValue;
                      propertiesInstance2.weight = weightInstance;
                    }
                    
                    var priorityValue = propertiesValue2['priority'];
                    if (priorityValue !== null && priorityValue !== undefined) {
                      var priorityInstance = priorityValue;
                      propertiesInstance2.priority = priorityInstance;
                    }
                    
                    var endpointLocationValue = propertiesValue2['endpointLocation'];
                    if (endpointLocationValue !== null && endpointLocationValue !== undefined) {
                      var endpointLocationInstance = endpointLocationValue;
                      propertiesInstance2.endpointLocation = endpointLocationInstance;
                    }
                    
                    var endpointMonitorStatusValue = propertiesValue2['endpointMonitorStatus'];
                    if (endpointMonitorStatusValue !== null && endpointMonitorStatusValue !== undefined) {
                      var endpointMonitorStatusInstance = endpointMonitorStatusValue;
                      propertiesInstance2.endpointMonitorStatus = endpointMonitorStatusInstance;
                    }
                    
                    var minChildEndpointsValue = propertiesValue2['minChildEndpoints'];
                    if (minChildEndpointsValue !== null && minChildEndpointsValue !== undefined) {
                      var minChildEndpointsInstance = minChildEndpointsValue;
                      propertiesInstance2.minChildEndpoints = minChildEndpointsInstance;
                    }
                  }
                }
              }
            }
            
            var idValue2 = valueValue['id'];
            if (idValue2 !== null && idValue2 !== undefined) {
              var idInstance2 = idValue2;
              profileInstance.id = idInstance2;
            }
            
            var nameValue2 = valueValue['name'];
            if (nameValue2 !== null && nameValue2 !== undefined) {
              var nameInstance2 = nameValue2;
              profileInstance.name = nameInstance2;
            }
            
            var typeValue2 = valueValue['type'];
            if (typeValue2 !== null && typeValue2 !== undefined) {
              var typeInstance2 = typeValue2;
              profileInstance.type = typeInstance2;
            }
            
            var locationValue = valueValue['location'];
            if (locationValue !== null && locationValue !== undefined) {
              var locationInstance = locationValue;
              profileInstance.location = locationInstance;
            }
            
            var tagsSequenceElement = valueValue['tags'];
            if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
              for (var property in tagsSequenceElement) {
                var tagsKey = property;
                var tagsValue = tagsSequenceElement[property];
                profileInstance.tags[tagsKey] = tagsValue;
              }
            }
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  /**
   * Update a Traffic Manager profile.
   * 
   * @param {string} resourceGroupName The name of the resource group
   * containing the Traffic Manager profile.
   * 
   * @param {string} profileName The name of the Traffic Manager profile.
   * 
   * @param {ProfileUpdateParameters} parameters The Traffic Manager profile
   * parameters supplied to the Update operation.
   * 
   * @param {Profile} parameters.profile Gets or sets parameters for the
   * Traffic Manager profile being updated.
   * 
   * @param {ProfileProperties} [parameters.profile.properties] Gets or sets
   * the properties of the profile.
   * 
   * @param {string} [parameters.profile.properties.profileStatus] Gets or sets
   * the status of the Traffic Manager profile.  Possible values are 'Enabled'
   * and 'Disabled'.
   * 
   * @param {string} [parameters.profile.properties.trafficRoutingMethod] Gets
   * or sets the traffic routing method of the Traffic Manager profile.
   * Possible values are 'Performance', 'Weighted', or 'Priority'.
   * 
   * @param {DnsConfig} [parameters.profile.properties.dnsConfig] Gets or sets
   * the DNS settings of the Traffic Manager profile.
   * 
   * @param {string} [parameters.profile.properties.dnsConfig.relativeName]
   * Gets or sets the relative DNS name provided by this Traffic Manager
   * profile.  This value is combined with the DNS domain name used by Azure
   * Traffic Manager to form the fully-qualified domain name (FQDN) of the
   * profile.
   * 
   * @param {string} [parameters.profile.properties.dnsConfig.fqdn] Gets or
   * sets the fully-qualified domain name (FQDN) of the Traffic Manager
   * profile.  This is formed from the concatenation of the RelativeName with
   * the DNS domain used by Azure Traffic Manager.
   * 
   * @param {number} [parameters.profile.properties.dnsConfig.ttl] Gets or sets
   * the DNS Ttime-To-Live (TTL), in seconds.  This informs the local DNS
   * resolvers and DNS clients how long to cache DNS responses provided by
   * this Traffic Manager profile.
   * 
   * @param {MonitorConfig} [parameters.profile.properties.monitorConfig] Gets
   * or sets the endpoint monitoring settings of the Traffic Manager profile.
   * 
   * @param {string}
   * [parameters.profile.properties.monitorConfig.profileMonitorStatus] Gets
   * or sets the profile-level monitoring status of the Traffic Manager
   * profile.
   * 
   * @param {string} [parameters.profile.properties.monitorConfig.protocol]
   * Gets or sets the protocol (HTTP or HTTPS) used to probe for endpoint
   * health.
   * 
   * @param {number} [parameters.profile.properties.monitorConfig.port] Gets or
   * sets the TCP port used to probe for endpoint health.
   * 
   * @param {string} [parameters.profile.properties.monitorConfig.path] Gets or
   * sets the path relative to the endpoint domain name used to probe for
   * endpoint health.
   * 
   * @param {array} [parameters.profile.properties.endpoints] Gets or sets the
   * list of endpoints in the Traffic Manager profile.
   * 
   * @param {string} [parameters.profile.id] Gets or sets the ID of the
   * resource.
   * 
   * @param {string} [parameters.profile.name] Gets or sets the name of the
   * resource.
   * 
   * @param {string} [parameters.profile.type] Gets or sets the type of the
   * resource.
   * 
   * @param {string} parameters.profile.location Gets or sets the location of
   * the resource.
   * 
   * @param {object} [parameters.profile.tags] Gets or sets the tags attached
   * to the resource.
   * 
   * @param {function} callback
   * 
   * @returns {Stream} The response stream.
   */
  ProfileOperations.prototype.update = function(resourceGroupName, profileName, parameters, callback) {
    if (callback === null || callback === undefined) {
      throw new Error('callback cannot be null.');
    }
    // Validate
    if (resourceGroupName === null || resourceGroupName === undefined) {
      return callback(new Error('resourceGroupName cannot be null.'));
    }
    if (profileName === null || profileName === undefined) {
      return callback(new Error('profileName cannot be null.'));
    }
    if (parameters === null || parameters === undefined) {
      return callback(new Error('parameters cannot be null.'));
    }
    if (parameters.profile === null || parameters.profile === undefined) {
      return callback(new Error('parameters.profile cannot be null.'));
    }
    if (parameters.profile.location === null || parameters.profile.location === undefined) {
      return callback(new Error('parameters.profile.location cannot be null.'));
    }
    if (parameters.profile.properties !== null && parameters.profile.properties !== undefined) {
      if (parameters.profile.properties.dnsConfig !== null && parameters.profile.properties.dnsConfig !== undefined) {
        if (parameters.profile.properties.dnsConfig.relativeName === null || parameters.profile.properties.dnsConfig.relativeName === undefined) {
          return callback(new Error('parameters.profile.properties.dnsConfig.relativeName cannot be null.'));
        }
        if (parameters.profile.properties.dnsConfig.ttl === null || parameters.profile.properties.dnsConfig.ttl === undefined) {
          return callback(new Error('parameters.profile.properties.dnsConfig.ttl cannot be null.'));
        }
      }
      if (parameters.profile.properties.monitorConfig !== null && parameters.profile.properties.monitorConfig !== undefined) {
        if (parameters.profile.properties.monitorConfig.path === null || parameters.profile.properties.monitorConfig.path === undefined) {
          return callback(new Error('parameters.profile.properties.monitorConfig.path cannot be null.'));
        }
        if (parameters.profile.properties.monitorConfig.port === null || parameters.profile.properties.monitorConfig.port === undefined) {
          return callback(new Error('parameters.profile.properties.monitorConfig.port cannot be null.'));
        }
        if (parameters.profile.properties.monitorConfig.protocol === null || parameters.profile.properties.monitorConfig.protocol === undefined) {
          return callback(new Error('parameters.profile.properties.monitorConfig.protocol cannot be null.'));
        }
      }
    }
    
    // Tracing
    
    // Construct URL
    var url2 = '';
    url2 = url2 + '/subscriptions/';
    if (this.client.credentials.subscriptionId !== null && this.client.credentials.subscriptionId !== undefined) {
      url2 = url2 + encodeURIComponent(this.client.credentials.subscriptionId);
    }
    url2 = url2 + '/resourceGroups/';
    url2 = url2 + encodeURIComponent(resourceGroupName);
    url2 = url2 + '/providers/';
    url2 = url2 + 'Microsoft.Network';
    url2 = url2 + '/trafficmanagerprofiles/';
    url2 = url2 + encodeURIComponent(profileName);
    var queryParameters = [];
    queryParameters.push('api-version=2015-11-01');
    if (queryParameters.length > 0) {
      url2 = url2 + '?' + queryParameters.join('&');
    }
    var baseUrl = this.client.baseUri;
    // Trim '/' character from the end of baseUrl and beginning of url.
    if (baseUrl[baseUrl.length - 1] === '/') {
      baseUrl = baseUrl.substring(0, (baseUrl.length - 1) + 0);
    }
    if (url2[0] === '/') {
      url2 = url2.substring(1);
    }
    url2 = baseUrl + '/' + url2;
    url2 = url2.replace(' ', '%20');
    
    // Create HTTP transport objects
    var httpRequest = new WebResource();
    httpRequest.method = 'PATCH';
    httpRequest.headers = {};
    httpRequest.url = url2;
    
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    
    // Serialize Request
    var requestContent = null;
    var requestDoc = null;
    
    var profileUpdateParametersValue = {};
    requestDoc = profileUpdateParametersValue;
    
    if (parameters.profile.properties !== null && parameters.profile.properties !== undefined) {
      var propertiesValue = {};
      profileUpdateParametersValue['properties'] = propertiesValue;
      
      if (parameters.profile.properties.profileStatus !== null && parameters.profile.properties.profileStatus !== undefined) {
        propertiesValue['profileStatus'] = parameters.profile.properties.profileStatus;
      }
      
      if (parameters.profile.properties.trafficRoutingMethod !== null && parameters.profile.properties.trafficRoutingMethod !== undefined) {
        propertiesValue['trafficRoutingMethod'] = parameters.profile.properties.trafficRoutingMethod;
      }
      
      if (parameters.profile.properties.dnsConfig !== null && parameters.profile.properties.dnsConfig !== undefined) {
        var dnsConfigValue = {};
        propertiesValue['dnsConfig'] = dnsConfigValue;
        
        dnsConfigValue['relativeName'] = parameters.profile.properties.dnsConfig.relativeName;
        
        if (parameters.profile.properties.dnsConfig.fqdn !== null && parameters.profile.properties.dnsConfig.fqdn !== undefined) {
          dnsConfigValue['fqdn'] = parameters.profile.properties.dnsConfig.fqdn;
        }
        
        dnsConfigValue['ttl'] = parameters.profile.properties.dnsConfig.ttl;
      }
      
      if (parameters.profile.properties.monitorConfig !== null && parameters.profile.properties.monitorConfig !== undefined) {
        var monitorConfigValue = {};
        propertiesValue['monitorConfig'] = monitorConfigValue;
        
        if (parameters.profile.properties.monitorConfig.profileMonitorStatus !== null && parameters.profile.properties.monitorConfig.profileMonitorStatus !== undefined) {
          monitorConfigValue['profileMonitorStatus'] = parameters.profile.properties.monitorConfig.profileMonitorStatus;
        }
        
        monitorConfigValue['protocol'] = parameters.profile.properties.monitorConfig.protocol;
        
        monitorConfigValue['port'] = parameters.profile.properties.monitorConfig.port;
        
        monitorConfigValue['path'] = parameters.profile.properties.monitorConfig.path;
      }
      
      if (parameters.profile.properties.endpoints !== null && parameters.profile.properties.endpoints !== undefined) {
        var endpointsArray = [];
        for (var loweredIndex1 = 0; loweredIndex1 < parameters.profile.properties.endpoints.length; loweredIndex1 = loweredIndex1 + 1) {
          var endpointsItem = parameters.profile.properties.endpoints[loweredIndex1];
          var endpointValue = {};
          endpointsArray.push(endpointValue);
          
          if (endpointsItem.id !== null && endpointsItem.id !== undefined) {
            endpointValue['id'] = endpointsItem.id;
          }
          
          if (endpointsItem.name !== null && endpointsItem.name !== undefined) {
            endpointValue['name'] = endpointsItem.name;
          }
          
          if (endpointsItem.type !== null && endpointsItem.type !== undefined) {
            endpointValue['type'] = endpointsItem.type;
          }
          
          if (endpointsItem.properties !== null && endpointsItem.properties !== undefined) {
            var propertiesValue2 = {};
            endpointValue['properties'] = propertiesValue2;
            
            if (endpointsItem.properties.targetResourceId !== null && endpointsItem.properties.targetResourceId !== undefined) {
              propertiesValue2['targetResourceId'] = endpointsItem.properties.targetResourceId;
            }
            
            if (endpointsItem.properties.target !== null && endpointsItem.properties.target !== undefined) {
              propertiesValue2['target'] = endpointsItem.properties.target;
            }
            
            if (endpointsItem.properties.endpointStatus !== null && endpointsItem.properties.endpointStatus !== undefined) {
              propertiesValue2['endpointStatus'] = endpointsItem.properties.endpointStatus;
            }
            
            if (endpointsItem.properties.weight !== null && endpointsItem.properties.weight !== undefined) {
              propertiesValue2['weight'] = endpointsItem.properties.weight;
            }
            
            if (endpointsItem.properties.priority !== null && endpointsItem.properties.priority !== undefined) {
              propertiesValue2['priority'] = endpointsItem.properties.priority;
            }
            
            if (endpointsItem.properties.endpointLocation !== null && endpointsItem.properties.endpointLocation !== undefined) {
              propertiesValue2['endpointLocation'] = endpointsItem.properties.endpointLocation;
            }
            
            if (endpointsItem.properties.endpointMonitorStatus !== null && endpointsItem.properties.endpointMonitorStatus !== undefined) {
              propertiesValue2['endpointMonitorStatus'] = endpointsItem.properties.endpointMonitorStatus;
            }
            
            if (endpointsItem.properties.minChildEndpoints !== null && endpointsItem.properties.minChildEndpoints !== undefined) {
              propertiesValue2['minChildEndpoints'] = endpointsItem.properties.minChildEndpoints;
            }
          }
        }
        propertiesValue['endpoints'] = endpointsArray;
      }
    }
    
    if (parameters.profile.id !== null && parameters.profile.id !== undefined) {
      profileUpdateParametersValue['id'] = parameters.profile.id;
    }
    
    if (parameters.profile.name !== null && parameters.profile.name !== undefined) {
      profileUpdateParametersValue['name'] = parameters.profile.name;
    }
    
    if (parameters.profile.type !== null && parameters.profile.type !== undefined) {
      profileUpdateParametersValue['type'] = parameters.profile.type;
    }
    
    profileUpdateParametersValue['location'] = parameters.profile.location;
    
    if (parameters.profile.tags !== null && parameters.profile.tags !== undefined) {
      var tagsDictionary = {};
      for (var tagsKey in parameters.profile.tags) {
        var tagsValue = parameters.profile.tags[tagsKey];
        tagsDictionary[tagsKey] = tagsValue;
      }
      profileUpdateParametersValue['tags'] = tagsDictionary;
    }
    
    requestContent = JSON.stringify(requestDoc);
    httpRequest.body = requestContent;
    httpRequest.headers['Content-Length'] = Buffer.isBuffer(requestContent) ? requestContent.length : Buffer.byteLength(requestContent, 'UTF8');
    // Send Request
    return this.client.pipeline(httpRequest, function (err, response, body) {
      if (err !== null && err !== undefined) {
        return callback(err);
      }
      var statusCode = response.statusCode;
      if (statusCode >= 400) {
        var error = new Error(body);
        error.statusCode = response.statusCode;
        return callback(error);
      }
      
      // Create Result
      var result = null;
      // Deserialize Response
      var responseContent = body;
      result = {};
      var responseDoc = null;
      if (responseContent) {
        responseDoc = JSON.parse(responseContent);
      }
      
      var profileUpdateResponseValue = responseDoc['ProfileUpdateResponse'];
      if (profileUpdateResponseValue !== null && profileUpdateResponseValue !== undefined) {
        var profileUpdateResponseInstance = {};
        
        var profileInstance = { tags: {} };
        result.profile = profileInstance;
        
        var propertiesValue3 = profileUpdateResponseValue['properties'];
        if (propertiesValue3 !== null && propertiesValue3 !== undefined) {
          var propertiesInstance = { endpoints: [] };
          profileInstance.properties = propertiesInstance;
          
          var profileStatusValue = propertiesValue3['profileStatus'];
          if (profileStatusValue !== null && profileStatusValue !== undefined) {
            var profileStatusInstance = profileStatusValue;
            propertiesInstance.profileStatus = profileStatusInstance;
          }
          
          var trafficRoutingMethodValue = propertiesValue3['trafficRoutingMethod'];
          if (trafficRoutingMethodValue !== null && trafficRoutingMethodValue !== undefined) {
            var trafficRoutingMethodInstance = trafficRoutingMethodValue;
            propertiesInstance.trafficRoutingMethod = trafficRoutingMethodInstance;
          }
          
          var dnsConfigValue2 = propertiesValue3['dnsConfig'];
          if (dnsConfigValue2 !== null && dnsConfigValue2 !== undefined) {
            var dnsConfigInstance = {};
            propertiesInstance.dnsConfig = dnsConfigInstance;
            
            var relativeNameValue = dnsConfigValue2['relativeName'];
            if (relativeNameValue !== null && relativeNameValue !== undefined) {
              var relativeNameInstance = relativeNameValue;
              dnsConfigInstance.relativeName = relativeNameInstance;
            }
            
            var fqdnValue = dnsConfigValue2['fqdn'];
            if (fqdnValue !== null && fqdnValue !== undefined) {
              var fqdnInstance = fqdnValue;
              dnsConfigInstance.fqdn = fqdnInstance;
            }
            
            var ttlValue = dnsConfigValue2['ttl'];
            if (ttlValue !== null && ttlValue !== undefined) {
              var ttlInstance = ttlValue;
              dnsConfigInstance.ttl = ttlInstance;
            }
          }
          
          var monitorConfigValue2 = propertiesValue3['monitorConfig'];
          if (monitorConfigValue2 !== null && monitorConfigValue2 !== undefined) {
            var monitorConfigInstance = {};
            propertiesInstance.monitorConfig = monitorConfigInstance;
            
            var profileMonitorStatusValue = monitorConfigValue2['profileMonitorStatus'];
            if (profileMonitorStatusValue !== null && profileMonitorStatusValue !== undefined) {
              var profileMonitorStatusInstance = profileMonitorStatusValue;
              monitorConfigInstance.profileMonitorStatus = profileMonitorStatusInstance;
            }
            
            var protocolValue = monitorConfigValue2['protocol'];
            if (protocolValue !== null && protocolValue !== undefined) {
              var protocolInstance = protocolValue;
              monitorConfigInstance.protocol = protocolInstance;
            }
            
            var portValue = monitorConfigValue2['port'];
            if (portValue !== null && portValue !== undefined) {
              var portInstance = portValue;
              monitorConfigInstance.port = portInstance;
            }
            
            var pathValue = monitorConfigValue2['path'];
            if (pathValue !== null && pathValue !== undefined) {
              var pathInstance = pathValue;
              monitorConfigInstance.path = pathInstance;
            }
          }
          
          var endpointsArray2 = propertiesValue3['endpoints'];
          if (endpointsArray2 !== null && endpointsArray2 !== undefined) {
            propertiesInstance.endpoints = [];
            for (var loweredIndex2 = 0; loweredIndex2 < endpointsArray2.length; loweredIndex2 = loweredIndex2 + 1) {
              var endpointsValue = endpointsArray2[loweredIndex2];
              var endpointInstance = {};
              propertiesInstance.endpoints.push(endpointInstance);
              
              var idValue = endpointsValue['id'];
              if (idValue !== null && idValue !== undefined) {
                var idInstance = idValue;
                endpointInstance.id = idInstance;
              }
              
              var nameValue = endpointsValue['name'];
              if (nameValue !== null && nameValue !== undefined) {
                var nameInstance = nameValue;
                endpointInstance.name = nameInstance;
              }
              
              var typeValue = endpointsValue['type'];
              if (typeValue !== null && typeValue !== undefined) {
                var typeInstance = typeValue;
                endpointInstance.type = typeInstance;
              }
              
              var propertiesValue4 = endpointsValue['properties'];
              if (propertiesValue4 !== null && propertiesValue4 !== undefined) {
                var propertiesInstance2 = {};
                endpointInstance.properties = propertiesInstance2;
                
                var targetResourceIdValue = propertiesValue4['targetResourceId'];
                if (targetResourceIdValue !== null && targetResourceIdValue !== undefined) {
                  var targetResourceIdInstance = targetResourceIdValue;
                  propertiesInstance2.targetResourceId = targetResourceIdInstance;
                }
                
                var targetValue = propertiesValue4['target'];
                if (targetValue !== null && targetValue !== undefined) {
                  var targetInstance = targetValue;
                  propertiesInstance2.target = targetInstance;
                }
                
                var endpointStatusValue = propertiesValue4['endpointStatus'];
                if (endpointStatusValue !== null && endpointStatusValue !== undefined) {
                  var endpointStatusInstance = endpointStatusValue;
                  propertiesInstance2.endpointStatus = endpointStatusInstance;
                }
                
                var weightValue = propertiesValue4['weight'];
                if (weightValue !== null && weightValue !== undefined) {
                  var weightInstance = weightValue;
                  propertiesInstance2.weight = weightInstance;
                }
                
                var priorityValue = propertiesValue4['priority'];
                if (priorityValue !== null && priorityValue !== undefined) {
                  var priorityInstance = priorityValue;
                  propertiesInstance2.priority = priorityInstance;
                }
                
                var endpointLocationValue = propertiesValue4['endpointLocation'];
                if (endpointLocationValue !== null && endpointLocationValue !== undefined) {
                  var endpointLocationInstance = endpointLocationValue;
                  propertiesInstance2.endpointLocation = endpointLocationInstance;
                }
                
                var endpointMonitorStatusValue = propertiesValue4['endpointMonitorStatus'];
                if (endpointMonitorStatusValue !== null && endpointMonitorStatusValue !== undefined) {
                  var endpointMonitorStatusInstance = endpointMonitorStatusValue;
                  propertiesInstance2.endpointMonitorStatus = endpointMonitorStatusInstance;
                }
                
                var minChildEndpointsValue = propertiesValue4['minChildEndpoints'];
                if (minChildEndpointsValue !== null && minChildEndpointsValue !== undefined) {
                  var minChildEndpointsInstance = minChildEndpointsValue;
                  propertiesInstance2.minChildEndpoints = minChildEndpointsInstance;
                }
              }
            }
          }
        }
        
        var idValue2 = profileUpdateResponseValue['id'];
        if (idValue2 !== null && idValue2 !== undefined) {
          var idInstance2 = idValue2;
          profileInstance.id = idInstance2;
        }
        
        var nameValue2 = profileUpdateResponseValue['name'];
        if (nameValue2 !== null && nameValue2 !== undefined) {
          var nameInstance2 = nameValue2;
          profileInstance.name = nameInstance2;
        }
        
        var typeValue2 = profileUpdateResponseValue['type'];
        if (typeValue2 !== null && typeValue2 !== undefined) {
          var typeInstance2 = typeValue2;
          profileInstance.type = typeInstance2;
        }
        
        var locationValue = profileUpdateResponseValue['location'];
        if (locationValue !== null && locationValue !== undefined) {
          var locationInstance = locationValue;
          profileInstance.location = locationInstance;
        }
        
        var tagsSequenceElement = profileUpdateResponseValue['tags'];
        if (tagsSequenceElement !== null && tagsSequenceElement !== undefined) {
          for (var property in tagsSequenceElement) {
            var tagsKey2 = property;
            var tagsValue2 = tagsSequenceElement[property];
            profileInstance.tags[tagsKey2] = tagsValue2;
          }
        }
      }
      
      result.statusCode = statusCode;
      result.requestId = response.headers['x-ms-request-id'];
      
      return callback(null, result);
    });
  };
  
  return ProfileOperations;
})();
