/*
 * 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;

/**
 * Lists existing CDN endpoints.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @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 EndpointListResult} 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 _listByProfile(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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    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.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.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('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints';
  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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['EndpointListResult']().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 an existing CDN endpoint with the specified endpoint name under the
 * specified subscription, resource group and profile.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @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 Endpoint} 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, endpointName, 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    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 (endpointName === null || endpointName === undefined || typeof endpointName.valueOf() !== 'string') {
      throw new Error('endpointName 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.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('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{endpointName}', encodeURIComponent(endpointName));
  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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['Endpoint']().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);
  });
}


/**
 * Creates a new CDN endpoint with the specified endpoint name under the
 * specified subscription, resource group and profile.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @param {object} endpoint Endpoint properties
 *
 * @param {string} [endpoint.originHostHeader] The host header value sent to
 * the origin with each request. If you leave this blank, the request hostname
 * determines this value. Azure CDN origins, such as Web Apps, Blob Storage,
 * and Cloud Services require this host header value to match the origin
 * hostname by default.
 *
 * @param {string} [endpoint.originPath] A directory path on the origin that
 * CDN can use to retrieve content from, e.g. contoso.cloudapp.net/originpath.
 *
 * @param {array} [endpoint.contentTypesToCompress] List of content types on
 * which compression applies. The value should be a valid MIME type.
 *
 * @param {boolean} [endpoint.isCompressionEnabled] Indicates whether content
 * compression is enabled on CDN. Default value is false. If compression is
 * enabled, content will be served as compressed if user requests for a
 * compressed version. Content won't be compressed on CDN when requested
 * content is smaller than 1 byte or larger than 1 MB.
 *
 * @param {boolean} [endpoint.isHttpAllowed] Indicates whether HTTP traffic is
 * allowed on the endpoint. Default value is true. At least one protocol (HTTP
 * or HTTPS) must be allowed.
 *
 * @param {boolean} [endpoint.isHttpsAllowed] Indicates whether HTTPS traffic
 * is allowed on the endpoint. Default value is true. At least one protocol
 * (HTTP or HTTPS) must be allowed.
 *
 * @param {string} [endpoint.queryStringCachingBehavior] Defines how CDN caches
 * requests that include query strings. You can ignore any query strings when
 * caching, bypass caching to prevent requests that contain query strings from
 * being cached, or cache every request with a unique URL. Possible values
 * include: 'IgnoreQueryString', 'BypassCaching', 'UseQueryString', 'NotSet'
 *
 * @param {string} [endpoint.optimizationType] Specifies what scenario the
 * customer wants this CDN endpoint to optimize for, e.g. Download, Media
 * services. With this information, CDN can apply scenario driven optimization.
 * Possible values include: 'GeneralWebDelivery', 'GeneralMediaStreaming',
 * 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
 * 'DynamicSiteAcceleration'
 *
 * @param {string} [endpoint.probePath] Path to a file hosted on the origin
 * which helps accelerate delivery of the dynamic content and calculate the
 * most optimal routes for the CDN. This is relative to the origin path.
 *
 * @param {array} [endpoint.geoFilters] List of rules defining the user's geo
 * access within a CDN endpoint. Each geo filter defines an access rule to a
 * specified path or content, e.g. block APAC for path /pictures/
 *
 * @param {object} [endpoint.deliveryPolicy] A policy that specifies the
 * delivery rules to be used for an endpoint.
 *
 * @param {string} [endpoint.deliveryPolicy.description] User-friendly
 * description of the policy.
 *
 * @param {array} endpoint.deliveryPolicy.rules A list of the delivery rules.
 *
 * @param {array} endpoint.origins The source of the content being delivered
 * via CDN.
 *
 * @param {string} endpoint.location Resource location.
 *
 * @param {object} [endpoint.tags] Resource tags.
 *
 * @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 Endpoint} 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 _create(resourceGroupName, profileName, endpointName, endpoint, 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.');
  }

  // Send request
  this.beginCreate(resourceGroupName, profileName, endpointName, endpoint, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Endpoint']().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);
    });
  });
}


/**
 * Updates an existing CDN endpoint with the specified endpoint name under the
 * specified subscription, resource group and profile. Only tags and Origin
 * HostHeader can be updated after creating an endpoint. To update origins, use
 * the Update Origin operation. To update custom domains, use the Update Custom
 * Domain operation.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @param {object} endpointUpdateProperties Endpoint update properties
 *
 * @param {object} [endpointUpdateProperties.tags] Endpoint tags.
 *
 * @param {string} [endpointUpdateProperties.originHostHeader] The host header
 * value sent to the origin with each request. If you leave this blank, the
 * request hostname determines this value. Azure CDN origins, such as Web Apps,
 * Blob Storage, and Cloud Services require this host header value to match the
 * origin hostname by default.
 *
 * @param {string} [endpointUpdateProperties.originPath] A directory path on
 * the origin that CDN can use to retrieve content from, e.g.
 * contoso.cloudapp.net/originpath.
 *
 * @param {array} [endpointUpdateProperties.contentTypesToCompress] List of
 * content types on which compression applies. The value should be a valid MIME
 * type.
 *
 * @param {boolean} [endpointUpdateProperties.isCompressionEnabled] Indicates
 * whether content compression is enabled on CDN. Default value is false. If
 * compression is enabled, content will be served as compressed if user
 * requests for a compressed version. Content won't be compressed on CDN when
 * requested content is smaller than 1 byte or larger than 1 MB.
 *
 * @param {boolean} [endpointUpdateProperties.isHttpAllowed] Indicates whether
 * HTTP traffic is allowed on the endpoint. Default value is true. At least one
 * protocol (HTTP or HTTPS) must be allowed.
 *
 * @param {boolean} [endpointUpdateProperties.isHttpsAllowed] Indicates whether
 * HTTPS traffic is allowed on the endpoint. Default value is true. At least
 * one protocol (HTTP or HTTPS) must be allowed.
 *
 * @param {string} [endpointUpdateProperties.queryStringCachingBehavior]
 * Defines how CDN caches requests that include query strings. You can ignore
 * any query strings when caching, bypass caching to prevent requests that
 * contain query strings from being cached, or cache every request with a
 * unique URL. Possible values include: 'IgnoreQueryString', 'BypassCaching',
 * 'UseQueryString', 'NotSet'
 *
 * @param {string} [endpointUpdateProperties.optimizationType] Specifies what
 * scenario the customer wants this CDN endpoint to optimize for, e.g.
 * Download, Media services. With this information, CDN can apply scenario
 * driven optimization. Possible values include: 'GeneralWebDelivery',
 * 'GeneralMediaStreaming', 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
 * 'DynamicSiteAcceleration'
 *
 * @param {string} [endpointUpdateProperties.probePath] Path to a file hosted
 * on the origin which helps accelerate delivery of the dynamic content and
 * calculate the most optimal routes for the CDN. This is relative to the
 * origin path.
 *
 * @param {array} [endpointUpdateProperties.geoFilters] List of rules defining
 * the user's geo access within a CDN endpoint. Each geo filter defines an
 * access rule to a specified path or content, e.g. block APAC for path
 * /pictures/
 *
 * @param {object} [endpointUpdateProperties.deliveryPolicy] A policy that
 * specifies the delivery rules to be used for an endpoint.
 *
 * @param {string} [endpointUpdateProperties.deliveryPolicy.description]
 * User-friendly description of the policy.
 *
 * @param {array} endpointUpdateProperties.deliveryPolicy.rules A list of the
 * delivery rules.
 *
 * @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 Endpoint} 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, endpointName, endpointUpdateProperties, 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.');
  }

  // Send request
  this.beginUpdate(resourceGroupName, profileName, endpointName, endpointUpdateProperties, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Endpoint']().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);
    });
  });
}


/**
 * Deletes an existing CDN endpoint with the specified endpoint name under the
 * specified subscription, resource group and profile.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @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.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {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, endpointName, 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.');
  }

  // Send request
  this.beginDeleteMethod(resourceGroupName, profileName, endpointName, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response

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


/**
 * Starts an existing CDN endpoint that is on a stopped state.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @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 Endpoint} 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 _start(resourceGroupName, profileName, endpointName, 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.');
  }

  // Send request
  this.beginStart(resourceGroupName, profileName, endpointName, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Endpoint']().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);
    });
  });
}


/**
 * Stops an existing running CDN endpoint.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @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 Endpoint} 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 _stop(resourceGroupName, profileName, endpointName, 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.');
  }

  // Send request
  this.beginStop(resourceGroupName, profileName, endpointName, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Endpoint']().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);
    });
  });
}


/**
 * Removes a content from CDN.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @param {array} contentPaths The path to the content to be purged. Can
 * describe a file path or a wild card directory.
 *
 * @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.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {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 _purgeContent(resourceGroupName, profileName, endpointName, contentPaths, 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.');
  }

  // Send request
  this.beginPurgeContent(resourceGroupName, profileName, endpointName, contentPaths, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response

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


/**
 * Pre-loads a content to CDN. Available for Verizon Profiles.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @param {array} contentPaths The path to the content to be loaded. Path
 * should be a relative file URL of the origin.
 *
 * @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.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {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 _loadContent(resourceGroupName, profileName, endpointName, contentPaths, 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.');
  }

  // Send request
  this.beginLoadContent(resourceGroupName, profileName, endpointName, contentPaths, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response

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

/**
 * Validates the custom domain mapping to ensure it maps to the correct CDN
 * endpoint in DNS.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @param {string} hostName The host name of the custom domain. Must be a
 * domain name.
 *
 * @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 ValidateCustomDomainOutput} 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 _validateCustomDomain(resourceGroupName, profileName, endpointName, hostName, 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    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 (endpointName === null || endpointName === undefined || typeof endpointName.valueOf() !== 'string') {
      throw new Error('endpointName 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.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 (hostName === null || hostName === undefined || typeof hostName.valueOf() !== 'string') {
      throw new Error('hostName 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);
  }
  let customDomainProperties;
  if (hostName !== null && hostName !== undefined) {
    customDomainProperties = new client.models['ValidateCustomDomainInput']();
    customDomainProperties.hostName = hostName;
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/validateCustomDomain';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{endpointName}', encodeURIComponent(endpointName));
  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 = '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 (customDomainProperties !== null && customDomainProperties !== undefined) {
      let requestModelMapper = new client.models['ValidateCustomDomainInput']().mapper();
      requestModel = client.serialize(requestModelMapper, customDomainProperties, 'customDomainProperties');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(customDomainProperties, 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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ValidateCustomDomainOutput']().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);
  });
}

/**
 * Checks the quota and usage of geo filters and custom domains under the given
 * endpoint.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @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 ResourceUsageListResult} 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 _listResourceUsage(resourceGroupName, profileName, endpointName, 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    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 (endpointName === null || endpointName === undefined || typeof endpointName.valueOf() !== 'string') {
      throw new Error('endpointName 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.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('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/checkResourceUsage';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{endpointName}', encodeURIComponent(endpointName));
  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 = '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];
      }
    }
  }
  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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ResourceUsageListResult']().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);
  });
}

/**
 * Creates a new CDN endpoint with the specified endpoint name under the
 * specified subscription, resource group and profile.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @param {object} endpoint Endpoint properties
 *
 * @param {string} [endpoint.originHostHeader] The host header value sent to
 * the origin with each request. If you leave this blank, the request hostname
 * determines this value. Azure CDN origins, such as Web Apps, Blob Storage,
 * and Cloud Services require this host header value to match the origin
 * hostname by default.
 *
 * @param {string} [endpoint.originPath] A directory path on the origin that
 * CDN can use to retrieve content from, e.g. contoso.cloudapp.net/originpath.
 *
 * @param {array} [endpoint.contentTypesToCompress] List of content types on
 * which compression applies. The value should be a valid MIME type.
 *
 * @param {boolean} [endpoint.isCompressionEnabled] Indicates whether content
 * compression is enabled on CDN. Default value is false. If compression is
 * enabled, content will be served as compressed if user requests for a
 * compressed version. Content won't be compressed on CDN when requested
 * content is smaller than 1 byte or larger than 1 MB.
 *
 * @param {boolean} [endpoint.isHttpAllowed] Indicates whether HTTP traffic is
 * allowed on the endpoint. Default value is true. At least one protocol (HTTP
 * or HTTPS) must be allowed.
 *
 * @param {boolean} [endpoint.isHttpsAllowed] Indicates whether HTTPS traffic
 * is allowed on the endpoint. Default value is true. At least one protocol
 * (HTTP or HTTPS) must be allowed.
 *
 * @param {string} [endpoint.queryStringCachingBehavior] Defines how CDN caches
 * requests that include query strings. You can ignore any query strings when
 * caching, bypass caching to prevent requests that contain query strings from
 * being cached, or cache every request with a unique URL. Possible values
 * include: 'IgnoreQueryString', 'BypassCaching', 'UseQueryString', 'NotSet'
 *
 * @param {string} [endpoint.optimizationType] Specifies what scenario the
 * customer wants this CDN endpoint to optimize for, e.g. Download, Media
 * services. With this information, CDN can apply scenario driven optimization.
 * Possible values include: 'GeneralWebDelivery', 'GeneralMediaStreaming',
 * 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
 * 'DynamicSiteAcceleration'
 *
 * @param {string} [endpoint.probePath] Path to a file hosted on the origin
 * which helps accelerate delivery of the dynamic content and calculate the
 * most optimal routes for the CDN. This is relative to the origin path.
 *
 * @param {array} [endpoint.geoFilters] List of rules defining the user's geo
 * access within a CDN endpoint. Each geo filter defines an access rule to a
 * specified path or content, e.g. block APAC for path /pictures/
 *
 * @param {object} [endpoint.deliveryPolicy] A policy that specifies the
 * delivery rules to be used for an endpoint.
 *
 * @param {string} [endpoint.deliveryPolicy.description] User-friendly
 * description of the policy.
 *
 * @param {array} endpoint.deliveryPolicy.rules A list of the delivery rules.
 *
 * @param {array} endpoint.origins The source of the content being delivered
 * via CDN.
 *
 * @param {string} endpoint.location Resource location.
 *
 * @param {object} [endpoint.tags] Resource tags.
 *
 * @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 Endpoint} 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 _beginCreate(resourceGroupName, profileName, endpointName, endpoint, 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    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 (endpointName === null || endpointName === undefined || typeof endpointName.valueOf() !== 'string') {
      throw new Error('endpointName cannot be null or undefined and it must be of type string.');
    }
    if (endpoint === null || endpoint === undefined) {
      throw new Error('endpoint cannot be null or undefined.');
    }
    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.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('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{endpointName}', encodeURIComponent(endpointName));
  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 (endpoint !== null && endpoint !== undefined) {
      let requestModelMapper = new client.models['Endpoint']().mapper();
      requestModel = client.serialize(requestModelMapper, endpoint, 'endpoint');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(endpoint, 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 && statusCode !== 202) {
      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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['Endpoint']().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['Endpoint']().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);
      }
    }
    // Deserialize Response
    if (statusCode === 202) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Endpoint']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError2 = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError2.request = msRest.stripRequest(httpRequest);
        deserializationError2.response = msRest.stripResponse(response);
        return callback(deserializationError2);
      }
    }

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

/**
 * Updates an existing CDN endpoint with the specified endpoint name under the
 * specified subscription, resource group and profile. Only tags and Origin
 * HostHeader can be updated after creating an endpoint. To update origins, use
 * the Update Origin operation. To update custom domains, use the Update Custom
 * Domain operation.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @param {object} endpointUpdateProperties Endpoint update properties
 *
 * @param {object} [endpointUpdateProperties.tags] Endpoint tags.
 *
 * @param {string} [endpointUpdateProperties.originHostHeader] The host header
 * value sent to the origin with each request. If you leave this blank, the
 * request hostname determines this value. Azure CDN origins, such as Web Apps,
 * Blob Storage, and Cloud Services require this host header value to match the
 * origin hostname by default.
 *
 * @param {string} [endpointUpdateProperties.originPath] A directory path on
 * the origin that CDN can use to retrieve content from, e.g.
 * contoso.cloudapp.net/originpath.
 *
 * @param {array} [endpointUpdateProperties.contentTypesToCompress] List of
 * content types on which compression applies. The value should be a valid MIME
 * type.
 *
 * @param {boolean} [endpointUpdateProperties.isCompressionEnabled] Indicates
 * whether content compression is enabled on CDN. Default value is false. If
 * compression is enabled, content will be served as compressed if user
 * requests for a compressed version. Content won't be compressed on CDN when
 * requested content is smaller than 1 byte or larger than 1 MB.
 *
 * @param {boolean} [endpointUpdateProperties.isHttpAllowed] Indicates whether
 * HTTP traffic is allowed on the endpoint. Default value is true. At least one
 * protocol (HTTP or HTTPS) must be allowed.
 *
 * @param {boolean} [endpointUpdateProperties.isHttpsAllowed] Indicates whether
 * HTTPS traffic is allowed on the endpoint. Default value is true. At least
 * one protocol (HTTP or HTTPS) must be allowed.
 *
 * @param {string} [endpointUpdateProperties.queryStringCachingBehavior]
 * Defines how CDN caches requests that include query strings. You can ignore
 * any query strings when caching, bypass caching to prevent requests that
 * contain query strings from being cached, or cache every request with a
 * unique URL. Possible values include: 'IgnoreQueryString', 'BypassCaching',
 * 'UseQueryString', 'NotSet'
 *
 * @param {string} [endpointUpdateProperties.optimizationType] Specifies what
 * scenario the customer wants this CDN endpoint to optimize for, e.g.
 * Download, Media services. With this information, CDN can apply scenario
 * driven optimization. Possible values include: 'GeneralWebDelivery',
 * 'GeneralMediaStreaming', 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
 * 'DynamicSiteAcceleration'
 *
 * @param {string} [endpointUpdateProperties.probePath] Path to a file hosted
 * on the origin which helps accelerate delivery of the dynamic content and
 * calculate the most optimal routes for the CDN. This is relative to the
 * origin path.
 *
 * @param {array} [endpointUpdateProperties.geoFilters] List of rules defining
 * the user's geo access within a CDN endpoint. Each geo filter defines an
 * access rule to a specified path or content, e.g. block APAC for path
 * /pictures/
 *
 * @param {object} [endpointUpdateProperties.deliveryPolicy] A policy that
 * specifies the delivery rules to be used for an endpoint.
 *
 * @param {string} [endpointUpdateProperties.deliveryPolicy.description]
 * User-friendly description of the policy.
 *
 * @param {array} endpointUpdateProperties.deliveryPolicy.rules A list of the
 * delivery rules.
 *
 * @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 Endpoint} 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 _beginUpdate(resourceGroupName, profileName, endpointName, endpointUpdateProperties, 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    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 (endpointName === null || endpointName === undefined || typeof endpointName.valueOf() !== 'string') {
      throw new Error('endpointName cannot be null or undefined and it must be of type string.');
    }
    if (endpointUpdateProperties === null || endpointUpdateProperties === undefined) {
      throw new Error('endpointUpdateProperties cannot be null or undefined.');
    }
    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.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('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{endpointName}', encodeURIComponent(endpointName));
  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 (endpointUpdateProperties !== null && endpointUpdateProperties !== undefined) {
      let requestModelMapper = new client.models['EndpointUpdateParameters']().mapper();
      requestModel = client.serialize(requestModelMapper, endpointUpdateProperties, 'endpointUpdateProperties');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(endpointUpdateProperties, 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 !== 202) {
      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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['Endpoint']().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 === 202) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Endpoint']().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 an existing CDN endpoint with the specified endpoint name under the
 * specified subscription, resource group and profile.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @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.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {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 _beginDeleteMethod(resourceGroupName, profileName, endpointName, 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    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 (endpointName === null || endpointName === undefined || typeof endpointName.valueOf() !== 'string') {
      throw new Error('endpointName 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.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('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{endpointName}', encodeURIComponent(endpointName));
  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 !== 202 && 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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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;

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

/**
 * Starts an existing CDN endpoint that is on a stopped state.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @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 Endpoint} 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 _beginStart(resourceGroupName, profileName, endpointName, 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    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 (endpointName === null || endpointName === undefined || typeof endpointName.valueOf() !== 'string') {
      throw new Error('endpointName 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.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('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/start';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{endpointName}', encodeURIComponent(endpointName));
  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 = '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];
      }
    }
  }
  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 !== 202) {
      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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['Endpoint']().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 === 202) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Endpoint']().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);
  });
}

/**
 * Stops an existing running CDN endpoint.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @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 Endpoint} 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 _beginStop(resourceGroupName, profileName, endpointName, 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    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 (endpointName === null || endpointName === undefined || typeof endpointName.valueOf() !== 'string') {
      throw new Error('endpointName 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.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('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/stop';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{endpointName}', encodeURIComponent(endpointName));
  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 = '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];
      }
    }
  }
  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 !== 202) {
      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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['Endpoint']().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 === 202) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Endpoint']().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);
  });
}

/**
 * Removes a content from CDN.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @param {array} contentPaths The path to the content to be purged. Can
 * describe a file path or a wild card directory.
 *
 * @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.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {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 _beginPurgeContent(resourceGroupName, profileName, endpointName, contentPaths, 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    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 (endpointName === null || endpointName === undefined || typeof endpointName.valueOf() !== 'string') {
      throw new Error('endpointName 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.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 (!Array.isArray(contentPaths)) {
      throw new Error('contentPaths cannot be null or undefined and it must be of type array.');
    }
    for (let i = 0; i < contentPaths.length; i++) {
      if (contentPaths[i] !== null && contentPaths[i] !== undefined && typeof contentPaths[i].valueOf() !== 'string') {
        throw new Error('contentPaths[i] 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);
  }
  let contentFilePaths;
  if (contentPaths !== null && contentPaths !== undefined) {
    contentFilePaths = new client.models['PurgeParameters']();
    contentFilePaths.contentPaths = contentPaths;
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/purge';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{endpointName}', encodeURIComponent(endpointName));
  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 = '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 (contentFilePaths !== null && contentFilePaths !== undefined) {
      let requestModelMapper = new client.models['PurgeParameters']().mapper();
      requestModel = client.serialize(requestModelMapper, contentFilePaths, 'contentFilePaths');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(contentFilePaths, 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 !== 202) {
      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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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;

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

/**
 * Pre-loads a content to CDN. Available for Verizon Profiles.
 *
 * @param {string} resourceGroupName Name of the Resource group within the
 * Azure subscription.
 *
 * @param {string} profileName Name of the CDN profile which is unique within
 * the resource group.
 *
 * @param {string} endpointName Name of the endpoint under the profile which is
 * unique globally.
 *
 * @param {array} contentPaths The path to the content to be loaded. Path
 * should be a relative file URL of the origin.
 *
 * @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.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {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 _beginLoadContent(resourceGroupName, profileName, endpointName, contentPaths, 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    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 (endpointName === null || endpointName === undefined || typeof endpointName.valueOf() !== 'string') {
      throw new Error('endpointName 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.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 (!Array.isArray(contentPaths)) {
      throw new Error('contentPaths cannot be null or undefined and it must be of type array.');
    }
    for (let i = 0; i < contentPaths.length; i++) {
      if (contentPaths[i] !== null && contentPaths[i] !== undefined && typeof contentPaths[i].valueOf() !== 'string') {
        throw new Error('contentPaths[i] 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);
  }
  let contentFilePaths;
  if (contentPaths !== null && contentPaths !== undefined) {
    contentFilePaths = new client.models['LoadParameters']();
    contentFilePaths.contentPaths = contentPaths;
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Cdn/profiles/{profileName}/endpoints/{endpointName}/load';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{profileName}', encodeURIComponent(profileName));
  requestUrl = requestUrl.replace('{endpointName}', encodeURIComponent(endpointName));
  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 = '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 (contentFilePaths !== null && contentFilePaths !== undefined) {
      let requestModelMapper = new client.models['LoadParameters']().mapper();
      requestModel = client.serialize(requestModelMapper, contentFilePaths, 'contentFilePaths');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(contentFilePaths, 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 !== 202) {
      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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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;

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

/**
 * Lists existing CDN endpoints.
 *
 * @param {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @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 EndpointListResult} 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 _listByProfileNext(nextPageLink, 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 (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink 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 requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // 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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['EndpointListResult']().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);
  });
}

/**
 * Checks the quota and usage of geo filters and custom domains under the given
 * endpoint.
 *
 * @param {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @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 ResourceUsageListResult} 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 _listResourceUsageNext(nextPageLink, 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 (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink 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 requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

  // 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];
      }
    }
  }
  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) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['ErrorResponse']().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['ResourceUsageListResult']().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 Endpoints. */
class Endpoints {
  /**
   * Create a Endpoints.
   * @param {CdnManagementClient} client Reference to the service client.
   */
  constructor(client) {
    this.client = client;
    this._listByProfile = _listByProfile;
    this._get = _get;
    this._create = _create;
    this._update = _update;
    this._deleteMethod = _deleteMethod;
    this._start = _start;
    this._stop = _stop;
    this._purgeContent = _purgeContent;
    this._loadContent = _loadContent;
    this._validateCustomDomain = _validateCustomDomain;
    this._listResourceUsage = _listResourceUsage;
    this._beginCreate = _beginCreate;
    this._beginUpdate = _beginUpdate;
    this._beginDeleteMethod = _beginDeleteMethod;
    this._beginStart = _beginStart;
    this._beginStop = _beginStop;
    this._beginPurgeContent = _beginPurgeContent;
    this._beginLoadContent = _beginLoadContent;
    this._listByProfileNext = _listByProfileNext;
    this._listResourceUsageNext = _listResourceUsageNext;
  }

  /**
   * Lists existing CDN endpoints.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @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<EndpointListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByProfileWithHttpOperationResponse(resourceGroupName, profileName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByProfile(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;
      });
    });
  }

  /**
   * Lists existing CDN endpoints.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @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 {EndpointListResult} - 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 EndpointListResult} 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.
   */
  listByProfile(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._listByProfile(resourceGroupName, profileName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByProfile(resourceGroupName, profileName, options, optionalCallback);
    }
  }

  /**
   * Gets an existing CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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<Endpoint>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getWithHttpOperationResponse(resourceGroupName, profileName, endpointName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._get(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets an existing CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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 {Endpoint} - 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 Endpoint} 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, endpointName, 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, endpointName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._get(resourceGroupName, profileName, endpointName, options, optionalCallback);
    }
  }

  /**
   * Creates a new CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {object} endpoint Endpoint properties
   *
   * @param {string} [endpoint.originHostHeader] The host header value sent to
   * the origin with each request. If you leave this blank, the request hostname
   * determines this value. Azure CDN origins, such as Web Apps, Blob Storage,
   * and Cloud Services require this host header value to match the origin
   * hostname by default.
   *
   * @param {string} [endpoint.originPath] A directory path on the origin that
   * CDN can use to retrieve content from, e.g. contoso.cloudapp.net/originpath.
   *
   * @param {array} [endpoint.contentTypesToCompress] List of content types on
   * which compression applies. The value should be a valid MIME type.
   *
   * @param {boolean} [endpoint.isCompressionEnabled] Indicates whether content
   * compression is enabled on CDN. Default value is false. If compression is
   * enabled, content will be served as compressed if user requests for a
   * compressed version. Content won't be compressed on CDN when requested
   * content is smaller than 1 byte or larger than 1 MB.
   *
   * @param {boolean} [endpoint.isHttpAllowed] Indicates whether HTTP traffic is
   * allowed on the endpoint. Default value is true. At least one protocol (HTTP
   * or HTTPS) must be allowed.
   *
   * @param {boolean} [endpoint.isHttpsAllowed] Indicates whether HTTPS traffic
   * is allowed on the endpoint. Default value is true. At least one protocol
   * (HTTP or HTTPS) must be allowed.
   *
   * @param {string} [endpoint.queryStringCachingBehavior] Defines how CDN caches
   * requests that include query strings. You can ignore any query strings when
   * caching, bypass caching to prevent requests that contain query strings from
   * being cached, or cache every request with a unique URL. Possible values
   * include: 'IgnoreQueryString', 'BypassCaching', 'UseQueryString', 'NotSet'
   *
   * @param {string} [endpoint.optimizationType] Specifies what scenario the
   * customer wants this CDN endpoint to optimize for, e.g. Download, Media
   * services. With this information, CDN can apply scenario driven optimization.
   * Possible values include: 'GeneralWebDelivery', 'GeneralMediaStreaming',
   * 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
   * 'DynamicSiteAcceleration'
   *
   * @param {string} [endpoint.probePath] Path to a file hosted on the origin
   * which helps accelerate delivery of the dynamic content and calculate the
   * most optimal routes for the CDN. This is relative to the origin path.
   *
   * @param {array} [endpoint.geoFilters] List of rules defining the user's geo
   * access within a CDN endpoint. Each geo filter defines an access rule to a
   * specified path or content, e.g. block APAC for path /pictures/
   *
   * @param {object} [endpoint.deliveryPolicy] A policy that specifies the
   * delivery rules to be used for an endpoint.
   *
   * @param {string} [endpoint.deliveryPolicy.description] User-friendly
   * description of the policy.
   *
   * @param {array} endpoint.deliveryPolicy.rules A list of the delivery rules.
   *
   * @param {array} endpoint.origins The source of the content being delivered
   * via CDN.
   *
   * @param {string} endpoint.location Resource location.
   *
   * @param {object} [endpoint.tags] Resource tags.
   *
   * @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<Endpoint>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createWithHttpOperationResponse(resourceGroupName, profileName, endpointName, endpoint, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._create(resourceGroupName, profileName, endpointName, endpoint, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates a new CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {object} endpoint Endpoint properties
   *
   * @param {string} [endpoint.originHostHeader] The host header value sent to
   * the origin with each request. If you leave this blank, the request hostname
   * determines this value. Azure CDN origins, such as Web Apps, Blob Storage,
   * and Cloud Services require this host header value to match the origin
   * hostname by default.
   *
   * @param {string} [endpoint.originPath] A directory path on the origin that
   * CDN can use to retrieve content from, e.g. contoso.cloudapp.net/originpath.
   *
   * @param {array} [endpoint.contentTypesToCompress] List of content types on
   * which compression applies. The value should be a valid MIME type.
   *
   * @param {boolean} [endpoint.isCompressionEnabled] Indicates whether content
   * compression is enabled on CDN. Default value is false. If compression is
   * enabled, content will be served as compressed if user requests for a
   * compressed version. Content won't be compressed on CDN when requested
   * content is smaller than 1 byte or larger than 1 MB.
   *
   * @param {boolean} [endpoint.isHttpAllowed] Indicates whether HTTP traffic is
   * allowed on the endpoint. Default value is true. At least one protocol (HTTP
   * or HTTPS) must be allowed.
   *
   * @param {boolean} [endpoint.isHttpsAllowed] Indicates whether HTTPS traffic
   * is allowed on the endpoint. Default value is true. At least one protocol
   * (HTTP or HTTPS) must be allowed.
   *
   * @param {string} [endpoint.queryStringCachingBehavior] Defines how CDN caches
   * requests that include query strings. You can ignore any query strings when
   * caching, bypass caching to prevent requests that contain query strings from
   * being cached, or cache every request with a unique URL. Possible values
   * include: 'IgnoreQueryString', 'BypassCaching', 'UseQueryString', 'NotSet'
   *
   * @param {string} [endpoint.optimizationType] Specifies what scenario the
   * customer wants this CDN endpoint to optimize for, e.g. Download, Media
   * services. With this information, CDN can apply scenario driven optimization.
   * Possible values include: 'GeneralWebDelivery', 'GeneralMediaStreaming',
   * 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
   * 'DynamicSiteAcceleration'
   *
   * @param {string} [endpoint.probePath] Path to a file hosted on the origin
   * which helps accelerate delivery of the dynamic content and calculate the
   * most optimal routes for the CDN. This is relative to the origin path.
   *
   * @param {array} [endpoint.geoFilters] List of rules defining the user's geo
   * access within a CDN endpoint. Each geo filter defines an access rule to a
   * specified path or content, e.g. block APAC for path /pictures/
   *
   * @param {object} [endpoint.deliveryPolicy] A policy that specifies the
   * delivery rules to be used for an endpoint.
   *
   * @param {string} [endpoint.deliveryPolicy.description] User-friendly
   * description of the policy.
   *
   * @param {array} endpoint.deliveryPolicy.rules A list of the delivery rules.
   *
   * @param {array} endpoint.origins The source of the content being delivered
   * via CDN.
   *
   * @param {string} endpoint.location Resource location.
   *
   * @param {object} [endpoint.tags] Resource tags.
   *
   * @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 {Endpoint} - 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 Endpoint} 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.
   */
  create(resourceGroupName, profileName, endpointName, endpoint, 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._create(resourceGroupName, profileName, endpointName, endpoint, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._create(resourceGroupName, profileName, endpointName, endpoint, options, optionalCallback);
    }
  }

  /**
   * Updates an existing CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile. Only tags and Origin
   * HostHeader can be updated after creating an endpoint. To update origins, use
   * the Update Origin operation. To update custom domains, use the Update Custom
   * Domain operation.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {object} endpointUpdateProperties Endpoint update properties
   *
   * @param {object} [endpointUpdateProperties.tags] Endpoint tags.
   *
   * @param {string} [endpointUpdateProperties.originHostHeader] The host header
   * value sent to the origin with each request. If you leave this blank, the
   * request hostname determines this value. Azure CDN origins, such as Web Apps,
   * Blob Storage, and Cloud Services require this host header value to match the
   * origin hostname by default.
   *
   * @param {string} [endpointUpdateProperties.originPath] A directory path on
   * the origin that CDN can use to retrieve content from, e.g.
   * contoso.cloudapp.net/originpath.
   *
   * @param {array} [endpointUpdateProperties.contentTypesToCompress] List of
   * content types on which compression applies. The value should be a valid MIME
   * type.
   *
   * @param {boolean} [endpointUpdateProperties.isCompressionEnabled] Indicates
   * whether content compression is enabled on CDN. Default value is false. If
   * compression is enabled, content will be served as compressed if user
   * requests for a compressed version. Content won't be compressed on CDN when
   * requested content is smaller than 1 byte or larger than 1 MB.
   *
   * @param {boolean} [endpointUpdateProperties.isHttpAllowed] Indicates whether
   * HTTP traffic is allowed on the endpoint. Default value is true. At least one
   * protocol (HTTP or HTTPS) must be allowed.
   *
   * @param {boolean} [endpointUpdateProperties.isHttpsAllowed] Indicates whether
   * HTTPS traffic is allowed on the endpoint. Default value is true. At least
   * one protocol (HTTP or HTTPS) must be allowed.
   *
   * @param {string} [endpointUpdateProperties.queryStringCachingBehavior]
   * Defines how CDN caches requests that include query strings. You can ignore
   * any query strings when caching, bypass caching to prevent requests that
   * contain query strings from being cached, or cache every request with a
   * unique URL. Possible values include: 'IgnoreQueryString', 'BypassCaching',
   * 'UseQueryString', 'NotSet'
   *
   * @param {string} [endpointUpdateProperties.optimizationType] Specifies what
   * scenario the customer wants this CDN endpoint to optimize for, e.g.
   * Download, Media services. With this information, CDN can apply scenario
   * driven optimization. Possible values include: 'GeneralWebDelivery',
   * 'GeneralMediaStreaming', 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
   * 'DynamicSiteAcceleration'
   *
   * @param {string} [endpointUpdateProperties.probePath] Path to a file hosted
   * on the origin which helps accelerate delivery of the dynamic content and
   * calculate the most optimal routes for the CDN. This is relative to the
   * origin path.
   *
   * @param {array} [endpointUpdateProperties.geoFilters] List of rules defining
   * the user's geo access within a CDN endpoint. Each geo filter defines an
   * access rule to a specified path or content, e.g. block APAC for path
   * /pictures/
   *
   * @param {object} [endpointUpdateProperties.deliveryPolicy] A policy that
   * specifies the delivery rules to be used for an endpoint.
   *
   * @param {string} [endpointUpdateProperties.deliveryPolicy.description]
   * User-friendly description of the policy.
   *
   * @param {array} endpointUpdateProperties.deliveryPolicy.rules A list of the
   * delivery rules.
   *
   * @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<Endpoint>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  updateWithHttpOperationResponse(resourceGroupName, profileName, endpointName, endpointUpdateProperties, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._update(resourceGroupName, profileName, endpointName, endpointUpdateProperties, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Updates an existing CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile. Only tags and Origin
   * HostHeader can be updated after creating an endpoint. To update origins, use
   * the Update Origin operation. To update custom domains, use the Update Custom
   * Domain operation.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {object} endpointUpdateProperties Endpoint update properties
   *
   * @param {object} [endpointUpdateProperties.tags] Endpoint tags.
   *
   * @param {string} [endpointUpdateProperties.originHostHeader] The host header
   * value sent to the origin with each request. If you leave this blank, the
   * request hostname determines this value. Azure CDN origins, such as Web Apps,
   * Blob Storage, and Cloud Services require this host header value to match the
   * origin hostname by default.
   *
   * @param {string} [endpointUpdateProperties.originPath] A directory path on
   * the origin that CDN can use to retrieve content from, e.g.
   * contoso.cloudapp.net/originpath.
   *
   * @param {array} [endpointUpdateProperties.contentTypesToCompress] List of
   * content types on which compression applies. The value should be a valid MIME
   * type.
   *
   * @param {boolean} [endpointUpdateProperties.isCompressionEnabled] Indicates
   * whether content compression is enabled on CDN. Default value is false. If
   * compression is enabled, content will be served as compressed if user
   * requests for a compressed version. Content won't be compressed on CDN when
   * requested content is smaller than 1 byte or larger than 1 MB.
   *
   * @param {boolean} [endpointUpdateProperties.isHttpAllowed] Indicates whether
   * HTTP traffic is allowed on the endpoint. Default value is true. At least one
   * protocol (HTTP or HTTPS) must be allowed.
   *
   * @param {boolean} [endpointUpdateProperties.isHttpsAllowed] Indicates whether
   * HTTPS traffic is allowed on the endpoint. Default value is true. At least
   * one protocol (HTTP or HTTPS) must be allowed.
   *
   * @param {string} [endpointUpdateProperties.queryStringCachingBehavior]
   * Defines how CDN caches requests that include query strings. You can ignore
   * any query strings when caching, bypass caching to prevent requests that
   * contain query strings from being cached, or cache every request with a
   * unique URL. Possible values include: 'IgnoreQueryString', 'BypassCaching',
   * 'UseQueryString', 'NotSet'
   *
   * @param {string} [endpointUpdateProperties.optimizationType] Specifies what
   * scenario the customer wants this CDN endpoint to optimize for, e.g.
   * Download, Media services. With this information, CDN can apply scenario
   * driven optimization. Possible values include: 'GeneralWebDelivery',
   * 'GeneralMediaStreaming', 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
   * 'DynamicSiteAcceleration'
   *
   * @param {string} [endpointUpdateProperties.probePath] Path to a file hosted
   * on the origin which helps accelerate delivery of the dynamic content and
   * calculate the most optimal routes for the CDN. This is relative to the
   * origin path.
   *
   * @param {array} [endpointUpdateProperties.geoFilters] List of rules defining
   * the user's geo access within a CDN endpoint. Each geo filter defines an
   * access rule to a specified path or content, e.g. block APAC for path
   * /pictures/
   *
   * @param {object} [endpointUpdateProperties.deliveryPolicy] A policy that
   * specifies the delivery rules to be used for an endpoint.
   *
   * @param {string} [endpointUpdateProperties.deliveryPolicy.description]
   * User-friendly description of the policy.
   *
   * @param {array} endpointUpdateProperties.deliveryPolicy.rules A list of the
   * delivery rules.
   *
   * @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 {Endpoint} - 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 Endpoint} 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, endpointName, endpointUpdateProperties, 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, endpointName, endpointUpdateProperties, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._update(resourceGroupName, profileName, endpointName, endpointUpdateProperties, options, optionalCallback);
    }
  }

  /**
   * Deletes an existing CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  deleteMethodWithHttpOperationResponse(resourceGroupName, profileName, endpointName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._deleteMethod(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Deletes an existing CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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 {null} - 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.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {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, endpointName, 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, endpointName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._deleteMethod(resourceGroupName, profileName, endpointName, options, optionalCallback);
    }
  }

  /**
   * Starts an existing CDN endpoint that is on a stopped state.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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<Endpoint>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  startWithHttpOperationResponse(resourceGroupName, profileName, endpointName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._start(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Starts an existing CDN endpoint that is on a stopped state.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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 {Endpoint} - 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 Endpoint} 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.
   */
  start(resourceGroupName, profileName, endpointName, 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._start(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._start(resourceGroupName, profileName, endpointName, options, optionalCallback);
    }
  }

  /**
   * Stops an existing running CDN endpoint.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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<Endpoint>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  stopWithHttpOperationResponse(resourceGroupName, profileName, endpointName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._stop(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Stops an existing running CDN endpoint.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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 {Endpoint} - 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 Endpoint} 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.
   */
  stop(resourceGroupName, profileName, endpointName, 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._stop(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._stop(resourceGroupName, profileName, endpointName, options, optionalCallback);
    }
  }

  /**
   * Removes a content from CDN.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {array} contentPaths The path to the content to be purged. Can
   * describe a file path or a wild card directory.
   *
   * @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<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  purgeContentWithHttpOperationResponse(resourceGroupName, profileName, endpointName, contentPaths, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._purgeContent(resourceGroupName, profileName, endpointName, contentPaths, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Removes a content from CDN.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {array} contentPaths The path to the content to be purged. Can
   * describe a file path or a wild card directory.
   *
   * @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 {null} - 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.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  purgeContent(resourceGroupName, profileName, endpointName, contentPaths, 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._purgeContent(resourceGroupName, profileName, endpointName, contentPaths, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._purgeContent(resourceGroupName, profileName, endpointName, contentPaths, options, optionalCallback);
    }
  }

  /**
   * Pre-loads a content to CDN. Available for Verizon Profiles.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {array} contentPaths The path to the content to be loaded. Path
   * should be a relative file URL of the origin.
   *
   * @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<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  loadContentWithHttpOperationResponse(resourceGroupName, profileName, endpointName, contentPaths, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._loadContent(resourceGroupName, profileName, endpointName, contentPaths, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Pre-loads a content to CDN. Available for Verizon Profiles.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {array} contentPaths The path to the content to be loaded. Path
   * should be a relative file URL of the origin.
   *
   * @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 {null} - 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.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  loadContent(resourceGroupName, profileName, endpointName, contentPaths, 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._loadContent(resourceGroupName, profileName, endpointName, contentPaths, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._loadContent(resourceGroupName, profileName, endpointName, contentPaths, options, optionalCallback);
    }
  }

  /**
   * Validates the custom domain mapping to ensure it maps to the correct CDN
   * endpoint in DNS.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {string} hostName The host name of the custom domain. Must be a
   * domain name.
   *
   * @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<ValidateCustomDomainOutput>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  validateCustomDomainWithHttpOperationResponse(resourceGroupName, profileName, endpointName, hostName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._validateCustomDomain(resourceGroupName, profileName, endpointName, hostName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Validates the custom domain mapping to ensure it maps to the correct CDN
   * endpoint in DNS.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {string} hostName The host name of the custom domain. Must be a
   * domain name.
   *
   * @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 {ValidateCustomDomainOutput} - 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 ValidateCustomDomainOutput} 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.
   */
  validateCustomDomain(resourceGroupName, profileName, endpointName, hostName, 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._validateCustomDomain(resourceGroupName, profileName, endpointName, hostName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._validateCustomDomain(resourceGroupName, profileName, endpointName, hostName, options, optionalCallback);
    }
  }

  /**
   * Checks the quota and usage of geo filters and custom domains under the given
   * endpoint.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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<ResourceUsageListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listResourceUsageWithHttpOperationResponse(resourceGroupName, profileName, endpointName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listResourceUsage(resourceGroupName, profileName, endpointName, 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 quota and usage of geo filters and custom domains under the given
   * endpoint.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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 {ResourceUsageListResult} - 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 ResourceUsageListResult} 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.
   */
  listResourceUsage(resourceGroupName, profileName, endpointName, 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._listResourceUsage(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listResourceUsage(resourceGroupName, profileName, endpointName, options, optionalCallback);
    }
  }

  /**
   * Creates a new CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {object} endpoint Endpoint properties
   *
   * @param {string} [endpoint.originHostHeader] The host header value sent to
   * the origin with each request. If you leave this blank, the request hostname
   * determines this value. Azure CDN origins, such as Web Apps, Blob Storage,
   * and Cloud Services require this host header value to match the origin
   * hostname by default.
   *
   * @param {string} [endpoint.originPath] A directory path on the origin that
   * CDN can use to retrieve content from, e.g. contoso.cloudapp.net/originpath.
   *
   * @param {array} [endpoint.contentTypesToCompress] List of content types on
   * which compression applies. The value should be a valid MIME type.
   *
   * @param {boolean} [endpoint.isCompressionEnabled] Indicates whether content
   * compression is enabled on CDN. Default value is false. If compression is
   * enabled, content will be served as compressed if user requests for a
   * compressed version. Content won't be compressed on CDN when requested
   * content is smaller than 1 byte or larger than 1 MB.
   *
   * @param {boolean} [endpoint.isHttpAllowed] Indicates whether HTTP traffic is
   * allowed on the endpoint. Default value is true. At least one protocol (HTTP
   * or HTTPS) must be allowed.
   *
   * @param {boolean} [endpoint.isHttpsAllowed] Indicates whether HTTPS traffic
   * is allowed on the endpoint. Default value is true. At least one protocol
   * (HTTP or HTTPS) must be allowed.
   *
   * @param {string} [endpoint.queryStringCachingBehavior] Defines how CDN caches
   * requests that include query strings. You can ignore any query strings when
   * caching, bypass caching to prevent requests that contain query strings from
   * being cached, or cache every request with a unique URL. Possible values
   * include: 'IgnoreQueryString', 'BypassCaching', 'UseQueryString', 'NotSet'
   *
   * @param {string} [endpoint.optimizationType] Specifies what scenario the
   * customer wants this CDN endpoint to optimize for, e.g. Download, Media
   * services. With this information, CDN can apply scenario driven optimization.
   * Possible values include: 'GeneralWebDelivery', 'GeneralMediaStreaming',
   * 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
   * 'DynamicSiteAcceleration'
   *
   * @param {string} [endpoint.probePath] Path to a file hosted on the origin
   * which helps accelerate delivery of the dynamic content and calculate the
   * most optimal routes for the CDN. This is relative to the origin path.
   *
   * @param {array} [endpoint.geoFilters] List of rules defining the user's geo
   * access within a CDN endpoint. Each geo filter defines an access rule to a
   * specified path or content, e.g. block APAC for path /pictures/
   *
   * @param {object} [endpoint.deliveryPolicy] A policy that specifies the
   * delivery rules to be used for an endpoint.
   *
   * @param {string} [endpoint.deliveryPolicy.description] User-friendly
   * description of the policy.
   *
   * @param {array} endpoint.deliveryPolicy.rules A list of the delivery rules.
   *
   * @param {array} endpoint.origins The source of the content being delivered
   * via CDN.
   *
   * @param {string} endpoint.location Resource location.
   *
   * @param {object} [endpoint.tags] Resource tags.
   *
   * @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<Endpoint>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginCreateWithHttpOperationResponse(resourceGroupName, profileName, endpointName, endpoint, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginCreate(resourceGroupName, profileName, endpointName, endpoint, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates a new CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {object} endpoint Endpoint properties
   *
   * @param {string} [endpoint.originHostHeader] The host header value sent to
   * the origin with each request. If you leave this blank, the request hostname
   * determines this value. Azure CDN origins, such as Web Apps, Blob Storage,
   * and Cloud Services require this host header value to match the origin
   * hostname by default.
   *
   * @param {string} [endpoint.originPath] A directory path on the origin that
   * CDN can use to retrieve content from, e.g. contoso.cloudapp.net/originpath.
   *
   * @param {array} [endpoint.contentTypesToCompress] List of content types on
   * which compression applies. The value should be a valid MIME type.
   *
   * @param {boolean} [endpoint.isCompressionEnabled] Indicates whether content
   * compression is enabled on CDN. Default value is false. If compression is
   * enabled, content will be served as compressed if user requests for a
   * compressed version. Content won't be compressed on CDN when requested
   * content is smaller than 1 byte or larger than 1 MB.
   *
   * @param {boolean} [endpoint.isHttpAllowed] Indicates whether HTTP traffic is
   * allowed on the endpoint. Default value is true. At least one protocol (HTTP
   * or HTTPS) must be allowed.
   *
   * @param {boolean} [endpoint.isHttpsAllowed] Indicates whether HTTPS traffic
   * is allowed on the endpoint. Default value is true. At least one protocol
   * (HTTP or HTTPS) must be allowed.
   *
   * @param {string} [endpoint.queryStringCachingBehavior] Defines how CDN caches
   * requests that include query strings. You can ignore any query strings when
   * caching, bypass caching to prevent requests that contain query strings from
   * being cached, or cache every request with a unique URL. Possible values
   * include: 'IgnoreQueryString', 'BypassCaching', 'UseQueryString', 'NotSet'
   *
   * @param {string} [endpoint.optimizationType] Specifies what scenario the
   * customer wants this CDN endpoint to optimize for, e.g. Download, Media
   * services. With this information, CDN can apply scenario driven optimization.
   * Possible values include: 'GeneralWebDelivery', 'GeneralMediaStreaming',
   * 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
   * 'DynamicSiteAcceleration'
   *
   * @param {string} [endpoint.probePath] Path to a file hosted on the origin
   * which helps accelerate delivery of the dynamic content and calculate the
   * most optimal routes for the CDN. This is relative to the origin path.
   *
   * @param {array} [endpoint.geoFilters] List of rules defining the user's geo
   * access within a CDN endpoint. Each geo filter defines an access rule to a
   * specified path or content, e.g. block APAC for path /pictures/
   *
   * @param {object} [endpoint.deliveryPolicy] A policy that specifies the
   * delivery rules to be used for an endpoint.
   *
   * @param {string} [endpoint.deliveryPolicy.description] User-friendly
   * description of the policy.
   *
   * @param {array} endpoint.deliveryPolicy.rules A list of the delivery rules.
   *
   * @param {array} endpoint.origins The source of the content being delivered
   * via CDN.
   *
   * @param {string} endpoint.location Resource location.
   *
   * @param {object} [endpoint.tags] Resource tags.
   *
   * @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 {Endpoint} - 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 Endpoint} 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.
   */
  beginCreate(resourceGroupName, profileName, endpointName, endpoint, 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._beginCreate(resourceGroupName, profileName, endpointName, endpoint, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginCreate(resourceGroupName, profileName, endpointName, endpoint, options, optionalCallback);
    }
  }

  /**
   * Updates an existing CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile. Only tags and Origin
   * HostHeader can be updated after creating an endpoint. To update origins, use
   * the Update Origin operation. To update custom domains, use the Update Custom
   * Domain operation.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {object} endpointUpdateProperties Endpoint update properties
   *
   * @param {object} [endpointUpdateProperties.tags] Endpoint tags.
   *
   * @param {string} [endpointUpdateProperties.originHostHeader] The host header
   * value sent to the origin with each request. If you leave this blank, the
   * request hostname determines this value. Azure CDN origins, such as Web Apps,
   * Blob Storage, and Cloud Services require this host header value to match the
   * origin hostname by default.
   *
   * @param {string} [endpointUpdateProperties.originPath] A directory path on
   * the origin that CDN can use to retrieve content from, e.g.
   * contoso.cloudapp.net/originpath.
   *
   * @param {array} [endpointUpdateProperties.contentTypesToCompress] List of
   * content types on which compression applies. The value should be a valid MIME
   * type.
   *
   * @param {boolean} [endpointUpdateProperties.isCompressionEnabled] Indicates
   * whether content compression is enabled on CDN. Default value is false. If
   * compression is enabled, content will be served as compressed if user
   * requests for a compressed version. Content won't be compressed on CDN when
   * requested content is smaller than 1 byte or larger than 1 MB.
   *
   * @param {boolean} [endpointUpdateProperties.isHttpAllowed] Indicates whether
   * HTTP traffic is allowed on the endpoint. Default value is true. At least one
   * protocol (HTTP or HTTPS) must be allowed.
   *
   * @param {boolean} [endpointUpdateProperties.isHttpsAllowed] Indicates whether
   * HTTPS traffic is allowed on the endpoint. Default value is true. At least
   * one protocol (HTTP or HTTPS) must be allowed.
   *
   * @param {string} [endpointUpdateProperties.queryStringCachingBehavior]
   * Defines how CDN caches requests that include query strings. You can ignore
   * any query strings when caching, bypass caching to prevent requests that
   * contain query strings from being cached, or cache every request with a
   * unique URL. Possible values include: 'IgnoreQueryString', 'BypassCaching',
   * 'UseQueryString', 'NotSet'
   *
   * @param {string} [endpointUpdateProperties.optimizationType] Specifies what
   * scenario the customer wants this CDN endpoint to optimize for, e.g.
   * Download, Media services. With this information, CDN can apply scenario
   * driven optimization. Possible values include: 'GeneralWebDelivery',
   * 'GeneralMediaStreaming', 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
   * 'DynamicSiteAcceleration'
   *
   * @param {string} [endpointUpdateProperties.probePath] Path to a file hosted
   * on the origin which helps accelerate delivery of the dynamic content and
   * calculate the most optimal routes for the CDN. This is relative to the
   * origin path.
   *
   * @param {array} [endpointUpdateProperties.geoFilters] List of rules defining
   * the user's geo access within a CDN endpoint. Each geo filter defines an
   * access rule to a specified path or content, e.g. block APAC for path
   * /pictures/
   *
   * @param {object} [endpointUpdateProperties.deliveryPolicy] A policy that
   * specifies the delivery rules to be used for an endpoint.
   *
   * @param {string} [endpointUpdateProperties.deliveryPolicy.description]
   * User-friendly description of the policy.
   *
   * @param {array} endpointUpdateProperties.deliveryPolicy.rules A list of the
   * delivery rules.
   *
   * @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<Endpoint>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginUpdateWithHttpOperationResponse(resourceGroupName, profileName, endpointName, endpointUpdateProperties, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginUpdate(resourceGroupName, profileName, endpointName, endpointUpdateProperties, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Updates an existing CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile. Only tags and Origin
   * HostHeader can be updated after creating an endpoint. To update origins, use
   * the Update Origin operation. To update custom domains, use the Update Custom
   * Domain operation.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {object} endpointUpdateProperties Endpoint update properties
   *
   * @param {object} [endpointUpdateProperties.tags] Endpoint tags.
   *
   * @param {string} [endpointUpdateProperties.originHostHeader] The host header
   * value sent to the origin with each request. If you leave this blank, the
   * request hostname determines this value. Azure CDN origins, such as Web Apps,
   * Blob Storage, and Cloud Services require this host header value to match the
   * origin hostname by default.
   *
   * @param {string} [endpointUpdateProperties.originPath] A directory path on
   * the origin that CDN can use to retrieve content from, e.g.
   * contoso.cloudapp.net/originpath.
   *
   * @param {array} [endpointUpdateProperties.contentTypesToCompress] List of
   * content types on which compression applies. The value should be a valid MIME
   * type.
   *
   * @param {boolean} [endpointUpdateProperties.isCompressionEnabled] Indicates
   * whether content compression is enabled on CDN. Default value is false. If
   * compression is enabled, content will be served as compressed if user
   * requests for a compressed version. Content won't be compressed on CDN when
   * requested content is smaller than 1 byte or larger than 1 MB.
   *
   * @param {boolean} [endpointUpdateProperties.isHttpAllowed] Indicates whether
   * HTTP traffic is allowed on the endpoint. Default value is true. At least one
   * protocol (HTTP or HTTPS) must be allowed.
   *
   * @param {boolean} [endpointUpdateProperties.isHttpsAllowed] Indicates whether
   * HTTPS traffic is allowed on the endpoint. Default value is true. At least
   * one protocol (HTTP or HTTPS) must be allowed.
   *
   * @param {string} [endpointUpdateProperties.queryStringCachingBehavior]
   * Defines how CDN caches requests that include query strings. You can ignore
   * any query strings when caching, bypass caching to prevent requests that
   * contain query strings from being cached, or cache every request with a
   * unique URL. Possible values include: 'IgnoreQueryString', 'BypassCaching',
   * 'UseQueryString', 'NotSet'
   *
   * @param {string} [endpointUpdateProperties.optimizationType] Specifies what
   * scenario the customer wants this CDN endpoint to optimize for, e.g.
   * Download, Media services. With this information, CDN can apply scenario
   * driven optimization. Possible values include: 'GeneralWebDelivery',
   * 'GeneralMediaStreaming', 'VideoOnDemandMediaStreaming', 'LargeFileDownload',
   * 'DynamicSiteAcceleration'
   *
   * @param {string} [endpointUpdateProperties.probePath] Path to a file hosted
   * on the origin which helps accelerate delivery of the dynamic content and
   * calculate the most optimal routes for the CDN. This is relative to the
   * origin path.
   *
   * @param {array} [endpointUpdateProperties.geoFilters] List of rules defining
   * the user's geo access within a CDN endpoint. Each geo filter defines an
   * access rule to a specified path or content, e.g. block APAC for path
   * /pictures/
   *
   * @param {object} [endpointUpdateProperties.deliveryPolicy] A policy that
   * specifies the delivery rules to be used for an endpoint.
   *
   * @param {string} [endpointUpdateProperties.deliveryPolicy.description]
   * User-friendly description of the policy.
   *
   * @param {array} endpointUpdateProperties.deliveryPolicy.rules A list of the
   * delivery rules.
   *
   * @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 {Endpoint} - 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 Endpoint} 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.
   */
  beginUpdate(resourceGroupName, profileName, endpointName, endpointUpdateProperties, 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._beginUpdate(resourceGroupName, profileName, endpointName, endpointUpdateProperties, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginUpdate(resourceGroupName, profileName, endpointName, endpointUpdateProperties, options, optionalCallback);
    }
  }

  /**
   * Deletes an existing CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginDeleteMethodWithHttpOperationResponse(resourceGroupName, profileName, endpointName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginDeleteMethod(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Deletes an existing CDN endpoint with the specified endpoint name under the
   * specified subscription, resource group and profile.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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 {null} - 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.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  beginDeleteMethod(resourceGroupName, profileName, endpointName, 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._beginDeleteMethod(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginDeleteMethod(resourceGroupName, profileName, endpointName, options, optionalCallback);
    }
  }

  /**
   * Starts an existing CDN endpoint that is on a stopped state.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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<Endpoint>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginStartWithHttpOperationResponse(resourceGroupName, profileName, endpointName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginStart(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Starts an existing CDN endpoint that is on a stopped state.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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 {Endpoint} - 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 Endpoint} 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.
   */
  beginStart(resourceGroupName, profileName, endpointName, 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._beginStart(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginStart(resourceGroupName, profileName, endpointName, options, optionalCallback);
    }
  }

  /**
   * Stops an existing running CDN endpoint.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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<Endpoint>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginStopWithHttpOperationResponse(resourceGroupName, profileName, endpointName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginStop(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Stops an existing running CDN endpoint.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @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 {Endpoint} - 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 Endpoint} 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.
   */
  beginStop(resourceGroupName, profileName, endpointName, 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._beginStop(resourceGroupName, profileName, endpointName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginStop(resourceGroupName, profileName, endpointName, options, optionalCallback);
    }
  }

  /**
   * Removes a content from CDN.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {array} contentPaths The path to the content to be purged. Can
   * describe a file path or a wild card directory.
   *
   * @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<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginPurgeContentWithHttpOperationResponse(resourceGroupName, profileName, endpointName, contentPaths, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginPurgeContent(resourceGroupName, profileName, endpointName, contentPaths, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Removes a content from CDN.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {array} contentPaths The path to the content to be purged. Can
   * describe a file path or a wild card directory.
   *
   * @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 {null} - 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.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  beginPurgeContent(resourceGroupName, profileName, endpointName, contentPaths, 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._beginPurgeContent(resourceGroupName, profileName, endpointName, contentPaths, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginPurgeContent(resourceGroupName, profileName, endpointName, contentPaths, options, optionalCallback);
    }
  }

  /**
   * Pre-loads a content to CDN. Available for Verizon Profiles.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {array} contentPaths The path to the content to be loaded. Path
   * should be a relative file URL of the origin.
   *
   * @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<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginLoadContentWithHttpOperationResponse(resourceGroupName, profileName, endpointName, contentPaths, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginLoadContent(resourceGroupName, profileName, endpointName, contentPaths, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Pre-loads a content to CDN. Available for Verizon Profiles.
   *
   * @param {string} resourceGroupName Name of the Resource group within the
   * Azure subscription.
   *
   * @param {string} profileName Name of the CDN profile which is unique within
   * the resource group.
   *
   * @param {string} endpointName Name of the endpoint under the profile which is
   * unique globally.
   *
   * @param {array} contentPaths The path to the content to be loaded. Path
   * should be a relative file URL of the origin.
   *
   * @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 {null} - 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.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  beginLoadContent(resourceGroupName, profileName, endpointName, contentPaths, 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._beginLoadContent(resourceGroupName, profileName, endpointName, contentPaths, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginLoadContent(resourceGroupName, profileName, endpointName, contentPaths, options, optionalCallback);
    }
  }

  /**
   * Lists existing CDN endpoints.
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @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<EndpointListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByProfileNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByProfileNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Lists existing CDN endpoints.
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @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 {EndpointListResult} - 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 EndpointListResult} 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.
   */
  listByProfileNext(nextPageLink, 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._listByProfileNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByProfileNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * Checks the quota and usage of geo filters and custom domains under the given
   * endpoint.
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @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<ResourceUsageListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listResourceUsageNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listResourceUsageNext(nextPageLink, 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 quota and usage of geo filters and custom domains under the given
   * endpoint.
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @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 {ResourceUsageListResult} - 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 ResourceUsageListResult} 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.
   */
  listResourceUsageNext(nextPageLink, 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._listResourceUsageNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listResourceUsageNext(nextPageLink, options, optionalCallback);
    }
  }

}

module.exports = Endpoints;
