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

'use strict';

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

/**
 * Creates a connector mapping or updates an existing connector mapping in the
 * connector.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} hubName The name of the hub.
 *
 * @param {string} connectorName The name of the connector.
 *
 * @param {string} mappingName The name of the connector mapping.
 *
 * @param {object} parameters Parameters supplied to the CreateOrUpdate
 * Connector Mapping operation.
 *
 * @param {string} [parameters.connectorType] Type of connector. Possible
 * values include: 'None', 'CRM', 'AzureBlob', 'Salesforce', 'ExchangeOnline',
 * 'Outbound'
 *
 * @param {string} parameters.entityType Defines which entity type the file
 * should map to. Possible values include: 'None', 'Profile', 'Interaction',
 * 'Relationship'
 *
 * @param {string} parameters.entityTypeName The mapping entity name.
 *
 * @param {string} [parameters.displayName] Display name for the connector
 * mapping.
 *
 * @param {string} [parameters.description] The description of the connector
 * mapping.
 *
 * @param {object} parameters.mappingProperties The properties of the mapping.
 *
 * @param {string} [parameters.mappingProperties.folderPath] The folder path
 * for the mapping.
 *
 * @param {string} [parameters.mappingProperties.fileFilter] The file filter
 * for the mapping.
 *
 * @param {boolean} [parameters.mappingProperties.hasHeader] If the file
 * contains a header or not.
 *
 * @param {object} parameters.mappingProperties.errorManagement The error
 * management setting for the mapping.
 *
 * @param {string}
 * parameters.mappingProperties.errorManagement.errorManagementType The type of
 * error management to use for the mapping. Possible values include:
 * 'RejectAndContinue', 'StopImport', 'RejectUntilLimit'
 *
 * @param {number} [parameters.mappingProperties.errorManagement.errorLimit]
 * The error limit allowed while importing data.
 *
 * @param {object} parameters.mappingProperties.format The format of mapping
 * property.
 *
 * @param {string} [parameters.mappingProperties.format.columnDelimiter] The
 * character that signifies a break between columns.
 *
 * @param {string} [parameters.mappingProperties.format.acceptLanguage] The
 * oData language.
 *
 * @param {string} [parameters.mappingProperties.format.quoteCharacter] Quote
 * character, used to indicate enquoted fields.
 *
 * @param {string} [parameters.mappingProperties.format.quoteEscapeCharacter]
 * Escape character for quotes, can be the same as the quoteCharacter.
 *
 * @param {string} [parameters.mappingProperties.format.arraySeparator]
 * Character separating array elements.
 *
 * @param {object} parameters.mappingProperties.availability The availability
 * of mapping property.
 *
 * @param {string} [parameters.mappingProperties.availability.frequency] The
 * frequency to update. Possible values include: 'Minute', 'Hour', 'Day',
 * 'Week', 'Month'
 *
 * @param {number} parameters.mappingProperties.availability.interval The
 * interval of the given frequency to use.
 *
 * @param {array} parameters.mappingProperties.structure Ingestion mapping
 * information at property level.
 *
 * @param {object} parameters.mappingProperties.completeOperation The operation
 * after import is done.
 *
 * @param {string}
 * [parameters.mappingProperties.completeOperation.completionOperationType] The
 * type of completion operation. Possible values include: 'DoNothing',
 * 'DeleteFile', 'MoveFile'
 *
 * @param {string}
 * [parameters.mappingProperties.completeOperation.destinationFolder] The
 * destination folder where files will be moved to once the import is done.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link ConnectorMappingResourceFormat} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _createOrUpdate(resourceGroupName, hubName, connectorName, mappingName, parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  if (parameters === null || parameters === undefined)
  {
    parameters = {};
  }
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (hubName === null || hubName === undefined || typeof hubName.valueOf() !== 'string') {
      throw new Error('hubName cannot be null or undefined and it must be of type string.');
    }
    if (connectorName === null || connectorName === undefined || typeof connectorName.valueOf() !== 'string') {
      throw new Error('connectorName cannot be null or undefined and it must be of type string.');
    }
    if (mappingName === null || mappingName === undefined || typeof mappingName.valueOf() !== 'string') {
      throw new Error('mappingName cannot be null or undefined and it must be of type string.');
    }
    if (mappingName !== null && mappingName !== undefined) {
      if (mappingName.length > 128)
      {
        throw new Error('"mappingName" should satisfy the constraint - "MaxLength": 128');
      }
      if (mappingName.length < 1)
      {
        throw new Error('"mappingName" should satisfy the constraint - "MinLength": 1');
      }
      if (mappingName.match(/^[a-zA-Z][a-zA-Z0-9_]+$/) === null)
      {
        throw new Error('"mappingName" should satisfy the constraint - "Pattern": /^[a-zA-Z][a-zA-Z0-9_]+$/');
      }
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomerInsights/hubs/{hubName}/connectors/{connectorName}/mappings/{mappingName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{hubName}', encodeURIComponent(hubName));
  requestUrl = requestUrl.replace('{connectorName}', encodeURIComponent(connectorName));
  requestUrl = requestUrl.replace('{mappingName}', encodeURIComponent(mappingName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

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

/**
 * Gets a connector mapping in the connector.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} hubName The name of the hub.
 *
 * @param {string} connectorName The name of the connector.
 *
 * @param {string} mappingName The name of the connector mapping.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link ConnectorMappingResourceFormat} for more
 *                      information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _get(resourceGroupName, hubName, connectorName, mappingName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (hubName === null || hubName === undefined || typeof hubName.valueOf() !== 'string') {
      throw new Error('hubName cannot be null or undefined and it must be of type string.');
    }
    if (connectorName === null || connectorName === undefined || typeof connectorName.valueOf() !== 'string') {
      throw new Error('connectorName cannot be null or undefined and it must be of type string.');
    }
    if (mappingName === null || mappingName === undefined || typeof mappingName.valueOf() !== 'string') {
      throw new Error('mappingName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomerInsights/hubs/{hubName}/connectors/{connectorName}/mappings/{mappingName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{hubName}', encodeURIComponent(hubName));
  requestUrl = requestUrl.replace('{connectorName}', encodeURIComponent(connectorName));
  requestUrl = requestUrl.replace('{mappingName}', encodeURIComponent(mappingName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

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

/**
 * Deletes a connector mapping in the connector.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} hubName The name of the hub.
 *
 * @param {string} connectorName The name of the connector.
 *
 * @param {string} mappingName The name of the connector mapping.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _deleteMethod(resourceGroupName, hubName, connectorName, mappingName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (hubName === null || hubName === undefined || typeof hubName.valueOf() !== 'string') {
      throw new Error('hubName cannot be null or undefined and it must be of type string.');
    }
    if (connectorName === null || connectorName === undefined || typeof connectorName.valueOf() !== 'string') {
      throw new Error('connectorName cannot be null or undefined and it must be of type string.');
    }
    if (mappingName === null || mappingName === undefined || typeof mappingName.valueOf() !== 'string') {
      throw new Error('mappingName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CustomerInsights/hubs/{hubName}/connectors/{connectorName}/mappings/{mappingName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{hubName}', encodeURIComponent(hubName));
  requestUrl = requestUrl.replace('{connectorName}', encodeURIComponent(connectorName));
  requestUrl = requestUrl.replace('{mappingName}', encodeURIComponent(mappingName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

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

/**
 * Gets all the connector mappings in the specified connector.
 *
 * @param {string} resourceGroupName The name of the resource group.
 *
 * @param {string} hubName The name of the hub.
 *
 * @param {string} connectorName The name of the connector.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link ConnectorMappingListResult} 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 _listByConnector(resourceGroupName, hubName, connectorName, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (hubName === null || hubName === undefined || typeof hubName.valueOf() !== 'string') {
      throw new Error('hubName cannot be null or undefined and it must be of type string.');
    }
    if (connectorName === null || connectorName === undefined || typeof connectorName.valueOf() !== 'string') {
      throw new Error('connectorName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

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

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

/**
 * Gets all the connector mappings in the specified connector.
 *
 * @param {string} nextPageLink The NextLink from the previous successful call
 * to List operation.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {object} [result]   - The deserialized result object if an error did not occur.
 *                      See {@link ConnectorMappingListResult} 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 _listByConnectorNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let requestUrl = '{nextLink}';
  requestUrl = requestUrl.replace('{nextLink}', nextPageLink);

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

  /**
   * Creates a connector mapping or updates an existing connector mapping in the
   * connector.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} hubName The name of the hub.
   *
   * @param {string} connectorName The name of the connector.
   *
   * @param {string} mappingName The name of the connector mapping.
   *
   * @param {object} parameters Parameters supplied to the CreateOrUpdate
   * Connector Mapping operation.
   *
   * @param {string} [parameters.connectorType] Type of connector. Possible
   * values include: 'None', 'CRM', 'AzureBlob', 'Salesforce', 'ExchangeOnline',
   * 'Outbound'
   *
   * @param {string} parameters.entityType Defines which entity type the file
   * should map to. Possible values include: 'None', 'Profile', 'Interaction',
   * 'Relationship'
   *
   * @param {string} parameters.entityTypeName The mapping entity name.
   *
   * @param {string} [parameters.displayName] Display name for the connector
   * mapping.
   *
   * @param {string} [parameters.description] The description of the connector
   * mapping.
   *
   * @param {object} parameters.mappingProperties The properties of the mapping.
   *
   * @param {string} [parameters.mappingProperties.folderPath] The folder path
   * for the mapping.
   *
   * @param {string} [parameters.mappingProperties.fileFilter] The file filter
   * for the mapping.
   *
   * @param {boolean} [parameters.mappingProperties.hasHeader] If the file
   * contains a header or not.
   *
   * @param {object} parameters.mappingProperties.errorManagement The error
   * management setting for the mapping.
   *
   * @param {string}
   * parameters.mappingProperties.errorManagement.errorManagementType The type of
   * error management to use for the mapping. Possible values include:
   * 'RejectAndContinue', 'StopImport', 'RejectUntilLimit'
   *
   * @param {number} [parameters.mappingProperties.errorManagement.errorLimit]
   * The error limit allowed while importing data.
   *
   * @param {object} parameters.mappingProperties.format The format of mapping
   * property.
   *
   * @param {string} [parameters.mappingProperties.format.columnDelimiter] The
   * character that signifies a break between columns.
   *
   * @param {string} [parameters.mappingProperties.format.acceptLanguage] The
   * oData language.
   *
   * @param {string} [parameters.mappingProperties.format.quoteCharacter] Quote
   * character, used to indicate enquoted fields.
   *
   * @param {string} [parameters.mappingProperties.format.quoteEscapeCharacter]
   * Escape character for quotes, can be the same as the quoteCharacter.
   *
   * @param {string} [parameters.mappingProperties.format.arraySeparator]
   * Character separating array elements.
   *
   * @param {object} parameters.mappingProperties.availability The availability
   * of mapping property.
   *
   * @param {string} [parameters.mappingProperties.availability.frequency] The
   * frequency to update. Possible values include: 'Minute', 'Hour', 'Day',
   * 'Week', 'Month'
   *
   * @param {number} parameters.mappingProperties.availability.interval The
   * interval of the given frequency to use.
   *
   * @param {array} parameters.mappingProperties.structure Ingestion mapping
   * information at property level.
   *
   * @param {object} parameters.mappingProperties.completeOperation The operation
   * after import is done.
   *
   * @param {string}
   * [parameters.mappingProperties.completeOperation.completionOperationType] The
   * type of completion operation. Possible values include: 'DoNothing',
   * 'DeleteFile', 'MoveFile'
   *
   * @param {string}
   * [parameters.mappingProperties.completeOperation.destinationFolder] The
   * destination folder where files will be moved to once the import is done.
   *
   * @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<ConnectorMappingResourceFormat>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createOrUpdateWithHttpOperationResponse(resourceGroupName, hubName, connectorName, mappingName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._createOrUpdate(resourceGroupName, hubName, connectorName, mappingName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates a connector mapping or updates an existing connector mapping in the
   * connector.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} hubName The name of the hub.
   *
   * @param {string} connectorName The name of the connector.
   *
   * @param {string} mappingName The name of the connector mapping.
   *
   * @param {object} parameters Parameters supplied to the CreateOrUpdate
   * Connector Mapping operation.
   *
   * @param {string} [parameters.connectorType] Type of connector. Possible
   * values include: 'None', 'CRM', 'AzureBlob', 'Salesforce', 'ExchangeOnline',
   * 'Outbound'
   *
   * @param {string} parameters.entityType Defines which entity type the file
   * should map to. Possible values include: 'None', 'Profile', 'Interaction',
   * 'Relationship'
   *
   * @param {string} parameters.entityTypeName The mapping entity name.
   *
   * @param {string} [parameters.displayName] Display name for the connector
   * mapping.
   *
   * @param {string} [parameters.description] The description of the connector
   * mapping.
   *
   * @param {object} parameters.mappingProperties The properties of the mapping.
   *
   * @param {string} [parameters.mappingProperties.folderPath] The folder path
   * for the mapping.
   *
   * @param {string} [parameters.mappingProperties.fileFilter] The file filter
   * for the mapping.
   *
   * @param {boolean} [parameters.mappingProperties.hasHeader] If the file
   * contains a header or not.
   *
   * @param {object} parameters.mappingProperties.errorManagement The error
   * management setting for the mapping.
   *
   * @param {string}
   * parameters.mappingProperties.errorManagement.errorManagementType The type of
   * error management to use for the mapping. Possible values include:
   * 'RejectAndContinue', 'StopImport', 'RejectUntilLimit'
   *
   * @param {number} [parameters.mappingProperties.errorManagement.errorLimit]
   * The error limit allowed while importing data.
   *
   * @param {object} parameters.mappingProperties.format The format of mapping
   * property.
   *
   * @param {string} [parameters.mappingProperties.format.columnDelimiter] The
   * character that signifies a break between columns.
   *
   * @param {string} [parameters.mappingProperties.format.acceptLanguage] The
   * oData language.
   *
   * @param {string} [parameters.mappingProperties.format.quoteCharacter] Quote
   * character, used to indicate enquoted fields.
   *
   * @param {string} [parameters.mappingProperties.format.quoteEscapeCharacter]
   * Escape character for quotes, can be the same as the quoteCharacter.
   *
   * @param {string} [parameters.mappingProperties.format.arraySeparator]
   * Character separating array elements.
   *
   * @param {object} parameters.mappingProperties.availability The availability
   * of mapping property.
   *
   * @param {string} [parameters.mappingProperties.availability.frequency] The
   * frequency to update. Possible values include: 'Minute', 'Hour', 'Day',
   * 'Week', 'Month'
   *
   * @param {number} parameters.mappingProperties.availability.interval The
   * interval of the given frequency to use.
   *
   * @param {array} parameters.mappingProperties.structure Ingestion mapping
   * information at property level.
   *
   * @param {object} parameters.mappingProperties.completeOperation The operation
   * after import is done.
   *
   * @param {string}
   * [parameters.mappingProperties.completeOperation.completionOperationType] The
   * type of completion operation. Possible values include: 'DoNothing',
   * 'DeleteFile', 'MoveFile'
   *
   * @param {string}
   * [parameters.mappingProperties.completeOperation.destinationFolder] The
   * destination folder where files will be moved to once the import is done.
   *
   * @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 {ConnectorMappingResourceFormat} - 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 ConnectorMappingResourceFormat} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  createOrUpdate(resourceGroupName, hubName, connectorName, mappingName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._createOrUpdate(resourceGroupName, hubName, connectorName, mappingName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._createOrUpdate(resourceGroupName, hubName, connectorName, mappingName, parameters, options, optionalCallback);
    }
  }

  /**
   * Gets a connector mapping in the connector.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} hubName The name of the hub.
   *
   * @param {string} connectorName The name of the connector.
   *
   * @param {string} mappingName The name of the connector mapping.
   *
   * @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<ConnectorMappingResourceFormat>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getWithHttpOperationResponse(resourceGroupName, hubName, connectorName, mappingName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._get(resourceGroupName, hubName, connectorName, mappingName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets a connector mapping in the connector.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} hubName The name of the hub.
   *
   * @param {string} connectorName The name of the connector.
   *
   * @param {string} mappingName The name of the connector mapping.
   *
   * @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 {ConnectorMappingResourceFormat} - 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 ConnectorMappingResourceFormat} for more
   *                      information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  get(resourceGroupName, hubName, connectorName, mappingName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._get(resourceGroupName, hubName, connectorName, mappingName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._get(resourceGroupName, hubName, connectorName, mappingName, options, optionalCallback);
    }
  }

  /**
   * Deletes a connector mapping in the connector.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} hubName The name of the hub.
   *
   * @param {string} connectorName The name of the connector.
   *
   * @param {string} mappingName The name of the connector mapping.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  deleteMethodWithHttpOperationResponse(resourceGroupName, hubName, connectorName, mappingName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._deleteMethod(resourceGroupName, hubName, connectorName, mappingName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Deletes a connector mapping in the connector.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} hubName The name of the hub.
   *
   * @param {string} connectorName The name of the connector.
   *
   * @param {string} mappingName The name of the connector mapping.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {null} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  deleteMethod(resourceGroupName, hubName, connectorName, mappingName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._deleteMethod(resourceGroupName, hubName, connectorName, mappingName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._deleteMethod(resourceGroupName, hubName, connectorName, mappingName, options, optionalCallback);
    }
  }

  /**
   * Gets all the connector mappings in the specified connector.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} hubName The name of the hub.
   *
   * @param {string} connectorName The name of the connector.
   *
   * @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<ConnectorMappingListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByConnectorWithHttpOperationResponse(resourceGroupName, hubName, connectorName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByConnector(resourceGroupName, hubName, connectorName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets all the connector mappings in the specified connector.
   *
   * @param {string} resourceGroupName The name of the resource group.
   *
   * @param {string} hubName The name of the hub.
   *
   * @param {string} connectorName The name of the connector.
   *
   * @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 {ConnectorMappingListResult} - 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 ConnectorMappingListResult} 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.
   */
  listByConnector(resourceGroupName, hubName, connectorName, 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._listByConnector(resourceGroupName, hubName, connectorName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByConnector(resourceGroupName, hubName, connectorName, options, optionalCallback);
    }
  }

  /**
   * Gets all the connector mappings in the specified connector.
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<ConnectorMappingListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByConnectorNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByConnectorNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets all the connector mappings in the specified connector.
   *
   * @param {string} nextPageLink The NextLink from the previous successful call
   * to List operation.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {ConnectorMappingListResult} - 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 ConnectorMappingListResult} 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.
   */
  listByConnectorNext(nextPageLink, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._listByConnectorNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByConnectorNext(nextPageLink, options, optionalCallback);
    }
  }

}

module.exports = ConnectorMappings;
