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

'use strict';

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

/**
 * Lists all of the certificates in the specified account.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the Batch account.
 *
 * @param {string} accountName The name of the Batch account.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {number} [options.maxresults] The maximum number of items to return
 * in the response.
 *
 * @param {string} [options.select] Comma separated list of properties that
 * should be returned. e.g. "properties/provisioningState". Only top level
 * properties under properties/ are valid for selection.
 *
 * @param {string} [options.filter] OData filter expression. Valid properties
 * for filtering are "properties/provisioningState",
 * "properties/provisioningStateTransitionTime", "name".
 *
 * @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 ListCertificatesResult} 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 _listByBatchAccount(resourceGroupName, accountName, 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 maxresults = (options && options.maxresults !== undefined) ? options.maxresults : undefined;
  let select = (options && options.select !== undefined) ? options.select : undefined;
  let filter = (options && options.filter !== undefined) ? options.filter : 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 (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
      throw new Error('accountName cannot be null or undefined and it must be of type string.');
    }
    if (accountName !== null && accountName !== undefined) {
      if (accountName.length > 24)
      {
        throw new Error('"accountName" should satisfy the constraint - "MaxLength": 24');
      }
      if (accountName.length < 3)
      {
        throw new Error('"accountName" should satisfy the constraint - "MinLength": 3');
      }
      if (accountName.match(/^[a-zA-Z0-9]+$/) === null)
      {
        throw new Error('"accountName" should satisfy the constraint - "Pattern": /^[a-zA-Z0-9]+$/');
      }
    }
    if (maxresults !== null && maxresults !== undefined && typeof maxresults !== 'number') {
      throw new Error('maxresults must be of type number.');
    }
    if (select !== null && select !== undefined && typeof select.valueOf() !== 'string') {
      throw new Error('select must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Batch/batchAccounts/{accountName}/certificates';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{accountName}', encodeURIComponent(accountName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  if (maxresults !== null && maxresults !== undefined) {
    queryParameters.push('maxresults=' + encodeURIComponent(maxresults.toString()));
  }
  if (select !== null && select !== undefined) {
    queryParameters.push('$select=' + encodeURIComponent(select));
  }
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  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['ListCertificatesResult']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

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


/**
 * Creates a new certificate inside the specified account.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the Batch account.
 *
 * @param {string} accountName The name of the Batch account.
 *
 * @param {string} certificateName The identifier for the certificate. This
 * must be made up of algorithm and thumbprint separated by a dash, and must
 * match the certificate data in the request. For example SHA1-a3d1c5.
 *
 * @param {object} parameters Additional parameters for certificate creation.
 *
 * @param {string} [parameters.thumbprintAlgorithm] The algorithm of the
 * certificate thumbprint. This must match the first portion of the certificate
 * name. Currently required to be 'SHA1'.
 *
 * @param {string} [parameters.thumbprint] The thumbprint of the certificate.
 * This must match the thumbprint from the name.
 *
 * @param {string} [parameters.format] The format of the certificate - either
 * Pfx or Cer. If omitted, the default is Pfx. Possible values include: 'Pfx',
 * 'Cer'
 *
 * @param {string} parameters.data The base64-encoded contents of the
 * certificate. The maximum size is 10KB.
 *
 * @param {string} [parameters.password] The password to access the
 * certificate's private key. This must not be specified if the certificate
 * format is Cer.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.ifMatch] The entity state (ETag) version of the
 * certificate to update. A value of "*" can be used to apply the operation
 * only if the certificate already exists. If omitted, this operation will
 * always be applied.
 *
 * @param {string} [options.ifNoneMatch] Set to '*' to allow a new certificate
 * to be created, but to prevent updating an existing certificate. Other values
 * will be ignored.
 *
 * @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 Certificate} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _create(resourceGroupName, accountName, certificateName, 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.beginCreate(resourceGroupName, accountName, certificateName, 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['Certificate']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }

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

/**
 * Updates the properties of an existing certificate.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the Batch account.
 *
 * @param {string} accountName The name of the Batch account.
 *
 * @param {string} certificateName The identifier for the certificate. This
 * must be made up of algorithm and thumbprint separated by a dash, and must
 * match the certificate data in the request. For example SHA1-a3d1c5.
 *
 * @param {object} parameters Certificate entity to update.
 *
 * @param {string} [parameters.thumbprintAlgorithm] The algorithm of the
 * certificate thumbprint. This must match the first portion of the certificate
 * name. Currently required to be 'SHA1'.
 *
 * @param {string} [parameters.thumbprint] The thumbprint of the certificate.
 * This must match the thumbprint from the name.
 *
 * @param {string} [parameters.format] The format of the certificate - either
 * Pfx or Cer. If omitted, the default is Pfx. Possible values include: 'Pfx',
 * 'Cer'
 *
 * @param {string} parameters.data The base64-encoded contents of the
 * certificate. The maximum size is 10KB.
 *
 * @param {string} [parameters.password] The password to access the
 * certificate's private key. This must not be specified if the certificate
 * format is Cer.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.ifMatch] The entity state (ETag) version of the
 * certificate to update. This value can be omitted or set to "*" to apply the
 * operation unconditionally.
 *
 * @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 Certificate} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _update(resourceGroupName, accountName, certificateName, 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.');
  }
  let ifMatch = (options && options.ifMatch !== undefined) ? options.ifMatch : 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 (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
      throw new Error('accountName cannot be null or undefined and it must be of type string.');
    }
    if (accountName !== null && accountName !== undefined) {
      if (accountName.length > 24)
      {
        throw new Error('"accountName" should satisfy the constraint - "MaxLength": 24');
      }
      if (accountName.length < 3)
      {
        throw new Error('"accountName" should satisfy the constraint - "MinLength": 3');
      }
      if (accountName.match(/^[a-zA-Z0-9]+$/) === null)
      {
        throw new Error('"accountName" should satisfy the constraint - "Pattern": /^[a-zA-Z0-9]+$/');
      }
    }
    if (certificateName === null || certificateName === undefined || typeof certificateName.valueOf() !== 'string') {
      throw new Error('certificateName cannot be null or undefined and it must be of type string.');
    }
    if (certificateName !== null && certificateName !== undefined) {
      if (certificateName.length > 45)
      {
        throw new Error('"certificateName" should satisfy the constraint - "MaxLength": 45');
      }
      if (certificateName.length < 5)
      {
        throw new Error('"certificateName" should satisfy the constraint - "MinLength": 5');
      }
      if (certificateName.match(/^[\w]+-[\w]+$/) === null)
      {
        throw new Error('"certificateName" should satisfy the constraint - "Pattern": /^[\w]+-[\w]+$/');
      }
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (ifMatch !== null && ifMatch !== undefined && typeof ifMatch.valueOf() !== 'string') {
      throw new Error('ifMatch must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

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

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


/**
 * Deletes the specified certificate.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the Batch account.
 *
 * @param {string} accountName The name of the Batch account.
 *
 * @param {string} certificateName The identifier for the certificate. This
 * must be made up of algorithm and thumbprint separated by a dash, and must
 * match the certificate data in the request. For example SHA1-a3d1c5.
 *
 * @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, accountName, certificateName, 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, accountName, certificateName, 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);
    });
  });
}

/**
 * Gets information about the specified certificate.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the Batch account.
 *
 * @param {string} accountName The name of the Batch account.
 *
 * @param {string} certificateName The identifier for the certificate. This
 * must be made up of algorithm and thumbprint separated by a dash, and must
 * match the certificate data in the request. For example SHA1-a3d1c5.
 *
 * @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 Certificate} 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, accountName, certificateName, 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 (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
      throw new Error('accountName cannot be null or undefined and it must be of type string.');
    }
    if (accountName !== null && accountName !== undefined) {
      if (accountName.length > 24)
      {
        throw new Error('"accountName" should satisfy the constraint - "MaxLength": 24');
      }
      if (accountName.length < 3)
      {
        throw new Error('"accountName" should satisfy the constraint - "MinLength": 3');
      }
      if (accountName.match(/^[a-zA-Z0-9]+$/) === null)
      {
        throw new Error('"accountName" should satisfy the constraint - "Pattern": /^[a-zA-Z0-9]+$/');
      }
    }
    if (certificateName === null || certificateName === undefined || typeof certificateName.valueOf() !== 'string') {
      throw new Error('certificateName cannot be null or undefined and it must be of type string.');
    }
    if (certificateName !== null && certificateName !== undefined) {
      if (certificateName.length > 45)
      {
        throw new Error('"certificateName" should satisfy the constraint - "MaxLength": 45');
      }
      if (certificateName.length < 5)
      {
        throw new Error('"certificateName" should satisfy the constraint - "MinLength": 5');
      }
      if (certificateName.match(/^[\w]+-[\w]+$/) === null)
      {
        throw new Error('"certificateName" should satisfy the constraint - "Pattern": /^[\w]+-[\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.Batch/batchAccounts/{accountName}/certificates/{certificateName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{accountName}', encodeURIComponent(accountName));
  requestUrl = requestUrl.replace('{certificateName}', encodeURIComponent(certificateName));
  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['Certificate']().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 failed deletion of a certificate from the specified
 * account.
 *
 * If you try to delete a certificate that is being used by a pool or compute
 * node, the status of the certificate changes to deleteFailed. If you decide
 * that you want to continue using the certificate, you can use this operation
 * to set the status of the certificate back to active. If you intend to delete
 * the certificate, you do not need to run this operation after the deletion
 * failed. You must make sure that the certificate is not being used by any
 * resources, and then you can try again to delete the certificate.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the Batch account.
 *
 * @param {string} accountName The name of the Batch account.
 *
 * @param {string} certificateName The identifier for the certificate. This
 * must be made up of algorithm and thumbprint separated by a dash, and must
 * match the certificate data in the request. For example SHA1-a3d1c5.
 *
 * @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 Certificate} 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 _cancelDeletion(resourceGroupName, accountName, certificateName, 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 (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
      throw new Error('accountName cannot be null or undefined and it must be of type string.');
    }
    if (accountName !== null && accountName !== undefined) {
      if (accountName.length > 24)
      {
        throw new Error('"accountName" should satisfy the constraint - "MaxLength": 24');
      }
      if (accountName.length < 3)
      {
        throw new Error('"accountName" should satisfy the constraint - "MinLength": 3');
      }
      if (accountName.match(/^[a-zA-Z0-9]+$/) === null)
      {
        throw new Error('"accountName" should satisfy the constraint - "Pattern": /^[a-zA-Z0-9]+$/');
      }
    }
    if (certificateName === null || certificateName === undefined || typeof certificateName.valueOf() !== 'string') {
      throw new Error('certificateName cannot be null or undefined and it must be of type string.');
    }
    if (certificateName !== null && certificateName !== undefined) {
      if (certificateName.length > 45)
      {
        throw new Error('"certificateName" should satisfy the constraint - "MaxLength": 45');
      }
      if (certificateName.length < 5)
      {
        throw new Error('"certificateName" should satisfy the constraint - "MinLength": 5');
      }
      if (certificateName.match(/^[\w]+-[\w]+$/) === null)
      {
        throw new Error('"certificateName" should satisfy the constraint - "Pattern": /^[\w]+-[\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.Batch/batchAccounts/{accountName}/certificates/{certificateName}/cancelDelete';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{accountName}', encodeURIComponent(accountName));
  requestUrl = requestUrl.replace('{certificateName}', encodeURIComponent(certificateName));
  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['Certificate']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }

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

/**
 * Creates a new certificate inside the specified account.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the Batch account.
 *
 * @param {string} accountName The name of the Batch account.
 *
 * @param {string} certificateName The identifier for the certificate. This
 * must be made up of algorithm and thumbprint separated by a dash, and must
 * match the certificate data in the request. For example SHA1-a3d1c5.
 *
 * @param {object} parameters Additional parameters for certificate creation.
 *
 * @param {string} [parameters.thumbprintAlgorithm] The algorithm of the
 * certificate thumbprint. This must match the first portion of the certificate
 * name. Currently required to be 'SHA1'.
 *
 * @param {string} [parameters.thumbprint] The thumbprint of the certificate.
 * This must match the thumbprint from the name.
 *
 * @param {string} [parameters.format] The format of the certificate - either
 * Pfx or Cer. If omitted, the default is Pfx. Possible values include: 'Pfx',
 * 'Cer'
 *
 * @param {string} parameters.data The base64-encoded contents of the
 * certificate. The maximum size is 10KB.
 *
 * @param {string} [parameters.password] The password to access the
 * certificate's private key. This must not be specified if the certificate
 * format is Cer.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.ifMatch] The entity state (ETag) version of the
 * certificate to update. A value of "*" can be used to apply the operation
 * only if the certificate already exists. If omitted, this operation will
 * always be applied.
 *
 * @param {string} [options.ifNoneMatch] Set to '*' to allow a new certificate
 * to be created, but to prevent updating an existing certificate. Other values
 * will be ignored.
 *
 * @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 Certificate} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _beginCreate(resourceGroupName, accountName, certificateName, 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.');
  }
  let ifMatch = (options && options.ifMatch !== undefined) ? options.ifMatch : undefined;
  let ifNoneMatch = (options && options.ifNoneMatch !== undefined) ? options.ifNoneMatch : 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 (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
      throw new Error('accountName cannot be null or undefined and it must be of type string.');
    }
    if (accountName !== null && accountName !== undefined) {
      if (accountName.length > 24)
      {
        throw new Error('"accountName" should satisfy the constraint - "MaxLength": 24');
      }
      if (accountName.length < 3)
      {
        throw new Error('"accountName" should satisfy the constraint - "MinLength": 3');
      }
      if (accountName.match(/^[a-zA-Z0-9]+$/) === null)
      {
        throw new Error('"accountName" should satisfy the constraint - "Pattern": /^[a-zA-Z0-9]+$/');
      }
    }
    if (certificateName === null || certificateName === undefined || typeof certificateName.valueOf() !== 'string') {
      throw new Error('certificateName cannot be null or undefined and it must be of type string.');
    }
    if (certificateName !== null && certificateName !== undefined) {
      if (certificateName.length > 45)
      {
        throw new Error('"certificateName" should satisfy the constraint - "MaxLength": 45');
      }
      if (certificateName.length < 5)
      {
        throw new Error('"certificateName" should satisfy the constraint - "MinLength": 5');
      }
      if (certificateName.match(/^[\w]+-[\w]+$/) === null)
      {
        throw new Error('"certificateName" should satisfy the constraint - "Pattern": /^[\w]+-[\w]+$/');
      }
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (ifMatch !== null && ifMatch !== undefined && typeof ifMatch.valueOf() !== 'string') {
      throw new Error('ifMatch must be of type string.');
    }
    if (ifNoneMatch !== null && ifNoneMatch !== undefined && typeof ifNoneMatch.valueOf() !== 'string') {
      throw new Error('ifNoneMatch must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

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

/**
 * Deletes the specified certificate.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the Batch account.
 *
 * @param {string} accountName The name of the Batch account.
 *
 * @param {string} certificateName The identifier for the certificate. This
 * must be made up of algorithm and thumbprint separated by a dash, and must
 * match the certificate data in the request. For example SHA1-a3d1c5.
 *
 * @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, accountName, certificateName, 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 (accountName === null || accountName === undefined || typeof accountName.valueOf() !== 'string') {
      throw new Error('accountName cannot be null or undefined and it must be of type string.');
    }
    if (accountName !== null && accountName !== undefined) {
      if (accountName.length > 24)
      {
        throw new Error('"accountName" should satisfy the constraint - "MaxLength": 24');
      }
      if (accountName.length < 3)
      {
        throw new Error('"accountName" should satisfy the constraint - "MinLength": 3');
      }
      if (accountName.match(/^[a-zA-Z0-9]+$/) === null)
      {
        throw new Error('"accountName" should satisfy the constraint - "Pattern": /^[a-zA-Z0-9]+$/');
      }
    }
    if (certificateName === null || certificateName === undefined || typeof certificateName.valueOf() !== 'string') {
      throw new Error('certificateName cannot be null or undefined and it must be of type string.');
    }
    if (certificateName !== null && certificateName !== undefined) {
      if (certificateName.length > 45)
      {
        throw new Error('"certificateName" should satisfy the constraint - "MaxLength": 45');
      }
      if (certificateName.length < 5)
      {
        throw new Error('"certificateName" should satisfy the constraint - "MinLength": 5');
      }
      if (certificateName.match(/^[\w]+-[\w]+$/) === null)
      {
        throw new Error('"certificateName" should satisfy the constraint - "Pattern": /^[\w]+-[\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.Batch/batchAccounts/{accountName}/certificates/{certificateName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{accountName}', encodeURIComponent(accountName));
  requestUrl = requestUrl.replace('{certificateName}', encodeURIComponent(certificateName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'DELETE';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200 && statusCode !== 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);
  });
}

/**
 * Lists all of the certificates in the specified account.
 *
 * @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 ListCertificatesResult} 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 _listByBatchAccountNext(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['ListCertificatesResult']().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 CertificateOperations. */
class CertificateOperations {
  /**
   * Create a CertificateOperations.
   * @param {BatchManagementClient} client Reference to the service client.
   */
  constructor(client) {
    this.client = client;
    this._listByBatchAccount = _listByBatchAccount;
    this._create = _create;
    this._update = _update;
    this._deleteMethod = _deleteMethod;
    this._get = _get;
    this._cancelDeletion = _cancelDeletion;
    this._beginCreate = _beginCreate;
    this._beginDeleteMethod = _beginDeleteMethod;
    this._listByBatchAccountNext = _listByBatchAccountNext;
  }

  /**
   * Lists all of the certificates in the specified account.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {number} [options.maxresults] The maximum number of items to return
   * in the response.
   *
   * @param {string} [options.select] Comma separated list of properties that
   * should be returned. e.g. "properties/provisioningState". Only top level
   * properties under properties/ are valid for selection.
   *
   * @param {string} [options.filter] OData filter expression. Valid properties
   * for filtering are "properties/provisioningState",
   * "properties/provisioningStateTransitionTime", "name".
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ListCertificatesResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByBatchAccountWithHttpOperationResponse(resourceGroupName, accountName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByBatchAccount(resourceGroupName, accountName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Lists all of the certificates in the specified account.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {number} [options.maxresults] The maximum number of items to return
   * in the response.
   *
   * @param {string} [options.select] Comma separated list of properties that
   * should be returned. e.g. "properties/provisioningState". Only top level
   * properties under properties/ are valid for selection.
   *
   * @param {string} [options.filter] OData filter expression. Valid properties
   * for filtering are "properties/provisioningState",
   * "properties/provisioningStateTransitionTime", "name".
   *
   * @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 {ListCertificatesResult} - 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 ListCertificatesResult} 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.
   */
  listByBatchAccount(resourceGroupName, accountName, 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._listByBatchAccount(resourceGroupName, accountName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByBatchAccount(resourceGroupName, accountName, options, optionalCallback);
    }
  }

  /**
   * Creates a new certificate inside the specified account.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @param {object} parameters Additional parameters for certificate creation.
   *
   * @param {string} [parameters.thumbprintAlgorithm] The algorithm of the
   * certificate thumbprint. This must match the first portion of the certificate
   * name. Currently required to be 'SHA1'.
   *
   * @param {string} [parameters.thumbprint] The thumbprint of the certificate.
   * This must match the thumbprint from the name.
   *
   * @param {string} [parameters.format] The format of the certificate - either
   * Pfx or Cer. If omitted, the default is Pfx. Possible values include: 'Pfx',
   * 'Cer'
   *
   * @param {string} parameters.data The base64-encoded contents of the
   * certificate. The maximum size is 10KB.
   *
   * @param {string} [parameters.password] The password to access the
   * certificate's private key. This must not be specified if the certificate
   * format is Cer.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.ifMatch] The entity state (ETag) version of the
   * certificate to update. A value of "*" can be used to apply the operation
   * only if the certificate already exists. If omitted, this operation will
   * always be applied.
   *
   * @param {string} [options.ifNoneMatch] Set to '*' to allow a new certificate
   * to be created, but to prevent updating an existing certificate. Other values
   * will be ignored.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<Certificate>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createWithHttpOperationResponse(resourceGroupName, accountName, certificateName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._create(resourceGroupName, accountName, certificateName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates a new certificate inside the specified account.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @param {object} parameters Additional parameters for certificate creation.
   *
   * @param {string} [parameters.thumbprintAlgorithm] The algorithm of the
   * certificate thumbprint. This must match the first portion of the certificate
   * name. Currently required to be 'SHA1'.
   *
   * @param {string} [parameters.thumbprint] The thumbprint of the certificate.
   * This must match the thumbprint from the name.
   *
   * @param {string} [parameters.format] The format of the certificate - either
   * Pfx or Cer. If omitted, the default is Pfx. Possible values include: 'Pfx',
   * 'Cer'
   *
   * @param {string} parameters.data The base64-encoded contents of the
   * certificate. The maximum size is 10KB.
   *
   * @param {string} [parameters.password] The password to access the
   * certificate's private key. This must not be specified if the certificate
   * format is Cer.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.ifMatch] The entity state (ETag) version of the
   * certificate to update. A value of "*" can be used to apply the operation
   * only if the certificate already exists. If omitted, this operation will
   * always be applied.
   *
   * @param {string} [options.ifNoneMatch] Set to '*' to allow a new certificate
   * to be created, but to prevent updating an existing certificate. Other values
   * will be ignored.
   *
   * @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 {Certificate} - 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 Certificate} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  create(resourceGroupName, accountName, certificateName, 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._create(resourceGroupName, accountName, certificateName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._create(resourceGroupName, accountName, certificateName, parameters, options, optionalCallback);
    }
  }

  /**
   * Updates the properties of an existing certificate.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @param {object} parameters Certificate entity to update.
   *
   * @param {string} [parameters.thumbprintAlgorithm] The algorithm of the
   * certificate thumbprint. This must match the first portion of the certificate
   * name. Currently required to be 'SHA1'.
   *
   * @param {string} [parameters.thumbprint] The thumbprint of the certificate.
   * This must match the thumbprint from the name.
   *
   * @param {string} [parameters.format] The format of the certificate - either
   * Pfx or Cer. If omitted, the default is Pfx. Possible values include: 'Pfx',
   * 'Cer'
   *
   * @param {string} parameters.data The base64-encoded contents of the
   * certificate. The maximum size is 10KB.
   *
   * @param {string} [parameters.password] The password to access the
   * certificate's private key. This must not be specified if the certificate
   * format is Cer.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.ifMatch] The entity state (ETag) version of the
   * certificate to update. This value can be omitted or set to "*" to apply the
   * operation unconditionally.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<Certificate>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  updateWithHttpOperationResponse(resourceGroupName, accountName, certificateName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._update(resourceGroupName, accountName, certificateName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Updates the properties of an existing certificate.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @param {object} parameters Certificate entity to update.
   *
   * @param {string} [parameters.thumbprintAlgorithm] The algorithm of the
   * certificate thumbprint. This must match the first portion of the certificate
   * name. Currently required to be 'SHA1'.
   *
   * @param {string} [parameters.thumbprint] The thumbprint of the certificate.
   * This must match the thumbprint from the name.
   *
   * @param {string} [parameters.format] The format of the certificate - either
   * Pfx or Cer. If omitted, the default is Pfx. Possible values include: 'Pfx',
   * 'Cer'
   *
   * @param {string} parameters.data The base64-encoded contents of the
   * certificate. The maximum size is 10KB.
   *
   * @param {string} [parameters.password] The password to access the
   * certificate's private key. This must not be specified if the certificate
   * format is Cer.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.ifMatch] The entity state (ETag) version of the
   * certificate to update. This value can be omitted or set to "*" to apply the
   * operation unconditionally.
   *
   * @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 {Certificate} - 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 Certificate} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  update(resourceGroupName, accountName, certificateName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._update(resourceGroupName, accountName, certificateName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._update(resourceGroupName, accountName, certificateName, parameters, options, optionalCallback);
    }
  }

  /**
   * Deletes the specified certificate.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @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, accountName, certificateName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._deleteMethod(resourceGroupName, accountName, certificateName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Deletes the specified certificate.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @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, accountName, certificateName, 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, accountName, certificateName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._deleteMethod(resourceGroupName, accountName, certificateName, options, optionalCallback);
    }
  }

  /**
   * Gets information about the specified certificate.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @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<Certificate>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getWithHttpOperationResponse(resourceGroupName, accountName, certificateName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._get(resourceGroupName, accountName, certificateName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets information about the specified certificate.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @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 {Certificate} - 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 Certificate} 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, accountName, certificateName, 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, accountName, certificateName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._get(resourceGroupName, accountName, certificateName, options, optionalCallback);
    }
  }

  /**
   * @summary Cancels a failed deletion of a certificate from the specified
   * account.
   *
   * If you try to delete a certificate that is being used by a pool or compute
   * node, the status of the certificate changes to deleteFailed. If you decide
   * that you want to continue using the certificate, you can use this operation
   * to set the status of the certificate back to active. If you intend to delete
   * the certificate, you do not need to run this operation after the deletion
   * failed. You must make sure that the certificate is not being used by any
   * resources, and then you can try again to delete the certificate.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @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<Certificate>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  cancelDeletionWithHttpOperationResponse(resourceGroupName, accountName, certificateName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._cancelDeletion(resourceGroupName, accountName, certificateName, 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 failed deletion of a certificate from the specified
   * account.
   *
   * If you try to delete a certificate that is being used by a pool or compute
   * node, the status of the certificate changes to deleteFailed. If you decide
   * that you want to continue using the certificate, you can use this operation
   * to set the status of the certificate back to active. If you intend to delete
   * the certificate, you do not need to run this operation after the deletion
   * failed. You must make sure that the certificate is not being used by any
   * resources, and then you can try again to delete the certificate.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @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 {Certificate} - 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 Certificate} 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.
   */
  cancelDeletion(resourceGroupName, accountName, certificateName, 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._cancelDeletion(resourceGroupName, accountName, certificateName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._cancelDeletion(resourceGroupName, accountName, certificateName, options, optionalCallback);
    }
  }

  /**
   * Creates a new certificate inside the specified account.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @param {object} parameters Additional parameters for certificate creation.
   *
   * @param {string} [parameters.thumbprintAlgorithm] The algorithm of the
   * certificate thumbprint. This must match the first portion of the certificate
   * name. Currently required to be 'SHA1'.
   *
   * @param {string} [parameters.thumbprint] The thumbprint of the certificate.
   * This must match the thumbprint from the name.
   *
   * @param {string} [parameters.format] The format of the certificate - either
   * Pfx or Cer. If omitted, the default is Pfx. Possible values include: 'Pfx',
   * 'Cer'
   *
   * @param {string} parameters.data The base64-encoded contents of the
   * certificate. The maximum size is 10KB.
   *
   * @param {string} [parameters.password] The password to access the
   * certificate's private key. This must not be specified if the certificate
   * format is Cer.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.ifMatch] The entity state (ETag) version of the
   * certificate to update. A value of "*" can be used to apply the operation
   * only if the certificate already exists. If omitted, this operation will
   * always be applied.
   *
   * @param {string} [options.ifNoneMatch] Set to '*' to allow a new certificate
   * to be created, but to prevent updating an existing certificate. Other values
   * will be ignored.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<Certificate>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginCreateWithHttpOperationResponse(resourceGroupName, accountName, certificateName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginCreate(resourceGroupName, accountName, certificateName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates a new certificate inside the specified account.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @param {object} parameters Additional parameters for certificate creation.
   *
   * @param {string} [parameters.thumbprintAlgorithm] The algorithm of the
   * certificate thumbprint. This must match the first portion of the certificate
   * name. Currently required to be 'SHA1'.
   *
   * @param {string} [parameters.thumbprint] The thumbprint of the certificate.
   * This must match the thumbprint from the name.
   *
   * @param {string} [parameters.format] The format of the certificate - either
   * Pfx or Cer. If omitted, the default is Pfx. Possible values include: 'Pfx',
   * 'Cer'
   *
   * @param {string} parameters.data The base64-encoded contents of the
   * certificate. The maximum size is 10KB.
   *
   * @param {string} [parameters.password] The password to access the
   * certificate's private key. This must not be specified if the certificate
   * format is Cer.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.ifMatch] The entity state (ETag) version of the
   * certificate to update. A value of "*" can be used to apply the operation
   * only if the certificate already exists. If omitted, this operation will
   * always be applied.
   *
   * @param {string} [options.ifNoneMatch] Set to '*' to allow a new certificate
   * to be created, but to prevent updating an existing certificate. Other values
   * will be ignored.
   *
   * @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 {Certificate} - 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 Certificate} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  beginCreate(resourceGroupName, accountName, certificateName, 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._beginCreate(resourceGroupName, accountName, certificateName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginCreate(resourceGroupName, accountName, certificateName, parameters, options, optionalCallback);
    }
  }

  /**
   * Deletes the specified certificate.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @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, accountName, certificateName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginDeleteMethod(resourceGroupName, accountName, certificateName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Deletes the specified certificate.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the Batch account.
   *
   * @param {string} accountName The name of the Batch account.
   *
   * @param {string} certificateName The identifier for the certificate. This
   * must be made up of algorithm and thumbprint separated by a dash, and must
   * match the certificate data in the request. For example SHA1-a3d1c5.
   *
   * @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, accountName, certificateName, 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, accountName, certificateName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginDeleteMethod(resourceGroupName, accountName, certificateName, options, optionalCallback);
    }
  }

  /**
   * Lists all of the certificates in the specified account.
   *
   * @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<ListCertificatesResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByBatchAccountNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByBatchAccountNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Lists all of the certificates in the specified account.
   *
   * @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 {ListCertificatesResult} - 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 ListCertificatesResult} 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.
   */
  listByBatchAccountNext(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._listByBatchAccountNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByBatchAccountNext(nextPageLink, options, optionalCallback);
    }
  }

}

module.exports = CertificateOperations;
