/*
 * Copyright (c) Microsoft Corporation. All rights reserved.
 * Licensed under the MIT License. See License.txt in the project root for
 * license information.
 *
 * Code generated by Microsoft (R) AutoRest Code Generator.
 * Changes may cause incorrect behavior and will be lost if the code is
 * regenerated.
 */

'use strict';

const msRest = require('ms-rest');
const msRestAzure = require('ms-rest-azure');
const WebResource = msRest.WebResource;

/**
 * Checks the availability of a Traffic Manager Relative DNS name.
 *
 * @param {object} parameters The Traffic Manager name parameters supplied to
 * the CheckTrafficManagerNameAvailability operation.
 *
 * @param {string} [parameters.name] The name of the resource.
 *
 * @param {string} [parameters.type] The type of the resource.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link TrafficManagerNameAvailability} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _checkTrafficManagerRelativeDnsNameAvailability(parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'providers/Microsoft.Network/checkTrafficManagerNameAvailability';
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'POST';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  // Serialize Request
  let requestContent = null;
  let requestModel = null;
  try {
    if (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['CheckTrafficManagerRelativeDnsNameAvailabilityParameters']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['TrafficManagerNameAvailability']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * 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 {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link ProfileListResult} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listByResourceGroup(resourceGroupName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['ProfileListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * Lists all Traffic Manager profiles within a subscription.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link ProfileListResult} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listBySubscription(options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.Network/trafficmanagerprofiles';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['ProfileListResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * 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 {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link Profile} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _get(resourceGroupName, profileName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (profileName === null || profileName === undefined || typeof profileName.valueOf() !== 'string') {
      throw new Error('profileName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Profile']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * 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 {object} parameters The Traffic Manager profile parameters supplied
 * to the CreateOrUpdate operation.
 *
 * @param {string} [parameters.profileStatus] The status of the Traffic Manager
 * profile. Possible values include: 'Enabled', 'Disabled'
 *
 * @param {string} [parameters.trafficRoutingMethod] The traffic routing method
 * of the Traffic Manager profile. Possible values include: 'Performance',
 * 'Priority', 'Weighted', 'Geographic', 'MultiValue', 'Subnet'
 *
 * @param {object} [parameters.dnsConfig] The DNS settings of the Traffic
 * Manager profile.
 *
 * @param {string} [parameters.dnsConfig.relativeName] 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 {number} [parameters.dnsConfig.ttl] The DNS Time-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 {object} [parameters.monitorConfig] The endpoint monitoring settings
 * of the Traffic Manager profile.
 *
 * @param {string} [parameters.monitorConfig.profileMonitorStatus] The
 * profile-level monitoring status of the Traffic Manager profile. Possible
 * values include: 'CheckingEndpoints', 'Online', 'Degraded', 'Disabled',
 * 'Inactive'
 *
 * @param {string} [parameters.monitorConfig.protocol] The protocol (HTTP,
 * HTTPS or TCP) used to probe for endpoint health. Possible values include:
 * 'HTTP', 'HTTPS', 'TCP'
 *
 * @param {number} [parameters.monitorConfig.port] The TCP port used to probe
 * for endpoint health.
 *
 * @param {string} [parameters.monitorConfig.path] The path relative to the
 * endpoint domain name used to probe for endpoint health.
 *
 * @param {number} [parameters.monitorConfig.intervalInSeconds] The monitor
 * interval for endpoints in this profile. This is the interval at which
 * Traffic Manager will check the health of each endpoint in this profile.
 *
 * @param {number} [parameters.monitorConfig.timeoutInSeconds] The monitor
 * timeout for endpoints in this profile. This is the time that Traffic Manager
 * allows endpoints in this profile to response to the health check.
 *
 * @param {number} [parameters.monitorConfig.toleratedNumberOfFailures] The
 * number of consecutive failed health check that Traffic Manager tolerates
 * before declaring an endpoint in this profile Degraded after the next failed
 * health check.
 *
 * @param {array} [parameters.monitorConfig.expectedStatusCodeRanges] List of
 * expected status code ranges.
 *
 * @param {array} [parameters.monitorConfig.customHeaders] List of custom
 * headers.
 *
 * @param {array} [parameters.endpoints] The list of endpoints in the Traffic
 * Manager profile.
 *
 * @param {string} [parameters.trafficViewEnrollmentStatus] Indicates whether
 * Traffic View is 'Enabled' or 'Disabled' for the Traffic Manager profile.
 * Null, indicates 'Disabled'. Enabling this feature will increase the cost of
 * the Traffic Manage profile. Possible values include: 'Enabled', 'Disabled'
 *
 * @param {number} [parameters.maxReturn] Maximum number of endpoints to be
 * returned for MultiValue routing type.
 *
 * @param {object} [parameters.tags] Resource tags.
 *
 * @param {string} [parameters.location] The Azure Region where the resource
 * lives
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link Profile} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _createOrUpdate(resourceGroupName, profileName, parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (profileName === null || profileName === undefined || typeof profileName.valueOf() !== 'string') {
      throw new Error('profileName cannot be null or undefined and it must be of type string.');
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'PUT';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  // Serialize Request
  let requestContent = null;
  let requestModel = null;
  try {
    if (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['Profile']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200 && statusCode !== 201) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Profile']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }
    // Deserialize Response
    if (statusCode === 201) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Profile']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError1 = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError1.request = msRest.stripRequest(httpRequest);
        deserializationError1.response = msRest.stripResponse(response);
        return callback(deserializationError1);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * 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 {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link DeleteOperationResult} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _deleteMethod(resourceGroupName, profileName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (profileName === null || profileName === undefined || typeof profileName.valueOf() !== 'string') {
      throw new Error('profileName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'DELETE';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200 && statusCode !== 204) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['DeleteOperationResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/**
 * 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 {object} parameters The Traffic Manager profile parameters supplied
 * to the Update operation.
 *
 * @param {string} [parameters.profileStatus] The status of the Traffic Manager
 * profile. Possible values include: 'Enabled', 'Disabled'
 *
 * @param {string} [parameters.trafficRoutingMethod] The traffic routing method
 * of the Traffic Manager profile. Possible values include: 'Performance',
 * 'Priority', 'Weighted', 'Geographic', 'MultiValue', 'Subnet'
 *
 * @param {object} [parameters.dnsConfig] The DNS settings of the Traffic
 * Manager profile.
 *
 * @param {string} [parameters.dnsConfig.relativeName] 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 {number} [parameters.dnsConfig.ttl] The DNS Time-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 {object} [parameters.monitorConfig] The endpoint monitoring settings
 * of the Traffic Manager profile.
 *
 * @param {string} [parameters.monitorConfig.profileMonitorStatus] The
 * profile-level monitoring status of the Traffic Manager profile. Possible
 * values include: 'CheckingEndpoints', 'Online', 'Degraded', 'Disabled',
 * 'Inactive'
 *
 * @param {string} [parameters.monitorConfig.protocol] The protocol (HTTP,
 * HTTPS or TCP) used to probe for endpoint health. Possible values include:
 * 'HTTP', 'HTTPS', 'TCP'
 *
 * @param {number} [parameters.monitorConfig.port] The TCP port used to probe
 * for endpoint health.
 *
 * @param {string} [parameters.monitorConfig.path] The path relative to the
 * endpoint domain name used to probe for endpoint health.
 *
 * @param {number} [parameters.monitorConfig.intervalInSeconds] The monitor
 * interval for endpoints in this profile. This is the interval at which
 * Traffic Manager will check the health of each endpoint in this profile.
 *
 * @param {number} [parameters.monitorConfig.timeoutInSeconds] The monitor
 * timeout for endpoints in this profile. This is the time that Traffic Manager
 * allows endpoints in this profile to response to the health check.
 *
 * @param {number} [parameters.monitorConfig.toleratedNumberOfFailures] The
 * number of consecutive failed health check that Traffic Manager tolerates
 * before declaring an endpoint in this profile Degraded after the next failed
 * health check.
 *
 * @param {array} [parameters.monitorConfig.expectedStatusCodeRanges] List of
 * expected status code ranges.
 *
 * @param {array} [parameters.monitorConfig.customHeaders] List of custom
 * headers.
 *
 * @param {array} [parameters.endpoints] The list of endpoints in the Traffic
 * Manager profile.
 *
 * @param {string} [parameters.trafficViewEnrollmentStatus] Indicates whether
 * Traffic View is 'Enabled' or 'Disabled' for the Traffic Manager profile.
 * Null, indicates 'Disabled'. Enabling this feature will increase the cost of
 * the Traffic Manage profile. Possible values include: 'Enabled', 'Disabled'
 *
 * @param {number} [parameters.maxReturn] Maximum number of endpoints to be
 * returned for MultiValue routing type.
 *
 * @param {object} [parameters.tags] Resource tags.
 *
 * @param {string} [parameters.location] The Azure Region where the resource
 * lives
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link Profile} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _update(resourceGroupName, profileName, parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (profileName === null || profileName === undefined || typeof profileName.valueOf() !== 'string') {
      throw new Error('profileName cannot be null or undefined and it must be of type string.');
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/trafficmanagerprofiles/{profileName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'PATCH';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  // Serialize Request
  let requestContent = null;
  let requestModel = null;
  try {
    if (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['Profile']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Profile']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

    return callback(null, result, httpRequest, response);
  });
}

/** Class representing a Profiles. */
class Profiles {
  /**
   * Create a Profiles.
   * @param {TrafficManagerManagementClient} client Reference to the service client.
   */
  constructor(client) {
    this.client = client;
    this._checkTrafficManagerRelativeDnsNameAvailability = _checkTrafficManagerRelativeDnsNameAvailability;
    this._listByResourceGroup = _listByResourceGroup;
    this._listBySubscription = _listBySubscription;
    this._get = _get;
    this._createOrUpdate = _createOrUpdate;
    this._deleteMethod = _deleteMethod;
    this._update = _update;
  }

  /**
   * Checks the availability of a Traffic Manager Relative DNS name.
   *
   * @param {object} parameters The Traffic Manager name parameters supplied to
   * the CheckTrafficManagerNameAvailability operation.
   *
   * @param {string} [parameters.name] The name of the resource.
   *
   * @param {string} [parameters.type] The type of the resource.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<TrafficManagerNameAvailability>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  checkTrafficManagerRelativeDnsNameAvailabilityWithHttpOperationResponse(parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._checkTrafficManagerRelativeDnsNameAvailability(parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Checks the availability of a Traffic Manager Relative DNS name.
   *
   * @param {object} parameters The Traffic Manager name parameters supplied to
   * the CheckTrafficManagerNameAvailability operation.
   *
   * @param {string} [parameters.name] The name of the resource.
   *
   * @param {string} [parameters.type] The type of the resource.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {TrafficManagerNameAvailability} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link TrafficManagerNameAvailability} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  checkTrafficManagerRelativeDnsNameAvailability(parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._checkTrafficManagerRelativeDnsNameAvailability(parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._checkTrafficManagerRelativeDnsNameAvailability(parameters, options, optionalCallback);
    }
  }

  /**
   * 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 {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ProfileListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByResourceGroupWithHttpOperationResponse(resourceGroupName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByResourceGroup(resourceGroupName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * 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 {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {ProfileListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link ProfileListResult} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listByResourceGroup(resourceGroupName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listByResourceGroup(resourceGroupName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByResourceGroup(resourceGroupName, options, optionalCallback);
    }
  }

  /**
   * Lists all Traffic Manager profiles within a subscription.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ProfileListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listBySubscriptionWithHttpOperationResponse(options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listBySubscription(options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Lists all Traffic Manager profiles within a subscription.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {ProfileListResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link ProfileListResult} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listBySubscription(options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listBySubscription(options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listBySubscription(options, optionalCallback);
    }
  }

  /**
   * 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 {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<Profile>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getWithHttpOperationResponse(resourceGroupName, profileName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._get(resourceGroupName, profileName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * 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 {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {Profile} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link Profile} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  get(resourceGroupName, profileName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._get(resourceGroupName, profileName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._get(resourceGroupName, profileName, options, optionalCallback);
    }
  }

  /**
   * 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 {object} parameters The Traffic Manager profile parameters supplied
   * to the CreateOrUpdate operation.
   *
   * @param {string} [parameters.profileStatus] The status of the Traffic Manager
   * profile. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {string} [parameters.trafficRoutingMethod] The traffic routing method
   * of the Traffic Manager profile. Possible values include: 'Performance',
   * 'Priority', 'Weighted', 'Geographic', 'MultiValue', 'Subnet'
   *
   * @param {object} [parameters.dnsConfig] The DNS settings of the Traffic
   * Manager profile.
   *
   * @param {string} [parameters.dnsConfig.relativeName] 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 {number} [parameters.dnsConfig.ttl] The DNS Time-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 {object} [parameters.monitorConfig] The endpoint monitoring settings
   * of the Traffic Manager profile.
   *
   * @param {string} [parameters.monitorConfig.profileMonitorStatus] The
   * profile-level monitoring status of the Traffic Manager profile. Possible
   * values include: 'CheckingEndpoints', 'Online', 'Degraded', 'Disabled',
   * 'Inactive'
   *
   * @param {string} [parameters.monitorConfig.protocol] The protocol (HTTP,
   * HTTPS or TCP) used to probe for endpoint health. Possible values include:
   * 'HTTP', 'HTTPS', 'TCP'
   *
   * @param {number} [parameters.monitorConfig.port] The TCP port used to probe
   * for endpoint health.
   *
   * @param {string} [parameters.monitorConfig.path] The path relative to the
   * endpoint domain name used to probe for endpoint health.
   *
   * @param {number} [parameters.monitorConfig.intervalInSeconds] The monitor
   * interval for endpoints in this profile. This is the interval at which
   * Traffic Manager will check the health of each endpoint in this profile.
   *
   * @param {number} [parameters.monitorConfig.timeoutInSeconds] The monitor
   * timeout for endpoints in this profile. This is the time that Traffic Manager
   * allows endpoints in this profile to response to the health check.
   *
   * @param {number} [parameters.monitorConfig.toleratedNumberOfFailures] The
   * number of consecutive failed health check that Traffic Manager tolerates
   * before declaring an endpoint in this profile Degraded after the next failed
   * health check.
   *
   * @param {array} [parameters.monitorConfig.expectedStatusCodeRanges] List of
   * expected status code ranges.
   *
   * @param {array} [parameters.monitorConfig.customHeaders] List of custom
   * headers.
   *
   * @param {array} [parameters.endpoints] The list of endpoints in the Traffic
   * Manager profile.
   *
   * @param {string} [parameters.trafficViewEnrollmentStatus] Indicates whether
   * Traffic View is 'Enabled' or 'Disabled' for the Traffic Manager profile.
   * Null, indicates 'Disabled'. Enabling this feature will increase the cost of
   * the Traffic Manage profile. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {number} [parameters.maxReturn] Maximum number of endpoints to be
   * returned for MultiValue routing type.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @param {string} [parameters.location] The Azure Region where the resource
   * lives
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<Profile>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createOrUpdateWithHttpOperationResponse(resourceGroupName, profileName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._createOrUpdate(resourceGroupName, profileName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * 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 {object} parameters The Traffic Manager profile parameters supplied
   * to the CreateOrUpdate operation.
   *
   * @param {string} [parameters.profileStatus] The status of the Traffic Manager
   * profile. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {string} [parameters.trafficRoutingMethod] The traffic routing method
   * of the Traffic Manager profile. Possible values include: 'Performance',
   * 'Priority', 'Weighted', 'Geographic', 'MultiValue', 'Subnet'
   *
   * @param {object} [parameters.dnsConfig] The DNS settings of the Traffic
   * Manager profile.
   *
   * @param {string} [parameters.dnsConfig.relativeName] 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 {number} [parameters.dnsConfig.ttl] The DNS Time-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 {object} [parameters.monitorConfig] The endpoint monitoring settings
   * of the Traffic Manager profile.
   *
   * @param {string} [parameters.monitorConfig.profileMonitorStatus] The
   * profile-level monitoring status of the Traffic Manager profile. Possible
   * values include: 'CheckingEndpoints', 'Online', 'Degraded', 'Disabled',
   * 'Inactive'
   *
   * @param {string} [parameters.monitorConfig.protocol] The protocol (HTTP,
   * HTTPS or TCP) used to probe for endpoint health. Possible values include:
   * 'HTTP', 'HTTPS', 'TCP'
   *
   * @param {number} [parameters.monitorConfig.port] The TCP port used to probe
   * for endpoint health.
   *
   * @param {string} [parameters.monitorConfig.path] The path relative to the
   * endpoint domain name used to probe for endpoint health.
   *
   * @param {number} [parameters.monitorConfig.intervalInSeconds] The monitor
   * interval for endpoints in this profile. This is the interval at which
   * Traffic Manager will check the health of each endpoint in this profile.
   *
   * @param {number} [parameters.monitorConfig.timeoutInSeconds] The monitor
   * timeout for endpoints in this profile. This is the time that Traffic Manager
   * allows endpoints in this profile to response to the health check.
   *
   * @param {number} [parameters.monitorConfig.toleratedNumberOfFailures] The
   * number of consecutive failed health check that Traffic Manager tolerates
   * before declaring an endpoint in this profile Degraded after the next failed
   * health check.
   *
   * @param {array} [parameters.monitorConfig.expectedStatusCodeRanges] List of
   * expected status code ranges.
   *
   * @param {array} [parameters.monitorConfig.customHeaders] List of custom
   * headers.
   *
   * @param {array} [parameters.endpoints] The list of endpoints in the Traffic
   * Manager profile.
   *
   * @param {string} [parameters.trafficViewEnrollmentStatus] Indicates whether
   * Traffic View is 'Enabled' or 'Disabled' for the Traffic Manager profile.
   * Null, indicates 'Disabled'. Enabling this feature will increase the cost of
   * the Traffic Manage profile. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {number} [parameters.maxReturn] Maximum number of endpoints to be
   * returned for MultiValue routing type.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @param {string} [parameters.location] The Azure Region where the resource
   * lives
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {Profile} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link Profile} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  createOrUpdate(resourceGroupName, profileName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._createOrUpdate(resourceGroupName, profileName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._createOrUpdate(resourceGroupName, profileName, parameters, options, optionalCallback);
    }
  }

  /**
   * 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 {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<DeleteOperationResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  deleteMethodWithHttpOperationResponse(resourceGroupName, profileName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._deleteMethod(resourceGroupName, profileName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * 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 {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {DeleteOperationResult} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link DeleteOperationResult} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  deleteMethod(resourceGroupName, profileName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._deleteMethod(resourceGroupName, profileName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._deleteMethod(resourceGroupName, profileName, options, optionalCallback);
    }
  }

  /**
   * 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 {object} parameters The Traffic Manager profile parameters supplied
   * to the Update operation.
   *
   * @param {string} [parameters.profileStatus] The status of the Traffic Manager
   * profile. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {string} [parameters.trafficRoutingMethod] The traffic routing method
   * of the Traffic Manager profile. Possible values include: 'Performance',
   * 'Priority', 'Weighted', 'Geographic', 'MultiValue', 'Subnet'
   *
   * @param {object} [parameters.dnsConfig] The DNS settings of the Traffic
   * Manager profile.
   *
   * @param {string} [parameters.dnsConfig.relativeName] 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 {number} [parameters.dnsConfig.ttl] The DNS Time-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 {object} [parameters.monitorConfig] The endpoint monitoring settings
   * of the Traffic Manager profile.
   *
   * @param {string} [parameters.monitorConfig.profileMonitorStatus] The
   * profile-level monitoring status of the Traffic Manager profile. Possible
   * values include: 'CheckingEndpoints', 'Online', 'Degraded', 'Disabled',
   * 'Inactive'
   *
   * @param {string} [parameters.monitorConfig.protocol] The protocol (HTTP,
   * HTTPS or TCP) used to probe for endpoint health. Possible values include:
   * 'HTTP', 'HTTPS', 'TCP'
   *
   * @param {number} [parameters.monitorConfig.port] The TCP port used to probe
   * for endpoint health.
   *
   * @param {string} [parameters.monitorConfig.path] The path relative to the
   * endpoint domain name used to probe for endpoint health.
   *
   * @param {number} [parameters.monitorConfig.intervalInSeconds] The monitor
   * interval for endpoints in this profile. This is the interval at which
   * Traffic Manager will check the health of each endpoint in this profile.
   *
   * @param {number} [parameters.monitorConfig.timeoutInSeconds] The monitor
   * timeout for endpoints in this profile. This is the time that Traffic Manager
   * allows endpoints in this profile to response to the health check.
   *
   * @param {number} [parameters.monitorConfig.toleratedNumberOfFailures] The
   * number of consecutive failed health check that Traffic Manager tolerates
   * before declaring an endpoint in this profile Degraded after the next failed
   * health check.
   *
   * @param {array} [parameters.monitorConfig.expectedStatusCodeRanges] List of
   * expected status code ranges.
   *
   * @param {array} [parameters.monitorConfig.customHeaders] List of custom
   * headers.
   *
   * @param {array} [parameters.endpoints] The list of endpoints in the Traffic
   * Manager profile.
   *
   * @param {string} [parameters.trafficViewEnrollmentStatus] Indicates whether
   * Traffic View is 'Enabled' or 'Disabled' for the Traffic Manager profile.
   * Null, indicates 'Disabled'. Enabling this feature will increase the cost of
   * the Traffic Manage profile. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {number} [parameters.maxReturn] Maximum number of endpoints to be
   * returned for MultiValue routing type.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @param {string} [parameters.location] The Azure Region where the resource
   * lives
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<Profile>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  updateWithHttpOperationResponse(resourceGroupName, profileName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._update(resourceGroupName, profileName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * 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 {object} parameters The Traffic Manager profile parameters supplied
   * to the Update operation.
   *
   * @param {string} [parameters.profileStatus] The status of the Traffic Manager
   * profile. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {string} [parameters.trafficRoutingMethod] The traffic routing method
   * of the Traffic Manager profile. Possible values include: 'Performance',
   * 'Priority', 'Weighted', 'Geographic', 'MultiValue', 'Subnet'
   *
   * @param {object} [parameters.dnsConfig] The DNS settings of the Traffic
   * Manager profile.
   *
   * @param {string} [parameters.dnsConfig.relativeName] 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 {number} [parameters.dnsConfig.ttl] The DNS Time-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 {object} [parameters.monitorConfig] The endpoint monitoring settings
   * of the Traffic Manager profile.
   *
   * @param {string} [parameters.monitorConfig.profileMonitorStatus] The
   * profile-level monitoring status of the Traffic Manager profile. Possible
   * values include: 'CheckingEndpoints', 'Online', 'Degraded', 'Disabled',
   * 'Inactive'
   *
   * @param {string} [parameters.monitorConfig.protocol] The protocol (HTTP,
   * HTTPS or TCP) used to probe for endpoint health. Possible values include:
   * 'HTTP', 'HTTPS', 'TCP'
   *
   * @param {number} [parameters.monitorConfig.port] The TCP port used to probe
   * for endpoint health.
   *
   * @param {string} [parameters.monitorConfig.path] The path relative to the
   * endpoint domain name used to probe for endpoint health.
   *
   * @param {number} [parameters.monitorConfig.intervalInSeconds] The monitor
   * interval for endpoints in this profile. This is the interval at which
   * Traffic Manager will check the health of each endpoint in this profile.
   *
   * @param {number} [parameters.monitorConfig.timeoutInSeconds] The monitor
   * timeout for endpoints in this profile. This is the time that Traffic Manager
   * allows endpoints in this profile to response to the health check.
   *
   * @param {number} [parameters.monitorConfig.toleratedNumberOfFailures] The
   * number of consecutive failed health check that Traffic Manager tolerates
   * before declaring an endpoint in this profile Degraded after the next failed
   * health check.
   *
   * @param {array} [parameters.monitorConfig.expectedStatusCodeRanges] List of
   * expected status code ranges.
   *
   * @param {array} [parameters.monitorConfig.customHeaders] List of custom
   * headers.
   *
   * @param {array} [parameters.endpoints] The list of endpoints in the Traffic
   * Manager profile.
   *
   * @param {string} [parameters.trafficViewEnrollmentStatus] Indicates whether
   * Traffic View is 'Enabled' or 'Disabled' for the Traffic Manager profile.
   * Null, indicates 'Disabled'. Enabling this feature will increase the cost of
   * the Traffic Manage profile. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {number} [parameters.maxReturn] Maximum number of endpoints to be
   * returned for MultiValue routing type.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @param {string} [parameters.location] The Azure Region where the resource
   * lives
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {Profile} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {object} [result]   - The deserialized result object if an error did not occur.
   *                      See {@link Profile} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  update(resourceGroupName, profileName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._update(resourceGroupName, profileName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._update(resourceGroupName, profileName, parameters, options, optionalCallback);
    }
  }

}

module.exports = Profiles;
