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

/* jshint latedef:false */
/* jshint forin:false */
/* jshint noempty:false */

'use strict';

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

const models = require('./models');


/**
 * @summary Classify an image url and saves the result.
 *
 * @param {uuid} projectId The project id.
 *
 * @param {string} publishedName Specifies the name of the model to evaluate
 * against.
 *
 * @param {object} imageUrl An ImageUrl that contains the url of the image to
 * be evaluated.
 *
 * @param {string} imageUrl.url Url of the image.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.application] Optional. Specifies the name of
 * application using the endpoint.
 *
 * @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 ImagePrediction} 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 _classifyImageUrl(projectId, publishedName, imageUrl, options, callback) {
   /* jshint validthis: true */
  let client = this;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let application = (options && options.application !== undefined) ? options.application : undefined;
  // Validate
  try {
    if (this.endpoint === null || this.endpoint === undefined || typeof this.endpoint.valueOf() !== 'string') {
      throw new Error('this.endpoint cannot be null or undefined and it must be of type string.');
    }
    if (projectId === null || projectId === undefined || typeof projectId.valueOf() !== 'string' || !msRest.isValidUuid(projectId)) {
      throw new Error('projectId cannot be null or undefined and it must be of type string and must be a valid uuid.');
    }
    if (publishedName === null || publishedName === undefined || typeof publishedName.valueOf() !== 'string') {
      throw new Error('publishedName cannot be null or undefined and it must be of type string.');
    }
    if (imageUrl === null || imageUrl === undefined) {
      throw new Error('imageUrl cannot be null or undefined.');
    }
    if (application !== null && application !== undefined && typeof application.valueOf() !== 'string') {
      throw new Error('application must be of type string.');
    }
    if (this.apiKey === null || this.apiKey === undefined || typeof this.apiKey.valueOf() !== 'string') {
      throw new Error('this.apiKey cannot be null or undefined and it must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{projectId}/classify/iterations/{publishedName}/url';
  requestUrl = requestUrl.replace('{Endpoint}', this.endpoint);
  requestUrl = requestUrl.replace('{projectId}', encodeURIComponent(projectId.toString()));
  requestUrl = requestUrl.replace('{publishedName}', encodeURIComponent(publishedName));
  let queryParameters = [];
  if (application !== null && application !== undefined) {
    queryParameters.push('application=' + encodeURIComponent(application));
  }
  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.apiKey !== undefined && this.apiKey !== null) {
    httpRequest.headers['Prediction-Key'] = this.apiKey;
  }
  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 (imageUrl !== null && imageUrl !== undefined) {
      let requestModelMapper = new client.models['ImageUrl']().mapper();
      requestModel = client.serialize(requestModelMapper, imageUrl, 'imageUrl');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(imageUrl, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CustomVisionError']().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['ImagePrediction']().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 Classify an image and saves the result.
 *
 * @param {uuid} projectId The project id.
 *
 * @param {string} publishedName Specifies the name of the model to evaluate
 * against.
 *
 * @param {object} imageData Binary image data. Supported formats are JPEG,
 * GIF, PNG, and BMP. Supports images up to 4MB.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.application] Optional. Specifies the name of
 * application using the endpoint.
 *
 * @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 ImagePrediction} 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 _classifyImage(projectId, publishedName, imageData, options, callback) {
   /* jshint validthis: true */
  let client = this;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let application = (options && options.application !== undefined) ? options.application : undefined;
  // Validate
  try {
    if (this.endpoint === null || this.endpoint === undefined || typeof this.endpoint.valueOf() !== 'string') {
      throw new Error('this.endpoint cannot be null or undefined and it must be of type string.');
    }
    if (projectId === null || projectId === undefined || typeof projectId.valueOf() !== 'string' || !msRest.isValidUuid(projectId)) {
      throw new Error('projectId cannot be null or undefined and it must be of type string and must be a valid uuid.');
    }
    if (publishedName === null || publishedName === undefined || typeof publishedName.valueOf() !== 'string') {
      throw new Error('publishedName cannot be null or undefined and it must be of type string.');
    }
    if (application !== null && application !== undefined && typeof application.valueOf() !== 'string') {
      throw new Error('application must be of type string.');
    }
    if (imageData === null || imageData === undefined) {
      throw new Error('imageData cannot be null or undefined and it must be of type object.');
    }
    if (this.apiKey === null || this.apiKey === undefined || typeof this.apiKey.valueOf() !== 'string') {
      throw new Error('this.apiKey cannot be null or undefined and it must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{projectId}/classify/iterations/{publishedName}/image';
  requestUrl = requestUrl.replace('{Endpoint}', this.endpoint);
  requestUrl = requestUrl.replace('{projectId}', encodeURIComponent(projectId.toString()));
  requestUrl = requestUrl.replace('{publishedName}', encodeURIComponent(publishedName));
  let queryParameters = [];
  if (application !== null && application !== undefined) {
    queryParameters.push('application=' + encodeURIComponent(application));
  }
  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'] = 'multipart/form-data';
  if (this.apiKey !== undefined && this.apiKey !== null) {
    httpRequest.headers['Prediction-Key'] = this.apiKey;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  // Serialize Request
  let formData = {};
  if (imageData !== undefined && imageData !== null) {
    formData['imageData'] = imageData;
  }
  httpRequest.formData = formData;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CustomVisionError']().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['ImagePrediction']().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 Classify an image url without saving the result.
 *
 * @param {uuid} projectId The project id.
 *
 * @param {string} publishedName Specifies the name of the model to evaluate
 * against.
 *
 * @param {object} imageUrl An {Iris.Web.Api.Models.ImageUrl} that contains the
 * url of the image to be evaluated.
 *
 * @param {string} imageUrl.url Url of the image.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.application] Optional. Specifies the name of
 * application using the endpoint.
 *
 * @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 ImagePrediction} 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 _classifyImageUrlWithNoStore(projectId, publishedName, imageUrl, options, callback) {
   /* jshint validthis: true */
  let client = this;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let application = (options && options.application !== undefined) ? options.application : undefined;
  // Validate
  try {
    if (this.endpoint === null || this.endpoint === undefined || typeof this.endpoint.valueOf() !== 'string') {
      throw new Error('this.endpoint cannot be null or undefined and it must be of type string.');
    }
    if (projectId === null || projectId === undefined || typeof projectId.valueOf() !== 'string' || !msRest.isValidUuid(projectId)) {
      throw new Error('projectId cannot be null or undefined and it must be of type string and must be a valid uuid.');
    }
    if (publishedName === null || publishedName === undefined || typeof publishedName.valueOf() !== 'string') {
      throw new Error('publishedName cannot be null or undefined and it must be of type string.');
    }
    if (imageUrl === null || imageUrl === undefined) {
      throw new Error('imageUrl cannot be null or undefined.');
    }
    if (application !== null && application !== undefined && typeof application.valueOf() !== 'string') {
      throw new Error('application must be of type string.');
    }
    if (this.apiKey === null || this.apiKey === undefined || typeof this.apiKey.valueOf() !== 'string') {
      throw new Error('this.apiKey cannot be null or undefined and it must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{projectId}/classify/iterations/{publishedName}/url/nostore';
  requestUrl = requestUrl.replace('{Endpoint}', this.endpoint);
  requestUrl = requestUrl.replace('{projectId}', encodeURIComponent(projectId.toString()));
  requestUrl = requestUrl.replace('{publishedName}', encodeURIComponent(publishedName));
  let queryParameters = [];
  if (application !== null && application !== undefined) {
    queryParameters.push('application=' + encodeURIComponent(application));
  }
  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.apiKey !== undefined && this.apiKey !== null) {
    httpRequest.headers['Prediction-Key'] = this.apiKey;
  }
  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 (imageUrl !== null && imageUrl !== undefined) {
      let requestModelMapper = new client.models['ImageUrl']().mapper();
      requestModel = client.serialize(requestModelMapper, imageUrl, 'imageUrl');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(imageUrl, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CustomVisionError']().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['ImagePrediction']().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 Classify an image without saving the result.
 *
 * @param {uuid} projectId The project id.
 *
 * @param {string} publishedName Specifies the name of the model to evaluate
 * against.
 *
 * @param {object} imageData Binary image data. Supported formats are JPEG,
 * GIF, PNG, and BMP. Supports images up to 0MB.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.application] Optional. Specifies the name of
 * application using the endpoint.
 *
 * @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 ImagePrediction} 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 _classifyImageWithNoStore(projectId, publishedName, imageData, options, callback) {
   /* jshint validthis: true */
  let client = this;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let application = (options && options.application !== undefined) ? options.application : undefined;
  // Validate
  try {
    if (this.endpoint === null || this.endpoint === undefined || typeof this.endpoint.valueOf() !== 'string') {
      throw new Error('this.endpoint cannot be null or undefined and it must be of type string.');
    }
    if (projectId === null || projectId === undefined || typeof projectId.valueOf() !== 'string' || !msRest.isValidUuid(projectId)) {
      throw new Error('projectId cannot be null or undefined and it must be of type string and must be a valid uuid.');
    }
    if (publishedName === null || publishedName === undefined || typeof publishedName.valueOf() !== 'string') {
      throw new Error('publishedName cannot be null or undefined and it must be of type string.');
    }
    if (application !== null && application !== undefined && typeof application.valueOf() !== 'string') {
      throw new Error('application must be of type string.');
    }
    if (imageData === null || imageData === undefined) {
      throw new Error('imageData cannot be null or undefined and it must be of type object.');
    }
    if (this.apiKey === null || this.apiKey === undefined || typeof this.apiKey.valueOf() !== 'string') {
      throw new Error('this.apiKey cannot be null or undefined and it must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{projectId}/classify/iterations/{publishedName}/image/nostore';
  requestUrl = requestUrl.replace('{Endpoint}', this.endpoint);
  requestUrl = requestUrl.replace('{projectId}', encodeURIComponent(projectId.toString()));
  requestUrl = requestUrl.replace('{publishedName}', encodeURIComponent(publishedName));
  let queryParameters = [];
  if (application !== null && application !== undefined) {
    queryParameters.push('application=' + encodeURIComponent(application));
  }
  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'] = 'multipart/form-data';
  if (this.apiKey !== undefined && this.apiKey !== null) {
    httpRequest.headers['Prediction-Key'] = this.apiKey;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  // Serialize Request
  let formData = {};
  if (imageData !== undefined && imageData !== null) {
    formData['imageData'] = imageData;
  }
  httpRequest.formData = formData;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CustomVisionError']().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['ImagePrediction']().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 Detect objects in an image url and saves the result.
 *
 * @param {uuid} projectId The project id.
 *
 * @param {string} publishedName Specifies the name of the model to evaluate
 * against.
 *
 * @param {object} imageUrl An ImageUrl that contains the url of the image to
 * be evaluated.
 *
 * @param {string} imageUrl.url Url of the image.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.application] Optional. Specifies the name of
 * application using the endpoint.
 *
 * @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 ImagePrediction} 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 _detectImageUrl(projectId, publishedName, imageUrl, options, callback) {
   /* jshint validthis: true */
  let client = this;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let application = (options && options.application !== undefined) ? options.application : undefined;
  // Validate
  try {
    if (this.endpoint === null || this.endpoint === undefined || typeof this.endpoint.valueOf() !== 'string') {
      throw new Error('this.endpoint cannot be null or undefined and it must be of type string.');
    }
    if (projectId === null || projectId === undefined || typeof projectId.valueOf() !== 'string' || !msRest.isValidUuid(projectId)) {
      throw new Error('projectId cannot be null or undefined and it must be of type string and must be a valid uuid.');
    }
    if (publishedName === null || publishedName === undefined || typeof publishedName.valueOf() !== 'string') {
      throw new Error('publishedName cannot be null or undefined and it must be of type string.');
    }
    if (imageUrl === null || imageUrl === undefined) {
      throw new Error('imageUrl cannot be null or undefined.');
    }
    if (application !== null && application !== undefined && typeof application.valueOf() !== 'string') {
      throw new Error('application must be of type string.');
    }
    if (this.apiKey === null || this.apiKey === undefined || typeof this.apiKey.valueOf() !== 'string') {
      throw new Error('this.apiKey cannot be null or undefined and it must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{projectId}/detect/iterations/{publishedName}/url';
  requestUrl = requestUrl.replace('{Endpoint}', this.endpoint);
  requestUrl = requestUrl.replace('{projectId}', encodeURIComponent(projectId.toString()));
  requestUrl = requestUrl.replace('{publishedName}', encodeURIComponent(publishedName));
  let queryParameters = [];
  if (application !== null && application !== undefined) {
    queryParameters.push('application=' + encodeURIComponent(application));
  }
  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.apiKey !== undefined && this.apiKey !== null) {
    httpRequest.headers['Prediction-Key'] = this.apiKey;
  }
  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 (imageUrl !== null && imageUrl !== undefined) {
      let requestModelMapper = new client.models['ImageUrl']().mapper();
      requestModel = client.serialize(requestModelMapper, imageUrl, 'imageUrl');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(imageUrl, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CustomVisionError']().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['ImagePrediction']().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 Detect objects in an image and saves the result.
 *
 * @param {uuid} projectId The project id.
 *
 * @param {string} publishedName Specifies the name of the model to evaluate
 * against.
 *
 * @param {object} imageData Binary image data. Supported formats are JPEG,
 * GIF, PNG, and BMP. Supports images up to 4MB.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.application] Optional. Specifies the name of
 * application using the endpoint.
 *
 * @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 ImagePrediction} 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 _detectImage(projectId, publishedName, imageData, options, callback) {
   /* jshint validthis: true */
  let client = this;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let application = (options && options.application !== undefined) ? options.application : undefined;
  // Validate
  try {
    if (this.endpoint === null || this.endpoint === undefined || typeof this.endpoint.valueOf() !== 'string') {
      throw new Error('this.endpoint cannot be null or undefined and it must be of type string.');
    }
    if (projectId === null || projectId === undefined || typeof projectId.valueOf() !== 'string' || !msRest.isValidUuid(projectId)) {
      throw new Error('projectId cannot be null or undefined and it must be of type string and must be a valid uuid.');
    }
    if (publishedName === null || publishedName === undefined || typeof publishedName.valueOf() !== 'string') {
      throw new Error('publishedName cannot be null or undefined and it must be of type string.');
    }
    if (application !== null && application !== undefined && typeof application.valueOf() !== 'string') {
      throw new Error('application must be of type string.');
    }
    if (imageData === null || imageData === undefined) {
      throw new Error('imageData cannot be null or undefined and it must be of type object.');
    }
    if (this.apiKey === null || this.apiKey === undefined || typeof this.apiKey.valueOf() !== 'string') {
      throw new Error('this.apiKey cannot be null or undefined and it must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{projectId}/detect/iterations/{publishedName}/image';
  requestUrl = requestUrl.replace('{Endpoint}', this.endpoint);
  requestUrl = requestUrl.replace('{projectId}', encodeURIComponent(projectId.toString()));
  requestUrl = requestUrl.replace('{publishedName}', encodeURIComponent(publishedName));
  let queryParameters = [];
  if (application !== null && application !== undefined) {
    queryParameters.push('application=' + encodeURIComponent(application));
  }
  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'] = 'multipart/form-data';
  if (this.apiKey !== undefined && this.apiKey !== null) {
    httpRequest.headers['Prediction-Key'] = this.apiKey;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  // Serialize Request
  let formData = {};
  if (imageData !== undefined && imageData !== null) {
    formData['imageData'] = imageData;
  }
  httpRequest.formData = formData;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CustomVisionError']().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['ImagePrediction']().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 Detect objects in an image url without saving the result.
 *
 * @param {uuid} projectId The project id.
 *
 * @param {string} publishedName Specifies the name of the model to evaluate
 * against.
 *
 * @param {object} imageUrl An {Iris.Web.Api.Models.ImageUrl} that contains the
 * url of the image to be evaluated.
 *
 * @param {string} imageUrl.url Url of the image.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.application] Optional. Specifies the name of
 * application using the endpoint.
 *
 * @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 ImagePrediction} 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 _detectImageUrlWithNoStore(projectId, publishedName, imageUrl, options, callback) {
   /* jshint validthis: true */
  let client = this;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let application = (options && options.application !== undefined) ? options.application : undefined;
  // Validate
  try {
    if (this.endpoint === null || this.endpoint === undefined || typeof this.endpoint.valueOf() !== 'string') {
      throw new Error('this.endpoint cannot be null or undefined and it must be of type string.');
    }
    if (projectId === null || projectId === undefined || typeof projectId.valueOf() !== 'string' || !msRest.isValidUuid(projectId)) {
      throw new Error('projectId cannot be null or undefined and it must be of type string and must be a valid uuid.');
    }
    if (publishedName === null || publishedName === undefined || typeof publishedName.valueOf() !== 'string') {
      throw new Error('publishedName cannot be null or undefined and it must be of type string.');
    }
    if (imageUrl === null || imageUrl === undefined) {
      throw new Error('imageUrl cannot be null or undefined.');
    }
    if (application !== null && application !== undefined && typeof application.valueOf() !== 'string') {
      throw new Error('application must be of type string.');
    }
    if (this.apiKey === null || this.apiKey === undefined || typeof this.apiKey.valueOf() !== 'string') {
      throw new Error('this.apiKey cannot be null or undefined and it must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{projectId}/detect/iterations/{publishedName}/url/nostore';
  requestUrl = requestUrl.replace('{Endpoint}', this.endpoint);
  requestUrl = requestUrl.replace('{projectId}', encodeURIComponent(projectId.toString()));
  requestUrl = requestUrl.replace('{publishedName}', encodeURIComponent(publishedName));
  let queryParameters = [];
  if (application !== null && application !== undefined) {
    queryParameters.push('application=' + encodeURIComponent(application));
  }
  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.apiKey !== undefined && this.apiKey !== null) {
    httpRequest.headers['Prediction-Key'] = this.apiKey;
  }
  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 (imageUrl !== null && imageUrl !== undefined) {
      let requestModelMapper = new client.models['ImageUrl']().mapper();
      requestModel = client.serialize(requestModelMapper, imageUrl, 'imageUrl');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(imageUrl, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CustomVisionError']().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['ImagePrediction']().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 Detect objects in an image without saving the result.
 *
 * @param {uuid} projectId The project id.
 *
 * @param {string} publishedName Specifies the name of the model to evaluate
 * against.
 *
 * @param {object} imageData Binary image data. Supported formats are JPEG,
 * GIF, PNG, and BMP. Supports images up to 0MB.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.application] Optional. Specifies the name of
 * application using the endpoint.
 *
 * @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 ImagePrediction} 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 _detectImageWithNoStore(projectId, publishedName, imageData, options, callback) {
   /* jshint validthis: true */
  let client = this;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  let application = (options && options.application !== undefined) ? options.application : undefined;
  // Validate
  try {
    if (this.endpoint === null || this.endpoint === undefined || typeof this.endpoint.valueOf() !== 'string') {
      throw new Error('this.endpoint cannot be null or undefined and it must be of type string.');
    }
    if (projectId === null || projectId === undefined || typeof projectId.valueOf() !== 'string' || !msRest.isValidUuid(projectId)) {
      throw new Error('projectId cannot be null or undefined and it must be of type string and must be a valid uuid.');
    }
    if (publishedName === null || publishedName === undefined || typeof publishedName.valueOf() !== 'string') {
      throw new Error('publishedName cannot be null or undefined and it must be of type string.');
    }
    if (application !== null && application !== undefined && typeof application.valueOf() !== 'string') {
      throw new Error('application must be of type string.');
    }
    if (imageData === null || imageData === undefined) {
      throw new Error('imageData cannot be null or undefined and it must be of type object.');
    }
    if (this.apiKey === null || this.apiKey === undefined || typeof this.apiKey.valueOf() !== 'string') {
      throw new Error('this.apiKey cannot be null or undefined and it must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{projectId}/detect/iterations/{publishedName}/image/nostore';
  requestUrl = requestUrl.replace('{Endpoint}', this.endpoint);
  requestUrl = requestUrl.replace('{projectId}', encodeURIComponent(projectId.toString()));
  requestUrl = requestUrl.replace('{publishedName}', encodeURIComponent(publishedName));
  let queryParameters = [];
  if (application !== null && application !== undefined) {
    queryParameters.push('application=' + encodeURIComponent(application));
  }
  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'] = 'multipart/form-data';
  if (this.apiKey !== undefined && this.apiKey !== null) {
    httpRequest.headers['Prediction-Key'] = this.apiKey;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  // Serialize Request
  let formData = {};
  if (imageData !== undefined && imageData !== null) {
    formData['imageData'] = imageData;
  }
  httpRequest.formData = formData;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          let internalError = null;
          if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
          error.code = internalError ? internalError.code : parsedErrorResponse.code;
          error.message = internalError ? internalError.message : parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CustomVisionError']().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['ImagePrediction']().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 PredictionAPIClient. */
class PredictionAPIClient extends ServiceClient {
  /**
   * Create a PredictionAPIClient.
   * @param {string} apiKey - API key.
   * @param {string} endpoint - Supported Cognitive Services endpoints.
   * @param {object} [options] - The parameter options
   * @param {Array} [options.filters] - Filters to be added to the request pipeline
   * @param {object} [options.requestOptions] - Options for the underlying request object
   * {@link https://github.com/request/request#requestoptions-callback Options doc}
   * @param {boolean} [options.noRetryPolicy] - If set to true, turn off default retry policy
   */
  constructor(apiKey, endpoint, options) {
    if (apiKey === null || apiKey === undefined) {
      throw new Error('\'apiKey\' cannot be null.');
    }
    if (endpoint === null || endpoint === undefined) {
      throw new Error('\'endpoint\' cannot be null.');
    }

    if (!options) options = {};

    super(null, options);

    this.baseUri = '{Endpoint}/customvision/v3.0/prediction';
    this.apiKey = apiKey;
    this.endpoint = endpoint;

    let packageInfo = this.getPackageJsonInfo(__dirname);
    this.addUserAgentInfo(`${packageInfo.name}/${packageInfo.version}`);
    this.models = models;
    this._classifyImageUrl = _classifyImageUrl;
    this._classifyImage = _classifyImage;
    this._classifyImageUrlWithNoStore = _classifyImageUrlWithNoStore;
    this._classifyImageWithNoStore = _classifyImageWithNoStore;
    this._detectImageUrl = _detectImageUrl;
    this._detectImage = _detectImage;
    this._detectImageUrlWithNoStore = _detectImageUrlWithNoStore;
    this._detectImageWithNoStore = _detectImageWithNoStore;
    msRest.addSerializationMixin(this);
  }

  /**
   * @summary Classify an image url and saves the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageUrl An ImageUrl that contains the url of the image to
   * be evaluated.
   *
   * @param {string} imageUrl.url Url of the image.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ImagePrediction>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  classifyImageUrlWithHttpOperationResponse(projectId, publishedName, imageUrl, options) {
    let client = this;
    let self = this;
    return new Promise((resolve, reject) => {
      self._classifyImageUrl(projectId, publishedName, imageUrl, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Classify an image url and saves the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageUrl An ImageUrl that contains the url of the image to
   * be evaluated.
   *
   * @param {string} imageUrl.url Url of the image.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @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 {ImagePrediction} - 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 ImagePrediction} 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.
   */
  classifyImageUrl(projectId, publishedName, imageUrl, options, optionalCallback) {
    let client = this;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._classifyImageUrl(projectId, publishedName, imageUrl, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._classifyImageUrl(projectId, publishedName, imageUrl, options, optionalCallback);
    }
  }

  /**
   * @summary Classify an image and saves the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageData Binary image data. Supported formats are JPEG,
   * GIF, PNG, and BMP. Supports images up to 4MB.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ImagePrediction>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  classifyImageWithHttpOperationResponse(projectId, publishedName, imageData, options) {
    let client = this;
    let self = this;
    return new Promise((resolve, reject) => {
      self._classifyImage(projectId, publishedName, imageData, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Classify an image and saves the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageData Binary image data. Supported formats are JPEG,
   * GIF, PNG, and BMP. Supports images up to 4MB.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @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 {ImagePrediction} - 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 ImagePrediction} 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.
   */
  classifyImage(projectId, publishedName, imageData, options, optionalCallback) {
    let client = this;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._classifyImage(projectId, publishedName, imageData, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._classifyImage(projectId, publishedName, imageData, options, optionalCallback);
    }
  }

  /**
   * @summary Classify an image url without saving the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageUrl An {Iris.Web.Api.Models.ImageUrl} that contains the
   * url of the image to be evaluated.
   *
   * @param {string} imageUrl.url Url of the image.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ImagePrediction>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  classifyImageUrlWithNoStoreWithHttpOperationResponse(projectId, publishedName, imageUrl, options) {
    let client = this;
    let self = this;
    return new Promise((resolve, reject) => {
      self._classifyImageUrlWithNoStore(projectId, publishedName, imageUrl, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Classify an image url without saving the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageUrl An {Iris.Web.Api.Models.ImageUrl} that contains the
   * url of the image to be evaluated.
   *
   * @param {string} imageUrl.url Url of the image.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @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 {ImagePrediction} - 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 ImagePrediction} 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.
   */
  classifyImageUrlWithNoStore(projectId, publishedName, imageUrl, options, optionalCallback) {
    let client = this;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._classifyImageUrlWithNoStore(projectId, publishedName, imageUrl, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._classifyImageUrlWithNoStore(projectId, publishedName, imageUrl, options, optionalCallback);
    }
  }

  /**
   * @summary Classify an image without saving the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageData Binary image data. Supported formats are JPEG,
   * GIF, PNG, and BMP. Supports images up to 0MB.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ImagePrediction>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  classifyImageWithNoStoreWithHttpOperationResponse(projectId, publishedName, imageData, options) {
    let client = this;
    let self = this;
    return new Promise((resolve, reject) => {
      self._classifyImageWithNoStore(projectId, publishedName, imageData, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Classify an image without saving the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageData Binary image data. Supported formats are JPEG,
   * GIF, PNG, and BMP. Supports images up to 0MB.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @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 {ImagePrediction} - 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 ImagePrediction} 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.
   */
  classifyImageWithNoStore(projectId, publishedName, imageData, options, optionalCallback) {
    let client = this;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._classifyImageWithNoStore(projectId, publishedName, imageData, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._classifyImageWithNoStore(projectId, publishedName, imageData, options, optionalCallback);
    }
  }

  /**
   * @summary Detect objects in an image url and saves the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageUrl An ImageUrl that contains the url of the image to
   * be evaluated.
   *
   * @param {string} imageUrl.url Url of the image.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ImagePrediction>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  detectImageUrlWithHttpOperationResponse(projectId, publishedName, imageUrl, options) {
    let client = this;
    let self = this;
    return new Promise((resolve, reject) => {
      self._detectImageUrl(projectId, publishedName, imageUrl, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Detect objects in an image url and saves the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageUrl An ImageUrl that contains the url of the image to
   * be evaluated.
   *
   * @param {string} imageUrl.url Url of the image.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @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 {ImagePrediction} - 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 ImagePrediction} 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.
   */
  detectImageUrl(projectId, publishedName, imageUrl, options, optionalCallback) {
    let client = this;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._detectImageUrl(projectId, publishedName, imageUrl, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._detectImageUrl(projectId, publishedName, imageUrl, options, optionalCallback);
    }
  }

  /**
   * @summary Detect objects in an image and saves the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageData Binary image data. Supported formats are JPEG,
   * GIF, PNG, and BMP. Supports images up to 4MB.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ImagePrediction>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  detectImageWithHttpOperationResponse(projectId, publishedName, imageData, options) {
    let client = this;
    let self = this;
    return new Promise((resolve, reject) => {
      self._detectImage(projectId, publishedName, imageData, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Detect objects in an image and saves the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageData Binary image data. Supported formats are JPEG,
   * GIF, PNG, and BMP. Supports images up to 4MB.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @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 {ImagePrediction} - 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 ImagePrediction} 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.
   */
  detectImage(projectId, publishedName, imageData, options, optionalCallback) {
    let client = this;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._detectImage(projectId, publishedName, imageData, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._detectImage(projectId, publishedName, imageData, options, optionalCallback);
    }
  }

  /**
   * @summary Detect objects in an image url without saving the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageUrl An {Iris.Web.Api.Models.ImageUrl} that contains the
   * url of the image to be evaluated.
   *
   * @param {string} imageUrl.url Url of the image.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ImagePrediction>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  detectImageUrlWithNoStoreWithHttpOperationResponse(projectId, publishedName, imageUrl, options) {
    let client = this;
    let self = this;
    return new Promise((resolve, reject) => {
      self._detectImageUrlWithNoStore(projectId, publishedName, imageUrl, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Detect objects in an image url without saving the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageUrl An {Iris.Web.Api.Models.ImageUrl} that contains the
   * url of the image to be evaluated.
   *
   * @param {string} imageUrl.url Url of the image.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @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 {ImagePrediction} - 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 ImagePrediction} 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.
   */
  detectImageUrlWithNoStore(projectId, publishedName, imageUrl, options, optionalCallback) {
    let client = this;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._detectImageUrlWithNoStore(projectId, publishedName, imageUrl, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._detectImageUrlWithNoStore(projectId, publishedName, imageUrl, options, optionalCallback);
    }
  }

  /**
   * @summary Detect objects in an image without saving the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageData Binary image data. Supported formats are JPEG,
   * GIF, PNG, and BMP. Supports images up to 0MB.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ImagePrediction>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  detectImageWithNoStoreWithHttpOperationResponse(projectId, publishedName, imageData, options) {
    let client = this;
    let self = this;
    return new Promise((resolve, reject) => {
      self._detectImageWithNoStore(projectId, publishedName, imageData, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Detect objects in an image without saving the result.
   *
   * @param {uuid} projectId The project id.
   *
   * @param {string} publishedName Specifies the name of the model to evaluate
   * against.
   *
   * @param {object} imageData Binary image data. Supported formats are JPEG,
   * GIF, PNG, and BMP. Supports images up to 0MB.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.application] Optional. Specifies the name of
   * application using the endpoint.
   *
   * @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 {ImagePrediction} - 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 ImagePrediction} 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.
   */
  detectImageWithNoStore(projectId, publishedName, imageData, options, optionalCallback) {
    let client = this;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._detectImageWithNoStore(projectId, publishedName, imageData, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._detectImageWithNoStore(projectId, publishedName, imageData, options, optionalCallback);
    }
  }

}

module.exports = PredictionAPIClient;
module.exports['default'] = PredictionAPIClient;
module.exports.PredictionAPIClient = PredictionAPIClient;
module.exports.PredictionAPIModels = models;
