/*
 * 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 WebResource = msRest.WebResource;

/**
 * Report Deployment status metric
 *
 * @param {object} releaseMetadata Deployment status metric properties
 *
 * @param {string} releaseMetadata.deploymentKey
 *
 * @param {string} [releaseMetadata.label]
 *
 * @param {string} [releaseMetadata.appVersion]
 *
 * @param {string} [releaseMetadata.previousDeploymentKey]
 *
 * @param {string} [releaseMetadata.previousLabelOrAppVersion]
 *
 * @param {string} [releaseMetadata.status]
 *
 * @param {string} [releaseMetadata.clientUniqueId]
 *
 * @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 _updateDeployStatus(releaseMetadata, 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 (releaseMetadata === null || releaseMetadata === undefined) {
      throw new Error('releaseMetadata cannot be null or undefined.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/deployments/releases/report_status/deploy';

  // 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(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 (releaseMetadata !== null && releaseMetadata !== undefined) {
      let requestModelMapper = new client.models['CodePushStatusMetricMetadata']().mapper();
      requestModel = client.serialize(requestModelMapper, releaseMetadata, 'releaseMetadata');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(releaseMetadata, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
      } 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);
  });
}

/**
 * Report download of specified release
 *
 * @param {object} releaseMetadata Deployment status metric properties
 *
 * @param {string} releaseMetadata.deploymentKey
 *
 * @param {string} [releaseMetadata.label]
 *
 * @param {string} [releaseMetadata.appVersion]
 *
 * @param {string} [releaseMetadata.previousDeploymentKey]
 *
 * @param {string} [releaseMetadata.previousLabelOrAppVersion]
 *
 * @param {string} [releaseMetadata.status]
 *
 * @param {string} [releaseMetadata.clientUniqueId]
 *
 * @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 _updateDownloadStatus(releaseMetadata, 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 (releaseMetadata === null || releaseMetadata === undefined) {
      throw new Error('releaseMetadata cannot be null or undefined.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/deployments/releases/report_status/download';

  // 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(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 (releaseMetadata !== null && releaseMetadata !== undefined) {
      let requestModelMapper = new client.models['CodePushStatusMetricMetadata']().mapper();
      requestModel = client.serialize(requestModelMapper, releaseMetadata, 'releaseMetadata');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(releaseMetadata, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
      } 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);
  });
}

/**
 * Check for updates
 *
 * @param {string} appVersion
 *
 * @param {string} deploymentKey
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.clientUniqueId]
 *
 * @param {boolean} [options.isCompanion]
 *
 * @param {string} [options.label]
 *
 * @param {string} [options.packageHash]
 *
 * @param {string} [options.previousDeploymentKey]
 *
 * @param {string} [options.previousLabelOrAppVersion]
 *
 * @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 UpdateCheckResponse} 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 _updateCheck(appVersion, deploymentKey, 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 clientUniqueId = (options && options.clientUniqueId !== undefined) ? options.clientUniqueId : undefined;
  let isCompanion = (options && options.isCompanion !== undefined) ? options.isCompanion : undefined;
  let label = (options && options.label !== undefined) ? options.label : undefined;
  let packageHash = (options && options.packageHash !== undefined) ? options.packageHash : undefined;
  let previousDeploymentKey = (options && options.previousDeploymentKey !== undefined) ? options.previousDeploymentKey : undefined;
  let previousLabelOrAppVersion = (options && options.previousLabelOrAppVersion !== undefined) ? options.previousLabelOrAppVersion : undefined;
  // Validate
  try {
    if (appVersion === null || appVersion === undefined || typeof appVersion.valueOf() !== 'string') {
      throw new Error('appVersion cannot be null or undefined and it must be of type string.');
    }
    if (clientUniqueId !== null && clientUniqueId !== undefined && typeof clientUniqueId.valueOf() !== 'string') {
      throw new Error('clientUniqueId must be of type string.');
    }
    if (deploymentKey === null || deploymentKey === undefined || typeof deploymentKey.valueOf() !== 'string') {
      throw new Error('deploymentKey cannot be null or undefined and it must be of type string.');
    }
    if (isCompanion !== null && isCompanion !== undefined && typeof isCompanion !== 'boolean') {
      throw new Error('isCompanion must be of type boolean.');
    }
    if (label !== null && label !== undefined && typeof label.valueOf() !== 'string') {
      throw new Error('label must be of type string.');
    }
    if (packageHash !== null && packageHash !== undefined && typeof packageHash.valueOf() !== 'string') {
      throw new Error('packageHash must be of type string.');
    }
    if (previousDeploymentKey !== null && previousDeploymentKey !== undefined && typeof previousDeploymentKey.valueOf() !== 'string') {
      throw new Error('previousDeploymentKey must be of type string.');
    }
    if (previousLabelOrAppVersion !== null && previousLabelOrAppVersion !== undefined && typeof previousLabelOrAppVersion.valueOf() !== 'string') {
      throw new Error('previousLabelOrAppVersion must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'v0.1/apps/deployments/releases/updateCheck';
  let queryParameters = [];
  queryParameters.push('app_version=' + encodeURIComponent(appVersion));
  if (clientUniqueId !== null && clientUniqueId !== undefined) {
    queryParameters.push('client_unique_id=' + encodeURIComponent(clientUniqueId));
  }
  queryParameters.push('deployment_key=' + encodeURIComponent(deploymentKey));
  if (isCompanion !== null && isCompanion !== undefined) {
    queryParameters.push('is_companion=' + encodeURIComponent(isCompanion.toString()));
  }
  if (label !== null && label !== undefined) {
    queryParameters.push('label=' + encodeURIComponent(label));
  }
  if (packageHash !== null && packageHash !== undefined) {
    queryParameters.push('package_hash=' + encodeURIComponent(packageHash));
  }
  if (previousDeploymentKey !== null && previousDeploymentKey !== undefined) {
    queryParameters.push('previous_deployment_key=' + encodeURIComponent(previousDeploymentKey));
  }
  if (previousLabelOrAppVersion !== null && previousLabelOrAppVersion !== undefined) {
    queryParameters.push('previous_label_or_app_version=' + encodeURIComponent(previousLabelOrAppVersion));
  }
  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(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
      } 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['UpdateCheckResponse']().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 CodePushAcquisition. */
class CodePushAcquisition {
  /**
   * Create a CodePushAcquisition.
   * @param {CodepushClient} client Reference to the service client.
   */
  constructor(client) {
    this.client = client;
    this._updateDeployStatus = _updateDeployStatus;
    this._updateDownloadStatus = _updateDownloadStatus;
    this._updateCheck = _updateCheck;
  }

  /**
   * Report Deployment status metric
   *
   * @param {object} releaseMetadata Deployment status metric properties
   *
   * @param {string} releaseMetadata.deploymentKey
   *
   * @param {string} [releaseMetadata.label]
   *
   * @param {string} [releaseMetadata.appVersion]
   *
   * @param {string} [releaseMetadata.previousDeploymentKey]
   *
   * @param {string} [releaseMetadata.previousLabelOrAppVersion]
   *
   * @param {string} [releaseMetadata.status]
   *
   * @param {string} [releaseMetadata.clientUniqueId]
   *
   * @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.
   */
  updateDeployStatusWithHttpOperationResponse(releaseMetadata, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._updateDeployStatus(releaseMetadata, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Report Deployment status metric
   *
   * @param {object} releaseMetadata Deployment status metric properties
   *
   * @param {string} releaseMetadata.deploymentKey
   *
   * @param {string} [releaseMetadata.label]
   *
   * @param {string} [releaseMetadata.appVersion]
   *
   * @param {string} [releaseMetadata.previousDeploymentKey]
   *
   * @param {string} [releaseMetadata.previousLabelOrAppVersion]
   *
   * @param {string} [releaseMetadata.status]
   *
   * @param {string} [releaseMetadata.clientUniqueId]
   *
   * @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.
   */
  updateDeployStatus(releaseMetadata, 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._updateDeployStatus(releaseMetadata, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._updateDeployStatus(releaseMetadata, options, optionalCallback);
    }
  }

  /**
   * Report download of specified release
   *
   * @param {object} releaseMetadata Deployment status metric properties
   *
   * @param {string} releaseMetadata.deploymentKey
   *
   * @param {string} [releaseMetadata.label]
   *
   * @param {string} [releaseMetadata.appVersion]
   *
   * @param {string} [releaseMetadata.previousDeploymentKey]
   *
   * @param {string} [releaseMetadata.previousLabelOrAppVersion]
   *
   * @param {string} [releaseMetadata.status]
   *
   * @param {string} [releaseMetadata.clientUniqueId]
   *
   * @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.
   */
  updateDownloadStatusWithHttpOperationResponse(releaseMetadata, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._updateDownloadStatus(releaseMetadata, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Report download of specified release
   *
   * @param {object} releaseMetadata Deployment status metric properties
   *
   * @param {string} releaseMetadata.deploymentKey
   *
   * @param {string} [releaseMetadata.label]
   *
   * @param {string} [releaseMetadata.appVersion]
   *
   * @param {string} [releaseMetadata.previousDeploymentKey]
   *
   * @param {string} [releaseMetadata.previousLabelOrAppVersion]
   *
   * @param {string} [releaseMetadata.status]
   *
   * @param {string} [releaseMetadata.clientUniqueId]
   *
   * @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.
   */
  updateDownloadStatus(releaseMetadata, 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._updateDownloadStatus(releaseMetadata, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._updateDownloadStatus(releaseMetadata, options, optionalCallback);
    }
  }

  /**
   * Check for updates
   *
   * @param {string} appVersion
   *
   * @param {string} deploymentKey
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.clientUniqueId]
   *
   * @param {boolean} [options.isCompanion]
   *
   * @param {string} [options.label]
   *
   * @param {string} [options.packageHash]
   *
   * @param {string} [options.previousDeploymentKey]
   *
   * @param {string} [options.previousLabelOrAppVersion]
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<UpdateCheckResponse>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  updateCheckWithHttpOperationResponse(appVersion, deploymentKey, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._updateCheck(appVersion, deploymentKey, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Check for updates
   *
   * @param {string} appVersion
   *
   * @param {string} deploymentKey
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.clientUniqueId]
   *
   * @param {boolean} [options.isCompanion]
   *
   * @param {string} [options.label]
   *
   * @param {string} [options.packageHash]
   *
   * @param {string} [options.previousDeploymentKey]
   *
   * @param {string} [options.previousLabelOrAppVersion]
   *
   * @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 {UpdateCheckResponse} - 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 UpdateCheckResponse} 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.
   */
  updateCheck(appVersion, deploymentKey, 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._updateCheck(appVersion, deploymentKey, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._updateCheck(appVersion, deploymentKey, options, optionalCallback);
    }
  }

}

module.exports = CodePushAcquisition;
