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


/**
 * @summary Deletes a deployment from the deployment history.
 *
 * A template deployment that is currently running cannot be deleted. Deleting
 * a template deployment removes the associated deployment operations. This is
 * an asynchronous operation that returns a status of 202 until the template
 * deployment is successfully deleted. The Location response header contains
 * the URI that is used to obtain the status of the process. While the process
 * is running, a call to the URI in the Location header returns a status of
 * 202. When the process finishes, the URI in the Location header returns a
 * status of 204 on success. If the asynchronous request failed, the URI in the
 * Location header returns an error-level status code.
 *
 * @param {string} deploymentName The name of the deployment to delete.
 *
 * @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 _deleteAtSubscriptionScope(deploymentName, 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.beginDeleteAtSubscriptionScope(deploymentName, 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);
    });
  });
}

/**
 * Checks whether the deployment exists.
 *
 * @param {string} deploymentName The name of the deployment to check.
 *
 * @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.
 *
 *                      {boolean} [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 _checkExistenceAtSubscriptionScope(deploymentName, 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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.Resources/deployments/{deploymentName}';
  requestUrl = requestUrl.replace('{deploymentName}', encodeURIComponent(deploymentName));
  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 = 'HEAD';
  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 !== 204 && statusCode !== 404) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    result = (statusCode === 204);

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


/**
 * @summary Deploys resources at subscription scope.
 *
 * You can provide the template and parameters directly in the request or link
 * to JSON files.
 *
 * @param {string} deploymentName The name of the deployment.
 *
 * @param {object} parameters Additional parameters supplied to the operation.
 *
 * @param {string} [parameters.location] The location to store the deployment
 * data.
 *
 * @param {object} parameters.properties The deployment properties.
 *
 * @param {object} [parameters.properties.template] The template content. You
 * use this element when you want to pass the template syntax directly in the
 * request rather than link to an existing template. It can be a JObject or
 * well-formed JSON string. Use either the templateLink property or the
 * template property, but not both.
 *
 * @param {object} [parameters.properties.templateLink] The URI of the
 * template. Use either the templateLink property or the template property, but
 * not both.
 *
 * @param {string} parameters.properties.templateLink.uri The URI of the
 * template to deploy.
 *
 * @param {string} [parameters.properties.templateLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {object} [parameters.properties.parameters] Name and value pairs that
 * define the deployment parameters for the template. You use this element when
 * you want to provide the parameter values directly in the request rather than
 * link to an existing parameter file. Use either the parametersLink property
 * or the parameters property, but not both. It can be a JObject or a well
 * formed JSON string.
 *
 * @param {object} [parameters.properties.parametersLink] The URI of parameters
 * file. You use this element to link to an existing parameters file. Use
 * either the parametersLink property or the parameters property, but not both.
 *
 * @param {string} parameters.properties.parametersLink.uri The URI of the
 * parameters file.
 *
 * @param {string} [parameters.properties.parametersLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {string} parameters.properties.mode The mode that is used to deploy
 * resources. This value can be either Incremental or Complete. In Incremental
 * mode, resources are deployed without deleting existing resources that are
 * not included in the template. In Complete mode, resources are deployed and
 * existing resources in the resource group that are not included in the
 * template are deleted. Be careful when using Complete mode as you may
 * unintentionally delete resources. Possible values include: 'Incremental',
 * 'Complete'
 *
 * @param {object} [parameters.properties.debugSetting] The debug setting of
 * the deployment.
 *
 * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
 * the type of information to log for debugging. The permitted values are none,
 * requestContent, responseContent, or both requestContent and responseContent
 * separated by a comma. The default is none. When setting this value,
 * carefully consider the type of information you are passing in during
 * deployment. By logging information about the request or response, you could
 * potentially expose sensitive data that is retrieved through the deployment
 * operations.
 *
 * @param {object} [parameters.properties.onErrorDeployment] The deployment on
 * error behavior.
 *
 * @param {string} [parameters.properties.onErrorDeployment.type] The
 * deployment on error behavior type. Possible values are LastSuccessful and
 * SpecificDeployment. Possible values include: 'LastSuccessful',
 * 'SpecificDeployment'
 *
 * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
 * deployment to be used on error case.
 *
 * @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 DeploymentExtended} 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 _createOrUpdateAtSubscriptionScope(deploymentName, parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }

  if (!callback) {
    throw new Error('callback cannot be null.');
  }

  // Send request
  this.beginCreateOrUpdateAtSubscriptionScope(deploymentName, parameters, 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['DeploymentExtended']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }

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

/**
 * Gets a deployment.
 *
 * @param {string} deploymentName The name of the deployment to get.
 *
 * @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 DeploymentExtended} 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 _getAtSubscriptionScope(deploymentName, 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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

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

/**
 * @summary Cancels a currently running template deployment.
 *
 * You can cancel a deployment only if the provisioningState is Accepted or
 * Running. After the deployment is canceled, the provisioningState is set to
 * Canceled. Canceling a template deployment stops the currently running
 * template deployment and leaves the resources partially deployed.
 *
 * @param {string} deploymentName The name of the deployment to cancel.
 *
 * @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 _cancelAtSubscriptionScope(deploymentName, 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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.Resources/deployments/{deploymentName}/cancel';
  requestUrl = requestUrl.replace('{deploymentName}', encodeURIComponent(deploymentName));
  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 !== 204) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;

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

/**
 * Validates whether the specified template is syntactically correct and will
 * be accepted by Azure Resource Manager..
 *
 * @param {string} deploymentName The name of the deployment.
 *
 * @param {object} parameters Parameters to validate.
 *
 * @param {string} [parameters.location] The location to store the deployment
 * data.
 *
 * @param {object} parameters.properties The deployment properties.
 *
 * @param {object} [parameters.properties.template] The template content. You
 * use this element when you want to pass the template syntax directly in the
 * request rather than link to an existing template. It can be a JObject or
 * well-formed JSON string. Use either the templateLink property or the
 * template property, but not both.
 *
 * @param {object} [parameters.properties.templateLink] The URI of the
 * template. Use either the templateLink property or the template property, but
 * not both.
 *
 * @param {string} parameters.properties.templateLink.uri The URI of the
 * template to deploy.
 *
 * @param {string} [parameters.properties.templateLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {object} [parameters.properties.parameters] Name and value pairs that
 * define the deployment parameters for the template. You use this element when
 * you want to provide the parameter values directly in the request rather than
 * link to an existing parameter file. Use either the parametersLink property
 * or the parameters property, but not both. It can be a JObject or a well
 * formed JSON string.
 *
 * @param {object} [parameters.properties.parametersLink] The URI of parameters
 * file. You use this element to link to an existing parameters file. Use
 * either the parametersLink property or the parameters property, but not both.
 *
 * @param {string} parameters.properties.parametersLink.uri The URI of the
 * parameters file.
 *
 * @param {string} [parameters.properties.parametersLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {string} parameters.properties.mode The mode that is used to deploy
 * resources. This value can be either Incremental or Complete. In Incremental
 * mode, resources are deployed without deleting existing resources that are
 * not included in the template. In Complete mode, resources are deployed and
 * existing resources in the resource group that are not included in the
 * template are deleted. Be careful when using Complete mode as you may
 * unintentionally delete resources. Possible values include: 'Incremental',
 * 'Complete'
 *
 * @param {object} [parameters.properties.debugSetting] The debug setting of
 * the deployment.
 *
 * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
 * the type of information to log for debugging. The permitted values are none,
 * requestContent, responseContent, or both requestContent and responseContent
 * separated by a comma. The default is none. When setting this value,
 * carefully consider the type of information you are passing in during
 * deployment. By logging information about the request or response, you could
 * potentially expose sensitive data that is retrieved through the deployment
 * operations.
 *
 * @param {object} [parameters.properties.onErrorDeployment] The deployment on
 * error behavior.
 *
 * @param {string} [parameters.properties.onErrorDeployment.type] The
 * deployment on error behavior type. Possible values are LastSuccessful and
 * SpecificDeployment. Possible values include: 'LastSuccessful',
 * 'SpecificDeployment'
 *
 * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
 * deployment to be used on error case.
 *
 * @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 DeploymentValidateResult} 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 _validateAtSubscriptionScope(deploymentName, parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.Resources/deployments/{deploymentName}/validate';
  requestUrl = requestUrl.replace('{deploymentName}', encodeURIComponent(deploymentName));
  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 (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['Deployment']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200 && statusCode !== 400) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['DeploymentValidateResult']().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 === 400) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['DeploymentValidateResult']().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);
  });
}

/**
 * Exports the template used for specified deployment.
 *
 * @param {string} deploymentName The name of the deployment from which to get
 * the template.
 *
 * @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 DeploymentExportResult} 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 _exportTemplateAtSubscriptionScope(deploymentName, 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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.Resources/deployments/{deploymentName}/exportTemplate';
  requestUrl = requestUrl.replace('{deploymentName}', encodeURIComponent(deploymentName));
  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) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['DeploymentExportResult']().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);
  });
}

/**
 * Get all the deployments for a subscription.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] The filter to apply on the operation. For
 * example, you can use $filter=provisioningState eq '{state}'.
 *
 * @param {number} [options.top] The number of results to get. If null is
 * passed, returns all deployments.
 *
 * @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 DeploymentListResult} 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 _listAtSubscriptionScope(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.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  // Validate
  try {
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.Resources/deployments/';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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


/**
 * @summary Deletes a deployment from the deployment history.
 *
 * A template deployment that is currently running cannot be deleted. Deleting
 * a template deployment removes the associated deployment operations. Deleting
 * a template deployment does not affect the state of the resource group. This
 * is an asynchronous operation that returns a status of 202 until the template
 * deployment is successfully deleted. The Location response header contains
 * the URI that is used to obtain the status of the process. While the process
 * is running, a call to the URI in the Location header returns a status of
 * 202. When the process finishes, the URI in the Location header returns a
 * status of 204 on success. If the asynchronous request failed, the URI in the
 * Location header returns an error-level status code.
 *
 * @param {string} resourceGroupName The name of the resource group with the
 * deployment to delete. The name is case insensitive.
 *
 * @param {string} deploymentName The name of the deployment to delete.
 *
 * @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, deploymentName, 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, deploymentName, 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);
    });
  });
}

/**
 * Checks whether the deployment exists.
 *
 * @param {string} resourceGroupName The name of the resource group with the
 * deployment to check. The name is case insensitive.
 *
 * @param {string} deploymentName The name of the deployment to check.
 *
 * @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.
 *
 *                      {boolean} [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 _checkExistence(resourceGroupName, deploymentName, 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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/{deploymentName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{deploymentName}', encodeURIComponent(deploymentName));
  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 = 'HEAD';
  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 !== 204 && statusCode !== 404) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    result = (statusCode === 204);

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


/**
 * @summary Deploys resources to a resource group.
 *
 * You can provide the template and parameters directly in the request or link
 * to JSON files.
 *
 * @param {string} resourceGroupName The name of the resource group to deploy
 * the resources to. The name is case insensitive. The resource group must
 * already exist.
 *
 * @param {string} deploymentName The name of the deployment.
 *
 * @param {object} parameters Additional parameters supplied to the operation.
 *
 * @param {string} [parameters.location] The location to store the deployment
 * data.
 *
 * @param {object} parameters.properties The deployment properties.
 *
 * @param {object} [parameters.properties.template] The template content. You
 * use this element when you want to pass the template syntax directly in the
 * request rather than link to an existing template. It can be a JObject or
 * well-formed JSON string. Use either the templateLink property or the
 * template property, but not both.
 *
 * @param {object} [parameters.properties.templateLink] The URI of the
 * template. Use either the templateLink property or the template property, but
 * not both.
 *
 * @param {string} parameters.properties.templateLink.uri The URI of the
 * template to deploy.
 *
 * @param {string} [parameters.properties.templateLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {object} [parameters.properties.parameters] Name and value pairs that
 * define the deployment parameters for the template. You use this element when
 * you want to provide the parameter values directly in the request rather than
 * link to an existing parameter file. Use either the parametersLink property
 * or the parameters property, but not both. It can be a JObject or a well
 * formed JSON string.
 *
 * @param {object} [parameters.properties.parametersLink] The URI of parameters
 * file. You use this element to link to an existing parameters file. Use
 * either the parametersLink property or the parameters property, but not both.
 *
 * @param {string} parameters.properties.parametersLink.uri The URI of the
 * parameters file.
 *
 * @param {string} [parameters.properties.parametersLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {string} parameters.properties.mode The mode that is used to deploy
 * resources. This value can be either Incremental or Complete. In Incremental
 * mode, resources are deployed without deleting existing resources that are
 * not included in the template. In Complete mode, resources are deployed and
 * existing resources in the resource group that are not included in the
 * template are deleted. Be careful when using Complete mode as you may
 * unintentionally delete resources. Possible values include: 'Incremental',
 * 'Complete'
 *
 * @param {object} [parameters.properties.debugSetting] The debug setting of
 * the deployment.
 *
 * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
 * the type of information to log for debugging. The permitted values are none,
 * requestContent, responseContent, or both requestContent and responseContent
 * separated by a comma. The default is none. When setting this value,
 * carefully consider the type of information you are passing in during
 * deployment. By logging information about the request or response, you could
 * potentially expose sensitive data that is retrieved through the deployment
 * operations.
 *
 * @param {object} [parameters.properties.onErrorDeployment] The deployment on
 * error behavior.
 *
 * @param {string} [parameters.properties.onErrorDeployment.type] The
 * deployment on error behavior type. Possible values are LastSuccessful and
 * SpecificDeployment. Possible values include: 'LastSuccessful',
 * 'SpecificDeployment'
 *
 * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
 * deployment to be used on error case.
 *
 * @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 DeploymentExtended} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _createOrUpdate(resourceGroupName, deploymentName, parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }

  if (!callback) {
    throw new Error('callback cannot be null.');
  }

  // Send request
  this.beginCreateOrUpdate(resourceGroupName, deploymentName, parameters, 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['DeploymentExtended']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }

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

/**
 * Gets a deployment.
 *
 * @param {string} resourceGroupName The name of the resource group. The name
 * is case insensitive.
 *
 * @param {string} deploymentName The name of the deployment to get.
 *
 * @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 DeploymentExtended} 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, deploymentName, 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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

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

/**
 * @summary Cancels a currently running template deployment.
 *
 * You can cancel a deployment only if the provisioningState is Accepted or
 * Running. After the deployment is canceled, the provisioningState is set to
 * Canceled. Canceling a template deployment stops the currently running
 * template deployment and leaves the resource group partially deployed.
 *
 * @param {string} resourceGroupName The name of the resource group. The name
 * is case insensitive.
 *
 * @param {string} deploymentName The name of the deployment to cancel.
 *
 * @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 _cancel(resourceGroupName, deploymentName, 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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/{deploymentName}/cancel';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{deploymentName}', encodeURIComponent(deploymentName));
  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 !== 204) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;

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

/**
 * Validates whether the specified template is syntactically correct and will
 * be accepted by Azure Resource Manager..
 *
 * @param {string} resourceGroupName The name of the resource group the
 * template will be deployed to. The name is case insensitive.
 *
 * @param {string} deploymentName The name of the deployment.
 *
 * @param {object} parameters Parameters to validate.
 *
 * @param {string} [parameters.location] The location to store the deployment
 * data.
 *
 * @param {object} parameters.properties The deployment properties.
 *
 * @param {object} [parameters.properties.template] The template content. You
 * use this element when you want to pass the template syntax directly in the
 * request rather than link to an existing template. It can be a JObject or
 * well-formed JSON string. Use either the templateLink property or the
 * template property, but not both.
 *
 * @param {object} [parameters.properties.templateLink] The URI of the
 * template. Use either the templateLink property or the template property, but
 * not both.
 *
 * @param {string} parameters.properties.templateLink.uri The URI of the
 * template to deploy.
 *
 * @param {string} [parameters.properties.templateLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {object} [parameters.properties.parameters] Name and value pairs that
 * define the deployment parameters for the template. You use this element when
 * you want to provide the parameter values directly in the request rather than
 * link to an existing parameter file. Use either the parametersLink property
 * or the parameters property, but not both. It can be a JObject or a well
 * formed JSON string.
 *
 * @param {object} [parameters.properties.parametersLink] The URI of parameters
 * file. You use this element to link to an existing parameters file. Use
 * either the parametersLink property or the parameters property, but not both.
 *
 * @param {string} parameters.properties.parametersLink.uri The URI of the
 * parameters file.
 *
 * @param {string} [parameters.properties.parametersLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {string} parameters.properties.mode The mode that is used to deploy
 * resources. This value can be either Incremental or Complete. In Incremental
 * mode, resources are deployed without deleting existing resources that are
 * not included in the template. In Complete mode, resources are deployed and
 * existing resources in the resource group that are not included in the
 * template are deleted. Be careful when using Complete mode as you may
 * unintentionally delete resources. Possible values include: 'Incremental',
 * 'Complete'
 *
 * @param {object} [parameters.properties.debugSetting] The debug setting of
 * the deployment.
 *
 * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
 * the type of information to log for debugging. The permitted values are none,
 * requestContent, responseContent, or both requestContent and responseContent
 * separated by a comma. The default is none. When setting this value,
 * carefully consider the type of information you are passing in during
 * deployment. By logging information about the request or response, you could
 * potentially expose sensitive data that is retrieved through the deployment
 * operations.
 *
 * @param {object} [parameters.properties.onErrorDeployment] The deployment on
 * error behavior.
 *
 * @param {string} [parameters.properties.onErrorDeployment.type] The
 * deployment on error behavior type. Possible values are LastSuccessful and
 * SpecificDeployment. Possible values include: 'LastSuccessful',
 * 'SpecificDeployment'
 *
 * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
 * deployment to be used on error case.
 *
 * @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 DeploymentValidateResult} 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 _validate(resourceGroupName, deploymentName, parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/{deploymentName}/validate';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{deploymentName}', encodeURIComponent(deploymentName));
  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 (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['Deployment']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200 && statusCode !== 400) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['DeploymentValidateResult']().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 === 400) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['DeploymentValidateResult']().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);
  });
}

/**
 * Exports the template used for specified deployment.
 *
 * @param {string} resourceGroupName The name of the resource group. The name
 * is case insensitive.
 *
 * @param {string} deploymentName The name of the deployment from which to get
 * the template.
 *
 * @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 DeploymentExportResult} 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 _exportTemplate(resourceGroupName, deploymentName, 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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/{deploymentName}/exportTemplate';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{deploymentName}', encodeURIComponent(deploymentName));
  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) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['DeploymentExportResult']().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);
  });
}

/**
 * Get all the deployments for a resource group.
 *
 * @param {string} resourceGroupName The name of the resource group with the
 * deployments to get. The name is case insensitive.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] The filter to apply on the operation. For
 * example, you can use $filter=provisioningState eq '{state}'.
 *
 * @param {number} [options.top] The number of results to get. If null is
 * passed, returns all deployments.
 *
 * @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 DeploymentListResult} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _listByResourceGroup(resourceGroupName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let filter = (options && options.filter !== undefined) ? options.filter : undefined;
  let top = (options && options.top !== undefined) ? options.top : undefined;
  // 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 (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (top !== null && top !== undefined && typeof top !== 'number') {
      throw new Error('top must be of type number.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

/**
 * @summary Deletes a deployment from the deployment history.
 *
 * A template deployment that is currently running cannot be deleted. Deleting
 * a template deployment removes the associated deployment operations. This is
 * an asynchronous operation that returns a status of 202 until the template
 * deployment is successfully deleted. The Location response header contains
 * the URI that is used to obtain the status of the process. While the process
 * is running, a call to the URI in the Location header returns a status of
 * 202. When the process finishes, the URI in the Location header returns a
 * status of 204 on success. If the asynchronous request failed, the URI in the
 * Location header returns an error-level status code.
 *
 * @param {string} deploymentName The name of the deployment to delete.
 *
 * @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 _beginDeleteAtSubscriptionScope(deploymentName, 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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.Resources/deployments/{deploymentName}';
  requestUrl = requestUrl.replace('{deploymentName}', encodeURIComponent(deploymentName));
  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) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;

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

/**
 * @summary Deploys resources at subscription scope.
 *
 * You can provide the template and parameters directly in the request or link
 * to JSON files.
 *
 * @param {string} deploymentName The name of the deployment.
 *
 * @param {object} parameters Additional parameters supplied to the operation.
 *
 * @param {string} [parameters.location] The location to store the deployment
 * data.
 *
 * @param {object} parameters.properties The deployment properties.
 *
 * @param {object} [parameters.properties.template] The template content. You
 * use this element when you want to pass the template syntax directly in the
 * request rather than link to an existing template. It can be a JObject or
 * well-formed JSON string. Use either the templateLink property or the
 * template property, but not both.
 *
 * @param {object} [parameters.properties.templateLink] The URI of the
 * template. Use either the templateLink property or the template property, but
 * not both.
 *
 * @param {string} parameters.properties.templateLink.uri The URI of the
 * template to deploy.
 *
 * @param {string} [parameters.properties.templateLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {object} [parameters.properties.parameters] Name and value pairs that
 * define the deployment parameters for the template. You use this element when
 * you want to provide the parameter values directly in the request rather than
 * link to an existing parameter file. Use either the parametersLink property
 * or the parameters property, but not both. It can be a JObject or a well
 * formed JSON string.
 *
 * @param {object} [parameters.properties.parametersLink] The URI of parameters
 * file. You use this element to link to an existing parameters file. Use
 * either the parametersLink property or the parameters property, but not both.
 *
 * @param {string} parameters.properties.parametersLink.uri The URI of the
 * parameters file.
 *
 * @param {string} [parameters.properties.parametersLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {string} parameters.properties.mode The mode that is used to deploy
 * resources. This value can be either Incremental or Complete. In Incremental
 * mode, resources are deployed without deleting existing resources that are
 * not included in the template. In Complete mode, resources are deployed and
 * existing resources in the resource group that are not included in the
 * template are deleted. Be careful when using Complete mode as you may
 * unintentionally delete resources. Possible values include: 'Incremental',
 * 'Complete'
 *
 * @param {object} [parameters.properties.debugSetting] The debug setting of
 * the deployment.
 *
 * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
 * the type of information to log for debugging. The permitted values are none,
 * requestContent, responseContent, or both requestContent and responseContent
 * separated by a comma. The default is none. When setting this value,
 * carefully consider the type of information you are passing in during
 * deployment. By logging information about the request or response, you could
 * potentially expose sensitive data that is retrieved through the deployment
 * operations.
 *
 * @param {object} [parameters.properties.onErrorDeployment] The deployment on
 * error behavior.
 *
 * @param {string} [parameters.properties.onErrorDeployment.type] The
 * deployment on error behavior type. Possible values are LastSuccessful and
 * SpecificDeployment. Possible values include: 'LastSuccessful',
 * 'SpecificDeployment'
 *
 * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
 * deployment to be used on error case.
 *
 * @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 DeploymentExtended} 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 _beginCreateOrUpdateAtSubscriptionScope(deploymentName, parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

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

/**
 * @summary Deletes a deployment from the deployment history.
 *
 * A template deployment that is currently running cannot be deleted. Deleting
 * a template deployment removes the associated deployment operations. Deleting
 * a template deployment does not affect the state of the resource group. This
 * is an asynchronous operation that returns a status of 202 until the template
 * deployment is successfully deleted. The Location response header contains
 * the URI that is used to obtain the status of the process. While the process
 * is running, a call to the URI in the Location header returns a status of
 * 202. When the process finishes, the URI in the Location header returns a
 * status of 204 on success. If the asynchronous request failed, the URI in the
 * Location header returns an error-level status code.
 *
 * @param {string} resourceGroupName The name of the resource group with the
 * deployment to delete. The name is case insensitive.
 *
 * @param {string} deploymentName The name of the deployment to delete.
 *
 * @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, deploymentName, 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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/Microsoft.Resources/deployments/{deploymentName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{deploymentName}', encodeURIComponent(deploymentName));
  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) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;

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

/**
 * @summary Deploys resources to a resource group.
 *
 * You can provide the template and parameters directly in the request or link
 * to JSON files.
 *
 * @param {string} resourceGroupName The name of the resource group to deploy
 * the resources to. The name is case insensitive. The resource group must
 * already exist.
 *
 * @param {string} deploymentName The name of the deployment.
 *
 * @param {object} parameters Additional parameters supplied to the operation.
 *
 * @param {string} [parameters.location] The location to store the deployment
 * data.
 *
 * @param {object} parameters.properties The deployment properties.
 *
 * @param {object} [parameters.properties.template] The template content. You
 * use this element when you want to pass the template syntax directly in the
 * request rather than link to an existing template. It can be a JObject or
 * well-formed JSON string. Use either the templateLink property or the
 * template property, but not both.
 *
 * @param {object} [parameters.properties.templateLink] The URI of the
 * template. Use either the templateLink property or the template property, but
 * not both.
 *
 * @param {string} parameters.properties.templateLink.uri The URI of the
 * template to deploy.
 *
 * @param {string} [parameters.properties.templateLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {object} [parameters.properties.parameters] Name and value pairs that
 * define the deployment parameters for the template. You use this element when
 * you want to provide the parameter values directly in the request rather than
 * link to an existing parameter file. Use either the parametersLink property
 * or the parameters property, but not both. It can be a JObject or a well
 * formed JSON string.
 *
 * @param {object} [parameters.properties.parametersLink] The URI of parameters
 * file. You use this element to link to an existing parameters file. Use
 * either the parametersLink property or the parameters property, but not both.
 *
 * @param {string} parameters.properties.parametersLink.uri The URI of the
 * parameters file.
 *
 * @param {string} [parameters.properties.parametersLink.contentVersion] If
 * included, must match the ContentVersion in the template.
 *
 * @param {string} parameters.properties.mode The mode that is used to deploy
 * resources. This value can be either Incremental or Complete. In Incremental
 * mode, resources are deployed without deleting existing resources that are
 * not included in the template. In Complete mode, resources are deployed and
 * existing resources in the resource group that are not included in the
 * template are deleted. Be careful when using Complete mode as you may
 * unintentionally delete resources. Possible values include: 'Incremental',
 * 'Complete'
 *
 * @param {object} [parameters.properties.debugSetting] The debug setting of
 * the deployment.
 *
 * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
 * the type of information to log for debugging. The permitted values are none,
 * requestContent, responseContent, or both requestContent and responseContent
 * separated by a comma. The default is none. When setting this value,
 * carefully consider the type of information you are passing in during
 * deployment. By logging information about the request or response, you could
 * potentially expose sensitive data that is retrieved through the deployment
 * operations.
 *
 * @param {object} [parameters.properties.onErrorDeployment] The deployment on
 * error behavior.
 *
 * @param {string} [parameters.properties.onErrorDeployment.type] The
 * deployment on error behavior type. Possible values are LastSuccessful and
 * SpecificDeployment. Possible values include: 'LastSuccessful',
 * 'SpecificDeployment'
 *
 * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
 * deployment to be used on error case.
 *
 * @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 DeploymentExtended} 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 _beginCreateOrUpdate(resourceGroupName, deploymentName, parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (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 (deploymentName === null || deploymentName === undefined || typeof deploymentName.valueOf() !== 'string') {
      throw new Error('deploymentName cannot be null or undefined and it must be of type string.');
    }
    if (deploymentName !== null && deploymentName !== undefined) {
      if (deploymentName.length > 64)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MaxLength": 64');
      }
      if (deploymentName.length < 1)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "MinLength": 1');
      }
      if (deploymentName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"deploymentName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

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

/**
 * Get all the deployments for a subscription.
 *
 * @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 DeploymentListResult} 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 _listAtSubscriptionScopeNext(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) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['DeploymentListResult']().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);
  });
}

/**
 * Get all the deployments for a resource group.
 *
 * @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 DeploymentListResult} 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 _listByResourceGroupNext(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) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['DeploymentListResult']().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 Deployments. */
class Deployments {
  /**
   * Create a Deployments.
   * @param {ResourceManagementClient} client Reference to the service client.
   */
  constructor(client) {
    this.client = client;
    this._deleteAtSubscriptionScope = _deleteAtSubscriptionScope;
    this._checkExistenceAtSubscriptionScope = _checkExistenceAtSubscriptionScope;
    this._createOrUpdateAtSubscriptionScope = _createOrUpdateAtSubscriptionScope;
    this._getAtSubscriptionScope = _getAtSubscriptionScope;
    this._cancelAtSubscriptionScope = _cancelAtSubscriptionScope;
    this._validateAtSubscriptionScope = _validateAtSubscriptionScope;
    this._exportTemplateAtSubscriptionScope = _exportTemplateAtSubscriptionScope;
    this._listAtSubscriptionScope = _listAtSubscriptionScope;
    this._deleteMethod = _deleteMethod;
    this._checkExistence = _checkExistence;
    this._createOrUpdate = _createOrUpdate;
    this._get = _get;
    this._cancel = _cancel;
    this._validate = _validate;
    this._exportTemplate = _exportTemplate;
    this._listByResourceGroup = _listByResourceGroup;
    this._beginDeleteAtSubscriptionScope = _beginDeleteAtSubscriptionScope;
    this._beginCreateOrUpdateAtSubscriptionScope = _beginCreateOrUpdateAtSubscriptionScope;
    this._beginDeleteMethod = _beginDeleteMethod;
    this._beginCreateOrUpdate = _beginCreateOrUpdate;
    this._listAtSubscriptionScopeNext = _listAtSubscriptionScopeNext;
    this._listByResourceGroupNext = _listByResourceGroupNext;
  }

  /**
   * @summary Deletes a deployment from the deployment history.
   *
   * A template deployment that is currently running cannot be deleted. Deleting
   * a template deployment removes the associated deployment operations. This is
   * an asynchronous operation that returns a status of 202 until the template
   * deployment is successfully deleted. The Location response header contains
   * the URI that is used to obtain the status of the process. While the process
   * is running, a call to the URI in the Location header returns a status of
   * 202. When the process finishes, the URI in the Location header returns a
   * status of 204 on success. If the asynchronous request failed, the URI in the
   * Location header returns an error-level status code.
   *
   * @param {string} deploymentName The name of the deployment to delete.
   *
   * @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.
   */
  deleteAtSubscriptionScopeWithHttpOperationResponse(deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._deleteAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Deletes a deployment from the deployment history.
   *
   * A template deployment that is currently running cannot be deleted. Deleting
   * a template deployment removes the associated deployment operations. This is
   * an asynchronous operation that returns a status of 202 until the template
   * deployment is successfully deleted. The Location response header contains
   * the URI that is used to obtain the status of the process. While the process
   * is running, a call to the URI in the Location header returns a status of
   * 202. When the process finishes, the URI in the Location header returns a
   * status of 204 on success. If the asynchronous request failed, the URI in the
   * Location header returns an error-level status code.
   *
   * @param {string} deploymentName The name of the deployment to delete.
   *
   * @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.
   */
  deleteAtSubscriptionScope(deploymentName, 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._deleteAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._deleteAtSubscriptionScope(deploymentName, options, optionalCallback);
    }
  }

  /**
   * Checks whether the deployment exists.
   *
   * @param {string} deploymentName The name of the deployment to check.
   *
   * @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<Boolean>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  checkExistenceAtSubscriptionScopeWithHttpOperationResponse(deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._checkExistenceAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Checks whether the deployment exists.
   *
   * @param {string} deploymentName The name of the deployment to check.
   *
   * @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 {Boolean} - 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.
   *
   *                      {boolean} [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.
   */
  checkExistenceAtSubscriptionScope(deploymentName, 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._checkExistenceAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._checkExistenceAtSubscriptionScope(deploymentName, options, optionalCallback);
    }
  }

  /**
   * @summary Deploys resources at subscription scope.
   *
   * You can provide the template and parameters directly in the request or link
   * to JSON files.
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Additional parameters supplied to the operation.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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<DeploymentExtended>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createOrUpdateAtSubscriptionScopeWithHttpOperationResponse(deploymentName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._createOrUpdateAtSubscriptionScope(deploymentName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Deploys resources at subscription scope.
   *
   * You can provide the template and parameters directly in the request or link
   * to JSON files.
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Additional parameters supplied to the operation.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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 {DeploymentExtended} - 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 DeploymentExtended} 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.
   */
  createOrUpdateAtSubscriptionScope(deploymentName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._createOrUpdateAtSubscriptionScope(deploymentName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._createOrUpdateAtSubscriptionScope(deploymentName, parameters, options, optionalCallback);
    }
  }

  /**
   * Gets a deployment.
   *
   * @param {string} deploymentName The name of the deployment to get.
   *
   * @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<DeploymentExtended>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getAtSubscriptionScopeWithHttpOperationResponse(deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._getAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets a deployment.
   *
   * @param {string} deploymentName The name of the deployment to get.
   *
   * @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 {DeploymentExtended} - 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 DeploymentExtended} 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.
   */
  getAtSubscriptionScope(deploymentName, 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._getAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._getAtSubscriptionScope(deploymentName, options, optionalCallback);
    }
  }

  /**
   * @summary Cancels a currently running template deployment.
   *
   * You can cancel a deployment only if the provisioningState is Accepted or
   * Running. After the deployment is canceled, the provisioningState is set to
   * Canceled. Canceling a template deployment stops the currently running
   * template deployment and leaves the resources partially deployed.
   *
   * @param {string} deploymentName The name of the deployment to cancel.
   *
   * @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.
   */
  cancelAtSubscriptionScopeWithHttpOperationResponse(deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._cancelAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Cancels a currently running template deployment.
   *
   * You can cancel a deployment only if the provisioningState is Accepted or
   * Running. After the deployment is canceled, the provisioningState is set to
   * Canceled. Canceling a template deployment stops the currently running
   * template deployment and leaves the resources partially deployed.
   *
   * @param {string} deploymentName The name of the deployment to cancel.
   *
   * @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.
   */
  cancelAtSubscriptionScope(deploymentName, 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._cancelAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._cancelAtSubscriptionScope(deploymentName, options, optionalCallback);
    }
  }

  /**
   * Validates whether the specified template is syntactically correct and will
   * be accepted by Azure Resource Manager..
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Parameters to validate.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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<DeploymentValidateResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  validateAtSubscriptionScopeWithHttpOperationResponse(deploymentName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._validateAtSubscriptionScope(deploymentName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Validates whether the specified template is syntactically correct and will
   * be accepted by Azure Resource Manager..
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Parameters to validate.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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 {DeploymentValidateResult} - 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 DeploymentValidateResult} 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.
   */
  validateAtSubscriptionScope(deploymentName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._validateAtSubscriptionScope(deploymentName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._validateAtSubscriptionScope(deploymentName, parameters, options, optionalCallback);
    }
  }

  /**
   * Exports the template used for specified deployment.
   *
   * @param {string} deploymentName The name of the deployment from which to get
   * the template.
   *
   * @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<DeploymentExportResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  exportTemplateAtSubscriptionScopeWithHttpOperationResponse(deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._exportTemplateAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Exports the template used for specified deployment.
   *
   * @param {string} deploymentName The name of the deployment from which to get
   * the template.
   *
   * @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 {DeploymentExportResult} - 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 DeploymentExportResult} 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.
   */
  exportTemplateAtSubscriptionScope(deploymentName, 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._exportTemplateAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._exportTemplateAtSubscriptionScope(deploymentName, options, optionalCallback);
    }
  }

  /**
   * Get all the deployments for a subscription.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] The filter to apply on the operation. For
   * example, you can use $filter=provisioningState eq '{state}'.
   *
   * @param {number} [options.top] The number of results to get. If null is
   * passed, returns all deployments.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<DeploymentListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listAtSubscriptionScopeWithHttpOperationResponse(options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listAtSubscriptionScope(options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Get all the deployments for a subscription.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] The filter to apply on the operation. For
   * example, you can use $filter=provisioningState eq '{state}'.
   *
   * @param {number} [options.top] The number of results to get. If null is
   * passed, returns all deployments.
   *
   * @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 {DeploymentListResult} - 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 DeploymentListResult} 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.
   */
  listAtSubscriptionScope(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._listAtSubscriptionScope(options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listAtSubscriptionScope(options, optionalCallback);
    }
  }

  /**
   * @summary Deletes a deployment from the deployment history.
   *
   * A template deployment that is currently running cannot be deleted. Deleting
   * a template deployment removes the associated deployment operations. Deleting
   * a template deployment does not affect the state of the resource group. This
   * is an asynchronous operation that returns a status of 202 until the template
   * deployment is successfully deleted. The Location response header contains
   * the URI that is used to obtain the status of the process. While the process
   * is running, a call to the URI in the Location header returns a status of
   * 202. When the process finishes, the URI in the Location header returns a
   * status of 204 on success. If the asynchronous request failed, the URI in the
   * Location header returns an error-level status code.
   *
   * @param {string} resourceGroupName The name of the resource group with the
   * deployment to delete. The name is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment to delete.
   *
   * @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, deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._deleteMethod(resourceGroupName, deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Deletes a deployment from the deployment history.
   *
   * A template deployment that is currently running cannot be deleted. Deleting
   * a template deployment removes the associated deployment operations. Deleting
   * a template deployment does not affect the state of the resource group. This
   * is an asynchronous operation that returns a status of 202 until the template
   * deployment is successfully deleted. The Location response header contains
   * the URI that is used to obtain the status of the process. While the process
   * is running, a call to the URI in the Location header returns a status of
   * 202. When the process finishes, the URI in the Location header returns a
   * status of 204 on success. If the asynchronous request failed, the URI in the
   * Location header returns an error-level status code.
   *
   * @param {string} resourceGroupName The name of the resource group with the
   * deployment to delete. The name is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment to delete.
   *
   * @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, deploymentName, 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, deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._deleteMethod(resourceGroupName, deploymentName, options, optionalCallback);
    }
  }

  /**
   * Checks whether the deployment exists.
   *
   * @param {string} resourceGroupName The name of the resource group with the
   * deployment to check. The name is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment to check.
   *
   * @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<Boolean>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  checkExistenceWithHttpOperationResponse(resourceGroupName, deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._checkExistence(resourceGroupName, deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Checks whether the deployment exists.
   *
   * @param {string} resourceGroupName The name of the resource group with the
   * deployment to check. The name is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment to check.
   *
   * @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 {Boolean} - 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.
   *
   *                      {boolean} [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.
   */
  checkExistence(resourceGroupName, deploymentName, 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._checkExistence(resourceGroupName, deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._checkExistence(resourceGroupName, deploymentName, options, optionalCallback);
    }
  }

  /**
   * @summary Deploys resources to a resource group.
   *
   * You can provide the template and parameters directly in the request or link
   * to JSON files.
   *
   * @param {string} resourceGroupName The name of the resource group to deploy
   * the resources to. The name is case insensitive. The resource group must
   * already exist.
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Additional parameters supplied to the operation.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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<DeploymentExtended>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createOrUpdateWithHttpOperationResponse(resourceGroupName, deploymentName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._createOrUpdate(resourceGroupName, deploymentName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Deploys resources to a resource group.
   *
   * You can provide the template and parameters directly in the request or link
   * to JSON files.
   *
   * @param {string} resourceGroupName The name of the resource group to deploy
   * the resources to. The name is case insensitive. The resource group must
   * already exist.
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Additional parameters supplied to the operation.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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 {DeploymentExtended} - 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 DeploymentExtended} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  createOrUpdate(resourceGroupName, deploymentName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._createOrUpdate(resourceGroupName, deploymentName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._createOrUpdate(resourceGroupName, deploymentName, parameters, options, optionalCallback);
    }
  }

  /**
   * Gets a deployment.
   *
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment to get.
   *
   * @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<DeploymentExtended>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getWithHttpOperationResponse(resourceGroupName, deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._get(resourceGroupName, deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets a deployment.
   *
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment to get.
   *
   * @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 {DeploymentExtended} - 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 DeploymentExtended} 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, deploymentName, 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, deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._get(resourceGroupName, deploymentName, options, optionalCallback);
    }
  }

  /**
   * @summary Cancels a currently running template deployment.
   *
   * You can cancel a deployment only if the provisioningState is Accepted or
   * Running. After the deployment is canceled, the provisioningState is set to
   * Canceled. Canceling a template deployment stops the currently running
   * template deployment and leaves the resource group partially deployed.
   *
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment to cancel.
   *
   * @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.
   */
  cancelWithHttpOperationResponse(resourceGroupName, deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._cancel(resourceGroupName, deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Cancels a currently running template deployment.
   *
   * You can cancel a deployment only if the provisioningState is Accepted or
   * Running. After the deployment is canceled, the provisioningState is set to
   * Canceled. Canceling a template deployment stops the currently running
   * template deployment and leaves the resource group partially deployed.
   *
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment to cancel.
   *
   * @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.
   */
  cancel(resourceGroupName, deploymentName, 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._cancel(resourceGroupName, deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._cancel(resourceGroupName, deploymentName, options, optionalCallback);
    }
  }

  /**
   * Validates whether the specified template is syntactically correct and will
   * be accepted by Azure Resource Manager..
   *
   * @param {string} resourceGroupName The name of the resource group the
   * template will be deployed to. The name is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Parameters to validate.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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<DeploymentValidateResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  validateWithHttpOperationResponse(resourceGroupName, deploymentName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._validate(resourceGroupName, deploymentName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Validates whether the specified template is syntactically correct and will
   * be accepted by Azure Resource Manager..
   *
   * @param {string} resourceGroupName The name of the resource group the
   * template will be deployed to. The name is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Parameters to validate.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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 {DeploymentValidateResult} - 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 DeploymentValidateResult} 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.
   */
  validate(resourceGroupName, deploymentName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._validate(resourceGroupName, deploymentName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._validate(resourceGroupName, deploymentName, parameters, options, optionalCallback);
    }
  }

  /**
   * Exports the template used for specified deployment.
   *
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment from which to get
   * the template.
   *
   * @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<DeploymentExportResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  exportTemplateWithHttpOperationResponse(resourceGroupName, deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._exportTemplate(resourceGroupName, deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Exports the template used for specified deployment.
   *
   * @param {string} resourceGroupName The name of the resource group. The name
   * is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment from which to get
   * the template.
   *
   * @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 {DeploymentExportResult} - 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 DeploymentExportResult} 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.
   */
  exportTemplate(resourceGroupName, deploymentName, 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._exportTemplate(resourceGroupName, deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._exportTemplate(resourceGroupName, deploymentName, options, optionalCallback);
    }
  }

  /**
   * Get all the deployments for a resource group.
   *
   * @param {string} resourceGroupName The name of the resource group with the
   * deployments to get. The name is case insensitive.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] The filter to apply on the operation. For
   * example, you can use $filter=provisioningState eq '{state}'.
   *
   * @param {number} [options.top] The number of results to get. If null is
   * passed, returns all deployments.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<DeploymentListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByResourceGroupWithHttpOperationResponse(resourceGroupName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByResourceGroup(resourceGroupName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Get all the deployments for a resource group.
   *
   * @param {string} resourceGroupName The name of the resource group with the
   * deployments to get. The name is case insensitive.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] The filter to apply on the operation. For
   * example, you can use $filter=provisioningState eq '{state}'.
   *
   * @param {number} [options.top] The number of results to get. If null is
   * passed, returns all deployments.
   *
   * @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 {DeploymentListResult} - 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 DeploymentListResult} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  listByResourceGroup(resourceGroupName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listByResourceGroup(resourceGroupName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByResourceGroup(resourceGroupName, options, optionalCallback);
    }
  }

  /**
   * @summary Deletes a deployment from the deployment history.
   *
   * A template deployment that is currently running cannot be deleted. Deleting
   * a template deployment removes the associated deployment operations. This is
   * an asynchronous operation that returns a status of 202 until the template
   * deployment is successfully deleted. The Location response header contains
   * the URI that is used to obtain the status of the process. While the process
   * is running, a call to the URI in the Location header returns a status of
   * 202. When the process finishes, the URI in the Location header returns a
   * status of 204 on success. If the asynchronous request failed, the URI in the
   * Location header returns an error-level status code.
   *
   * @param {string} deploymentName The name of the deployment to delete.
   *
   * @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.
   */
  beginDeleteAtSubscriptionScopeWithHttpOperationResponse(deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginDeleteAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Deletes a deployment from the deployment history.
   *
   * A template deployment that is currently running cannot be deleted. Deleting
   * a template deployment removes the associated deployment operations. This is
   * an asynchronous operation that returns a status of 202 until the template
   * deployment is successfully deleted. The Location response header contains
   * the URI that is used to obtain the status of the process. While the process
   * is running, a call to the URI in the Location header returns a status of
   * 202. When the process finishes, the URI in the Location header returns a
   * status of 204 on success. If the asynchronous request failed, the URI in the
   * Location header returns an error-level status code.
   *
   * @param {string} deploymentName The name of the deployment to delete.
   *
   * @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.
   */
  beginDeleteAtSubscriptionScope(deploymentName, 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._beginDeleteAtSubscriptionScope(deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginDeleteAtSubscriptionScope(deploymentName, options, optionalCallback);
    }
  }

  /**
   * @summary Deploys resources at subscription scope.
   *
   * You can provide the template and parameters directly in the request or link
   * to JSON files.
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Additional parameters supplied to the operation.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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<DeploymentExtended>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginCreateOrUpdateAtSubscriptionScopeWithHttpOperationResponse(deploymentName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginCreateOrUpdateAtSubscriptionScope(deploymentName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Deploys resources at subscription scope.
   *
   * You can provide the template and parameters directly in the request or link
   * to JSON files.
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Additional parameters supplied to the operation.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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 {DeploymentExtended} - 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 DeploymentExtended} 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.
   */
  beginCreateOrUpdateAtSubscriptionScope(deploymentName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._beginCreateOrUpdateAtSubscriptionScope(deploymentName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginCreateOrUpdateAtSubscriptionScope(deploymentName, parameters, options, optionalCallback);
    }
  }

  /**
   * @summary Deletes a deployment from the deployment history.
   *
   * A template deployment that is currently running cannot be deleted. Deleting
   * a template deployment removes the associated deployment operations. Deleting
   * a template deployment does not affect the state of the resource group. This
   * is an asynchronous operation that returns a status of 202 until the template
   * deployment is successfully deleted. The Location response header contains
   * the URI that is used to obtain the status of the process. While the process
   * is running, a call to the URI in the Location header returns a status of
   * 202. When the process finishes, the URI in the Location header returns a
   * status of 204 on success. If the asynchronous request failed, the URI in the
   * Location header returns an error-level status code.
   *
   * @param {string} resourceGroupName The name of the resource group with the
   * deployment to delete. The name is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment to delete.
   *
   * @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, deploymentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginDeleteMethod(resourceGroupName, deploymentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Deletes a deployment from the deployment history.
   *
   * A template deployment that is currently running cannot be deleted. Deleting
   * a template deployment removes the associated deployment operations. Deleting
   * a template deployment does not affect the state of the resource group. This
   * is an asynchronous operation that returns a status of 202 until the template
   * deployment is successfully deleted. The Location response header contains
   * the URI that is used to obtain the status of the process. While the process
   * is running, a call to the URI in the Location header returns a status of
   * 202. When the process finishes, the URI in the Location header returns a
   * status of 204 on success. If the asynchronous request failed, the URI in the
   * Location header returns an error-level status code.
   *
   * @param {string} resourceGroupName The name of the resource group with the
   * deployment to delete. The name is case insensitive.
   *
   * @param {string} deploymentName The name of the deployment to delete.
   *
   * @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, deploymentName, 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, deploymentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginDeleteMethod(resourceGroupName, deploymentName, options, optionalCallback);
    }
  }

  /**
   * @summary Deploys resources to a resource group.
   *
   * You can provide the template and parameters directly in the request or link
   * to JSON files.
   *
   * @param {string} resourceGroupName The name of the resource group to deploy
   * the resources to. The name is case insensitive. The resource group must
   * already exist.
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Additional parameters supplied to the operation.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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<DeploymentExtended>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginCreateOrUpdateWithHttpOperationResponse(resourceGroupName, deploymentName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginCreateOrUpdate(resourceGroupName, deploymentName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Deploys resources to a resource group.
   *
   * You can provide the template and parameters directly in the request or link
   * to JSON files.
   *
   * @param {string} resourceGroupName The name of the resource group to deploy
   * the resources to. The name is case insensitive. The resource group must
   * already exist.
   *
   * @param {string} deploymentName The name of the deployment.
   *
   * @param {object} parameters Additional parameters supplied to the operation.
   *
   * @param {string} [parameters.location] The location to store the deployment
   * data.
   *
   * @param {object} parameters.properties The deployment properties.
   *
   * @param {object} [parameters.properties.template] The template content. You
   * use this element when you want to pass the template syntax directly in the
   * request rather than link to an existing template. It can be a JObject or
   * well-formed JSON string. Use either the templateLink property or the
   * template property, but not both.
   *
   * @param {object} [parameters.properties.templateLink] The URI of the
   * template. Use either the templateLink property or the template property, but
   * not both.
   *
   * @param {string} parameters.properties.templateLink.uri The URI of the
   * template to deploy.
   *
   * @param {string} [parameters.properties.templateLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {object} [parameters.properties.parameters] Name and value pairs that
   * define the deployment parameters for the template. You use this element when
   * you want to provide the parameter values directly in the request rather than
   * link to an existing parameter file. Use either the parametersLink property
   * or the parameters property, but not both. It can be a JObject or a well
   * formed JSON string.
   *
   * @param {object} [parameters.properties.parametersLink] The URI of parameters
   * file. You use this element to link to an existing parameters file. Use
   * either the parametersLink property or the parameters property, but not both.
   *
   * @param {string} parameters.properties.parametersLink.uri The URI of the
   * parameters file.
   *
   * @param {string} [parameters.properties.parametersLink.contentVersion] If
   * included, must match the ContentVersion in the template.
   *
   * @param {string} parameters.properties.mode The mode that is used to deploy
   * resources. This value can be either Incremental or Complete. In Incremental
   * mode, resources are deployed without deleting existing resources that are
   * not included in the template. In Complete mode, resources are deployed and
   * existing resources in the resource group that are not included in the
   * template are deleted. Be careful when using Complete mode as you may
   * unintentionally delete resources. Possible values include: 'Incremental',
   * 'Complete'
   *
   * @param {object} [parameters.properties.debugSetting] The debug setting of
   * the deployment.
   *
   * @param {string} [parameters.properties.debugSetting.detailLevel] Specifies
   * the type of information to log for debugging. The permitted values are none,
   * requestContent, responseContent, or both requestContent and responseContent
   * separated by a comma. The default is none. When setting this value,
   * carefully consider the type of information you are passing in during
   * deployment. By logging information about the request or response, you could
   * potentially expose sensitive data that is retrieved through the deployment
   * operations.
   *
   * @param {object} [parameters.properties.onErrorDeployment] The deployment on
   * error behavior.
   *
   * @param {string} [parameters.properties.onErrorDeployment.type] The
   * deployment on error behavior type. Possible values are LastSuccessful and
   * SpecificDeployment. Possible values include: 'LastSuccessful',
   * 'SpecificDeployment'
   *
   * @param {string} [parameters.properties.onErrorDeployment.deploymentName] The
   * deployment to be used on error case.
   *
   * @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 {DeploymentExtended} - 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 DeploymentExtended} 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.
   */
  beginCreateOrUpdate(resourceGroupName, deploymentName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._beginCreateOrUpdate(resourceGroupName, deploymentName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginCreateOrUpdate(resourceGroupName, deploymentName, parameters, options, optionalCallback);
    }
  }

  /**
   * Get all the deployments for a subscription.
   *
   * @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<DeploymentListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listAtSubscriptionScopeNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listAtSubscriptionScopeNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Get all the deployments for a subscription.
   *
   * @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 {DeploymentListResult} - 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 DeploymentListResult} 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.
   */
  listAtSubscriptionScopeNext(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._listAtSubscriptionScopeNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listAtSubscriptionScopeNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * Get all the deployments for a resource group.
   *
   * @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<DeploymentListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByResourceGroupNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Get all the deployments for a resource group.
   *
   * @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 {DeploymentListResult} - 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 DeploymentListResult} 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.
   */
  listByResourceGroupNext(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._listByResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByResourceGroupNext(nextPageLink, options, optionalCallback);
    }
  }

}

module.exports = Deployments;
