text: /*
   * 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 WebResource = msRest.WebResource;
  
  /**
   * @summary Adds one pattern to the specified application.
   *
   * @param {uuid} appId The application ID.
   *
   * @param {string} versionId The version ID.
   *
   * @param {object} pattern The input pattern.
   *
   * @param {string} [pattern.pattern] The pattern text.
   *
   * @param {string} [pattern.intent] The intent's name which the pattern belongs
   * to.
   *
   * @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 PatternRuleInfo} 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 _addPattern(appId, versionId, pattern, 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 (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') {
        throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.');
      }
      if (appId === null || appId === undefined || typeof appId.valueOf() !== 'string' || !msRest.isValidUuid(appId)) {
        throw new Error('appId cannot be null or undefined and it must be of type string and must be a valid uuid.');
      }
      if (versionId === null || versionId === undefined || typeof versionId.valueOf() !== 'string') {
        throw new Error('versionId cannot be null or undefined and it must be of type string.');
      }
      if (pattern === null || pattern === undefined) {
        throw new Error('pattern cannot be null or undefined.');
      }
    } catch (error) {
      return callback(error);
    }
  
    // Construct URL
    let baseUrl = this.client.baseUri;
    let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'apps/{appId}/versions/{versionId}/patternrule';
    requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint);
    requestUrl = requestUrl.replace('{appId}', encodeURIComponent(appId.toString()));
    requestUrl = requestUrl.replace('{versionId}', encodeURIComponent(versionId));
  
    // Create HTTP transport objects
    let httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.url = requestUrl;
    httpRequest.headers = {};
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    if(options) {
      for(let headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    // Serialize Request
    let requestContent = null;
    let requestModel = null;
    try {
      if (pattern !== null && pattern !== undefined) {
        let requestModelMapper = new client.models['PatternRuleCreateObject']().mapper();
        requestModel = client.serialize(requestModelMapper, pattern, 'pattern');
        requestContent = JSON.stringify(requestModel);
      }
    } catch (error) {
      let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
          `payload - ${JSON.stringify(pattern, 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 !== 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) {
            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['ErrorResponse']().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 === 201) {
        let parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            let resultMapper = new client.models['PatternRuleInfo']().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 Returns an application version's patterns.
   *
   * @param {uuid} appId The application ID.
   *
   * @param {string} versionId The version ID.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {number} [options.skip] The number of entries to skip. Default value
   * is 0.
   *
   * @param {number} [options.take] The number of entries to return. Maximum page
   * size is 500. Default is 100.
   *
   * @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.
   *
   *                      {array} [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 _getPatterns(appId, versionId, options, callback) {
     /* jshint validthis: true */
    let client = this.client;
    if(!callback && typeof options === 'function') {
      callback = options;
      options = null;
    }
    if (!callback) {
      throw new Error('callback cannot be null.');
    }
    let skip = (options && options.skip !== undefined) ? options.skip : 0;
    let take = (options && options.take !== undefined) ? options.take : 100;
    // Validate
    try {
      if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') {
        throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.');
      }
      if (appId === null || appId === undefined || typeof appId.valueOf() !== 'string' || !msRest.isValidUuid(appId)) {
        throw new Error('appId cannot be null or undefined and it must be of type string and must be a valid uuid.');
      }
      if (versionId === null || versionId === undefined || typeof versionId.valueOf() !== 'string') {
        throw new Error('versionId cannot be null or undefined and it must be of type string.');
      }
      if (skip !== null && skip !== undefined && typeof skip !== 'number') {
        throw new Error('skip must be of type number.');
      }
      if (skip !== null && skip !== undefined) {
        if (skip < 0)
        {
          throw new Error('"skip" should satisfy the constraint - "InclusiveMinimum": 0');
        }
      }
      if (take !== null && take !== undefined && typeof take !== 'number') {
        throw new Error('take must be of type number.');
      }
      if (take !== null && take !== undefined) {
        if (take > 500)
        {
          throw new Error('"take" should satisfy the constraint - "InclusiveMaximum": 500');
        }
        if (take < 0)
        {
          throw new Error('"take" should satisfy the constraint - "InclusiveMinimum": 0');
        }
      }
    } catch (error) {
      return callback(error);
    }
  
    // Construct URL
    let baseUrl = this.client.baseUri;
    let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'apps/{appId}/versions/{versionId}/patternrules';
    requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint);
    requestUrl = requestUrl.replace('{appId}', encodeURIComponent(appId.toString()));
    requestUrl = requestUrl.replace('{versionId}', encodeURIComponent(versionId));
    let queryParameters = [];
    if (skip !== null && skip !== undefined) {
      queryParameters.push('skip=' + encodeURIComponent(skip.toString()));
    }
    if (take !== null && take !== undefined) {
      queryParameters.push('take=' + encodeURIComponent(take.toString()));
    }
    if (queryParameters.length > 0) {
      requestUrl += '?' + queryParameters.join('&');
    }
  
    // Create HTTP transport objects
    let httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.url = requestUrl;
    httpRequest.headers = {};
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    if(options) {
      for(let headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.body = null;
    // Send Request
    return client.pipeline(httpRequest, (err, response, responseBody) => {
      if (err) {
        return callback(err);
      }
      let statusCode = response.statusCode;
      if (statusCode !== 200) {
        let error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        let parsedErrorResponse;
        try {
          parsedErrorResponse = JSON.parse(responseBody);
          if (parsedErrorResponse) {
            let internalError = null;
            if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
            error.code = internalError ? internalError.code : parsedErrorResponse.code;
            error.message = internalError ? internalError.message : parsedErrorResponse.message;
          }
          if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
            let resultMapper = new client.models['ErrorResponse']().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 = {
              required: false,
              serializedName: 'parsedResponse',
              type: {
                name: 'Sequence',
                element: {
                    required: false,
                    serializedName: 'PatternRuleInfoElementType',
                    type: {
                      name: 'Composite',
                      className: 'PatternRuleInfo'
                    }
                }
              }
            };
            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 Updates patterns
   *
   * @param {uuid} appId The application ID.
   *
   * @param {string} versionId The version ID.
   *
   * @param {array} patterns An array represents the patterns.
   *
   * @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.
   *
   *                      {array} [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 _updatePatterns(appId, versionId, patterns, 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 (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') {
        throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.');
      }
      if (appId === null || appId === undefined || typeof appId.valueOf() !== 'string' || !msRest.isValidUuid(appId)) {
        throw new Error('appId cannot be null or undefined and it must be of type string and must be a valid uuid.');
      }
      if (versionId === null || versionId === undefined || typeof versionId.valueOf() !== 'string') {
        throw new Error('versionId cannot be null or undefined and it must be of type string.');
      }
    } catch (error) {
      return callback(error);
    }
  
    // Construct URL
    let baseUrl = this.client.baseUri;
    let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'apps/{appId}/versions/{versionId}/patternrules';
    requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint);
    requestUrl = requestUrl.replace('{appId}', encodeURIComponent(appId.toString()));
    requestUrl = requestUrl.replace('{versionId}', encodeURIComponent(versionId));
  
    // 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(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 (patterns !== null && patterns !== undefined) {
        let requestModelMapper = {
          required: true,
          serializedName: 'patterns',
          type: {
            name: 'Sequence',
            element: {
                required: false,
                serializedName: 'PatternRuleUpdateObjectElementType',
                type: {
                  name: 'Composite',
                  className: 'PatternRuleUpdateObject'
                }
            }
          }
        };
        requestModel = client.serialize(requestModelMapper, patterns, 'patterns');
        requestContent = JSON.stringify(requestModel);
      }
    } catch (error) {
      let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
          `payload - ${JSON.stringify(patterns, 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['ErrorResponse']().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 = {
              required: false,
              serializedName: 'parsedResponse',
              type: {
                name: 'Sequence',
                element: {
                    required: false,
                    serializedName: 'PatternRuleInfoElementType',
                    type: {
                      name: 'Composite',
                      className: 'PatternRuleInfo'
                    }
                }
              }
            };
            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 Adds a batch of patterns to the specified application.
   *
   * @param {uuid} appId The application ID.
   *
   * @param {string} versionId The version ID.
   *
   * @param {array} patterns A JSON array containing patterns.
   *
   * @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.
   *
   *                      {array} [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 _batchAddPatterns(appId, versionId, patterns, 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 (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') {
        throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.');
      }
      if (appId === null || appId === undefined || typeof appId.valueOf() !== 'string' || !msRest.isValidUuid(appId)) {
        throw new Error('appId cannot be null or undefined and it must be of type string and must be a valid uuid.');
      }
      if (versionId === null || versionId === undefined || typeof versionId.valueOf() !== 'string') {
        throw new Error('versionId cannot be null or undefined and it must be of type string.');
      }
    } catch (error) {
      return callback(error);
    }
  
    // Construct URL
    let baseUrl = this.client.baseUri;
    let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'apps/{appId}/versions/{versionId}/patternrules';
    requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint);
    requestUrl = requestUrl.replace('{appId}', encodeURIComponent(appId.toString()));
    requestUrl = requestUrl.replace('{versionId}', encodeURIComponent(versionId));
  
    // Create HTTP transport objects
    let httpRequest = new WebResource();
    httpRequest.method = 'POST';
    httpRequest.url = requestUrl;
    httpRequest.headers = {};
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    if(options) {
      for(let headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    // Serialize Request
    let requestContent = null;
    let requestModel = null;
    try {
      if (patterns !== null && patterns !== undefined) {
        let requestModelMapper = {
          required: true,
          serializedName: 'patterns',
          type: {
            name: 'Sequence',
            element: {
                required: false,
                serializedName: 'PatternRuleCreateObjectElementType',
                type: {
                  name: 'Composite',
                  className: 'PatternRuleCreateObject'
                }
            }
          }
        };
        requestModel = client.serialize(requestModelMapper, patterns, 'patterns');
        requestContent = JSON.stringify(requestModel);
      }
    } catch (error) {
      let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
          `payload - ${JSON.stringify(patterns, 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 !== 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) {
            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['ErrorResponse']().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 === 201) {
        let parsedResponse = null;
        try {
          parsedResponse = JSON.parse(responseBody);
          result = JSON.parse(responseBody);
          if (parsedResponse !== null && parsedResponse !== undefined) {
            let resultMapper = {
              required: false,
              serializedName: 'parsedResponse',
              type: {
                name: 'Sequence',
                element: {
                    required: false,
                    serializedName: 'PatternRuleInfoElementType',
                    type: {
                      name: 'Composite',
                      className: 'PatternRuleInfo'
                    }
                }
              }
            };
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
      }
  
      return callback(null, result, httpRequest, response);
    });
  }
  
  /**
   * @summary Deletes the patterns with the specified IDs.
   *
   * @param {uuid} appId The application ID.
   *
   * @param {string} versionId The version ID.
   *
   * @param {array} patternIds The patterns IDs.
   *
   * @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 OperationStatus} 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 _deletePatterns(appId, versionId, patternIds, 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 (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') {
        throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.');
      }
      if (appId === null || appId === undefined || typeof appId.valueOf() !== 'string' || !msRest.isValidUuid(appId)) {
        throw new Error('appId cannot be null or undefined and it must be of type string and must be a valid uuid.');
      }
      if (versionId === null || versionId === undefined || typeof versionId.valueOf() !== 'string') {
        throw new Error('versionId cannot be null or undefined and it must be of type string.');
      }
      if (!Array.isArray(patternIds)) {
        throw new Error('patternIds cannot be null or undefined and it must be of type array.');
      }
      for (let i = 0; i < patternIds.length; i++) {
        if (patternIds[i] !== null && patternIds[i] !== undefined && !(typeof patternIds[i].valueOf() === 'string' && msRest.isValidUuid(patternIds[i]))) {
          throw new Error('patternIds[i] must be of type string and must be a valid uuid.');
        }
      }
    } catch (error) {
      return callback(error);
    }
  
    // Construct URL
    let baseUrl = this.client.baseUri;
    let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'apps/{appId}/versions/{versionId}/patternrules';
    requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint);
    requestUrl = requestUrl.replace('{appId}', encodeURIComponent(appId.toString()));
    requestUrl = requestUrl.replace('{versionId}', encodeURIComponent(versionId));
  
    // 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(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 (patternIds !== null && patternIds !== undefined) {
        let requestModelMapper = {
          required: true,
          serializedName: 'patternIds',
          type: {
            name: 'Sequence',
            element: {
                required: false,
                serializedName: 'UuidElementType',
                type: {
                  name: 'String'
                }
            }
          }
        };
        requestModel = client.serialize(requestModelMapper, patternIds, 'patternIds');
        requestContent = JSON.stringify(requestModel);
      }
    } catch (error) {
      let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
          `payload - ${JSON.stringify(patternIds, 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['ErrorResponse']().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['OperationStatus']().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 Updates a pattern
   *
   * @param {uuid} appId The application ID.
   *
   * @param {string} versionId The version ID.
   *
   * @param {uuid} patternId The pattern ID.
   *
   * @param {object} pattern An object representing a pattern.
   *
   * @param {uuid} [pattern.id] The pattern ID.
   *
   * @param {string} [pattern.pattern] The pattern text.
   *
   * @param {string} [pattern.intent] The intent's name which the pattern belongs
   * to.
   *
   * @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 PatternRuleInfo} 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 _updatePattern(appId, versionId, patternId, pattern, 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 (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') {
        throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.');
      }
      if (appId === null || appId === undefined || typeof appId.valueOf() !== 'string' || !msRest.isValidUuid(appId)) {
        throw new Error('appId cannot be null or undefined and it must be of type string and must be a valid uuid.');
      }
      if (versionId === null || versionId === undefined || typeof versionId.valueOf() !== 'string') {
        throw new Error('versionId cannot be null or undefined and it must be of type string.');
      }
      if (patternId === null || patternId === undefined || typeof patternId.valueOf() !== 'string' || !msRest.isValidUuid(patternId)) {
        throw new Error('patternId cannot be null or undefined and it must be of type string and must be a valid uuid.');
      }
      if (pattern === null || pattern === undefined) {
        throw new Error('pattern cannot be null or undefined.');
      }
    } catch (error) {
      return callback(error);
    }
  
    // Construct URL
    let baseUrl = this.client.baseUri;
    let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'apps/{appId}/versions/{versionId}/patternrules/{patternId}';
    requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint);
    requestUrl = requestUrl.replace('{appId}', encodeURIComponent(appId.toString()));
    requestUrl = requestUrl.replace('{versionId}', encodeURIComponent(versionId));
    requestUrl = requestUrl.replace('{patternId}', encodeURIComponent(patternId.toString()));
  
    // 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(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 (pattern !== null && pattern !== undefined) {
        let requestModelMapper = new client.models['PatternRuleUpdateObject']().mapper();
        requestModel = client.serialize(requestModelMapper, pattern, 'pattern');
        requestContent = JSON.stringify(requestModel);
      }
    } catch (error) {
      let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
          `payload - ${JSON.stringify(pattern, 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['ErrorResponse']().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['PatternRuleInfo']().mapper();
            result = client.deserialize(resultMapper, parsedResponse, 'result');
          }
        } catch (error) {
          let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
          deserializationError.request = msRest.stripRequest(httpRequest);
          deserializationError.response = msRest.stripResponse(response);
          return callback(deserializationError);
        }
      }
  
      return callback(null, result, httpRequest, response);
    });
  }
  
  /**
   * @summary Deletes the pattern with the specified ID.
   *
   * @param {uuid} appId The application ID.
   *
   * @param {string} versionId The version ID.
   *
   * @param {uuid} patternId The pattern ID.
   *
   * @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 OperationStatus} 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 _deletePattern(appId, versionId, patternId, 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 (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') {
        throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.');
      }
      if (appId === null || appId === undefined || typeof appId.valueOf() !== 'string' || !msRest.isValidUuid(appId)) {
        throw new Error('appId cannot be null or undefined and it must be of type string and must be a valid uuid.');
      }
      if (versionId === null || versionId === undefined || typeof versionId.valueOf() !== 'string') {
        throw new Error('versionId cannot be null or undefined and it must be of type string.');
      }
      if (patternId === null || patternId === undefined || typeof patternId.valueOf() !== 'string' || !msRest.isValidUuid(patternId)) {
        throw new Error('patternId cannot be null or undefined and it must be of type string and must be a valid uuid.');
      }
    } catch (error) {
      return callback(error);
    }
  
    // Construct URL
    let baseUrl = this.client.baseUri;
    let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'apps/{appId}/versions/{versionId}/patternrules/{patternId}';
    requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint);
    requestUrl = requestUrl.replace('{appId}', encodeURIComponent(appId.toString()));
    requestUrl = requestUrl.replace('{versionId}', encodeURIComponent(versionId));
    requestUrl = requestUrl.replace('{patternId}', encodeURIComponent(patternId.toString()));
  
    // 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(options) {
      for(let headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.body = null;
    // Send Request
    return client.pipeline(httpRequest, (err, response, responseBody) => {
      if (err) {
        return callback(err);
      }
      let statusCode = response.statusCode;
      if (statusCode !== 200) {
        let error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        let parsedErrorResponse;
        try {
          parsedErrorResponse = JSON.parse(responseBody);
          if (parsedErrorResponse) {
            let internalError = null;
            if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
            error.code = internalError ? internalError.code : parsedErrorResponse.code;
            error.message = internalError ? internalError.message : parsedErrorResponse.message;
          }
          if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
            let resultMapper = new client.models['ErrorResponse']().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['OperationStatus']().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 Returns patterns to be retrieved for the specific intent.
   *
   * @param {uuid} appId The application ID.
   *
   * @param {string} versionId The version ID.
   *
   * @param {uuid} intentId The intent classifier ID.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {number} [options.skip] The number of entries to skip. Default value
   * is 0.
   *
   * @param {number} [options.take] The number of entries to return. Maximum page
   * size is 500. Default is 100.
   *
   * @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.
   *
   *                      {array} [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 _getIntentPatterns(appId, versionId, intentId, options, callback) {
     /* jshint validthis: true */
    let client = this.client;
    if(!callback && typeof options === 'function') {
      callback = options;
      options = null;
    }
    if (!callback) {
      throw new Error('callback cannot be null.');
    }
    let skip = (options && options.skip !== undefined) ? options.skip : 0;
    let take = (options && options.take !== undefined) ? options.take : 100;
    // Validate
    try {
      if (this.client.endpoint === null || this.client.endpoint === undefined || typeof this.client.endpoint.valueOf() !== 'string') {
        throw new Error('this.client.endpoint cannot be null or undefined and it must be of type string.');
      }
      if (appId === null || appId === undefined || typeof appId.valueOf() !== 'string' || !msRest.isValidUuid(appId)) {
        throw new Error('appId cannot be null or undefined and it must be of type string and must be a valid uuid.');
      }
      if (versionId === null || versionId === undefined || typeof versionId.valueOf() !== 'string') {
        throw new Error('versionId cannot be null or undefined and it must be of type string.');
      }
      if (intentId === null || intentId === undefined || typeof intentId.valueOf() !== 'string' || !msRest.isValidUuid(intentId)) {
        throw new Error('intentId cannot be null or undefined and it must be of type string and must be a valid uuid.');
      }
      if (skip !== null && skip !== undefined && typeof skip !== 'number') {
        throw new Error('skip must be of type number.');
      }
      if (skip !== null && skip !== undefined) {
        if (skip < 0)
        {
          throw new Error('"skip" should satisfy the constraint - "InclusiveMinimum": 0');
        }
      }
      if (take !== null && take !== undefined && typeof take !== 'number') {
        throw new Error('take must be of type number.');
      }
      if (take !== null && take !== undefined) {
        if (take > 500)
        {
          throw new Error('"take" should satisfy the constraint - "InclusiveMaximum": 500');
        }
        if (take < 0)
        {
          throw new Error('"take" should satisfy the constraint - "InclusiveMinimum": 0');
        }
      }
    } catch (error) {
      return callback(error);
    }
  
    // Construct URL
    let baseUrl = this.client.baseUri;
    let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'apps/{appId}/versions/{versionId}/intents/{intentId}/patternrules';
    requestUrl = requestUrl.replace('{Endpoint}', this.client.endpoint);
    requestUrl = requestUrl.replace('{appId}', encodeURIComponent(appId.toString()));
    requestUrl = requestUrl.replace('{versionId}', encodeURIComponent(versionId));
    requestUrl = requestUrl.replace('{intentId}', encodeURIComponent(intentId.toString()));
    let queryParameters = [];
    if (skip !== null && skip !== undefined) {
      queryParameters.push('skip=' + encodeURIComponent(skip.toString()));
    }
    if (take !== null && take !== undefined) {
      queryParameters.push('take=' + encodeURIComponent(take.toString()));
    }
    if (queryParameters.length > 0) {
      requestUrl += '?' + queryParameters.join('&');
    }
  
    // Create HTTP transport objects
    let httpRequest = new WebResource();
    httpRequest.method = 'GET';
    httpRequest.url = requestUrl;
    httpRequest.headers = {};
    // Set Headers
    httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
    if(options) {
      for(let headerName in options['customHeaders']) {
        if (options['customHeaders'].hasOwnProperty(headerName)) {
          httpRequest.headers[headerName] = options['customHeaders'][headerName];
        }
      }
    }
    httpRequest.body = null;
    // Send Request
    return client.pipeline(httpRequest, (err, response, responseBody) => {
      if (err) {
        return callback(err);
      }
      let statusCode = response.statusCode;
      if (statusCode !== 200) {
        let error = new Error(responseBody);
        error.statusCode = response.statusCode;
        error.request = msRest.stripRequest(httpRequest);
        error.response = msRest.stripResponse(response);
        if (responseBody === '') responseBody = null;
        let parsedErrorResponse;
        try {
          parsedErrorResponse = JSON.parse(responseBody);
          if (parsedErrorResponse) {
            let internalError = null;
            if (parsedErrorResponse.error) internalError = parsedErrorResponse.error;
            error.code = internalError ? internalError.code : parsedErrorResponse.code;
            error.message = internalError ? internalError.message : parsedErrorResponse.message;
          }
          if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
            let resultMapper = new client.models['ErrorResponse']().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 = {
              required: false,
              serializedName: 'parsedResponse',
              type: {
                name: 'Sequence',
                element: {
                    required: false,
                    serializedName: 'PatternRuleInfoElementType',
                    type: {
                      name: 'Composite',
                      className: 'PatternRuleInfo'
                    }
                }
              }
            };
            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 Pattern. */
  class Pattern {
    /**
     * Create a Pattern.
     * @param {LUISAuthoringClient} client Reference to the service client.
     */
    constructor(client) {
      this.client = client;
      this._addPattern = _addPattern;
      this._getPatterns = _getPatterns;
      this._updatePatterns = _updatePatterns;
      this._batchAddPatterns = _batchAddPatterns;
      this._deletePatterns = _deletePatterns;
      this._updatePattern = _updatePattern;
      this._deletePattern = _deletePattern;
      this._getIntentPatterns = _getIntentPatterns;
    }
  
    /**
     * @summary Adds one pattern to the specified application.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {object} pattern The input pattern.
     *
     * @param {string} [pattern.pattern] The pattern text.
     *
     * @param {string} [pattern.intent] The intent's name which the pattern belongs
     * to.
     *
     * @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<PatternRuleInfo>} - The deserialized result object.
     *
     * @reject {Error} - The error object.
     */
    addPatternWithHttpOperationResponse(appId, versionId, pattern, options) {
      let client = this.client;
      let self = this;
      return new Promise((resolve, reject) => {
        self._addPattern(appId, versionId, pattern, options, (err, result, request, response) => {
          let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
          httpOperationResponse.body = result;
          if (err) { reject(err); }
          else { resolve(httpOperationResponse); }
          return;
        });
      });
    }
  
    /**
     * @summary Adds one pattern to the specified application.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {object} pattern The input pattern.
     *
     * @param {string} [pattern.pattern] The pattern text.
     *
     * @param {string} [pattern.intent] The intent's name which the pattern belongs
     * to.
     *
     * @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 {PatternRuleInfo} - 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 PatternRuleInfo} 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.
     */
    addPattern(appId, versionId, pattern, 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._addPattern(appId, versionId, pattern, options, (err, result, request, response) => {
            if (err) { reject(err); }
            else { resolve(result); }
            return;
          });
        });
      } else {
        return self._addPattern(appId, versionId, pattern, options, optionalCallback);
      }
    }
  
    /**
     * @summary Returns an application version's patterns.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {object} [options] Optional Parameters.
     *
     * @param {number} [options.skip] The number of entries to skip. Default value
     * is 0.
     *
     * @param {number} [options.take] The number of entries to return. Maximum page
     * size is 500. Default is 100.
     *
     * @param {object} [options.customHeaders] Headers that will be added to the
     * request
     *
     * @returns {Promise} A promise is returned
     *
     * @resolve {HttpOperationResponse<Array>} - The deserialized result object.
     *
     * @reject {Error} - The error object.
     */
    getPatternsWithHttpOperationResponse(appId, versionId, options) {
      let client = this.client;
      let self = this;
      return new Promise((resolve, reject) => {
        self._getPatterns(appId, versionId, options, (err, result, request, response) => {
          let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
          httpOperationResponse.body = result;
          if (err) { reject(err); }
          else { resolve(httpOperationResponse); }
          return;
        });
      });
    }
  
    /**
     * @summary Returns an application version's patterns.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {object} [options] Optional Parameters.
     *
     * @param {number} [options.skip] The number of entries to skip. Default value
     * is 0.
     *
     * @param {number} [options.take] The number of entries to return. Maximum page
     * size is 500. Default is 100.
     *
     * @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 {Array} - 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.
     *
     *                      {array} [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.
     */
    getPatterns(appId, versionId, 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._getPatterns(appId, versionId, options, (err, result, request, response) => {
            if (err) { reject(err); }
            else { resolve(result); }
            return;
          });
        });
      } else {
        return self._getPatterns(appId, versionId, options, optionalCallback);
      }
    }
  
    /**
     * @summary Updates patterns
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {array} patterns An array represents the patterns.
     *
     * @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<Array>} - The deserialized result object.
     *
     * @reject {Error} - The error object.
     */
    updatePatternsWithHttpOperationResponse(appId, versionId, patterns, options) {
      let client = this.client;
      let self = this;
      return new Promise((resolve, reject) => {
        self._updatePatterns(appId, versionId, patterns, options, (err, result, request, response) => {
          let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
          httpOperationResponse.body = result;
          if (err) { reject(err); }
          else { resolve(httpOperationResponse); }
          return;
        });
      });
    }
  
    /**
     * @summary Updates patterns
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {array} patterns An array represents the patterns.
     *
     * @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 {Array} - 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.
     *
     *                      {array} [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.
     */
    updatePatterns(appId, versionId, patterns, 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._updatePatterns(appId, versionId, patterns, options, (err, result, request, response) => {
            if (err) { reject(err); }
            else { resolve(result); }
            return;
          });
        });
      } else {
        return self._updatePatterns(appId, versionId, patterns, options, optionalCallback);
      }
    }
  
    /**
     * @summary Adds a batch of patterns to the specified application.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {array} patterns A JSON array containing patterns.
     *
     * @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<Array>} - The deserialized result object.
     *
     * @reject {Error} - The error object.
     */
    batchAddPatternsWithHttpOperationResponse(appId, versionId, patterns, options) {
      let client = this.client;
      let self = this;
      return new Promise((resolve, reject) => {
        self._batchAddPatterns(appId, versionId, patterns, options, (err, result, request, response) => {
          let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
          httpOperationResponse.body = result;
          if (err) { reject(err); }
          else { resolve(httpOperationResponse); }
          return;
        });
      });
    }
  
    /**
     * @summary Adds a batch of patterns to the specified application.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {array} patterns A JSON array containing patterns.
     *
     * @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 {Array} - 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.
     *
     *                      {array} [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.
     */
    batchAddPatterns(appId, versionId, patterns, 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._batchAddPatterns(appId, versionId, patterns, options, (err, result, request, response) => {
            if (err) { reject(err); }
            else { resolve(result); }
            return;
          });
        });
      } else {
        return self._batchAddPatterns(appId, versionId, patterns, options, optionalCallback);
      }
    }
  
    /**
     * @summary Deletes the patterns with the specified IDs.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {array} patternIds The patterns IDs.
     *
     * @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<OperationStatus>} - The deserialized result object.
     *
     * @reject {Error} - The error object.
     */
    deletePatternsWithHttpOperationResponse(appId, versionId, patternIds, options) {
      let client = this.client;
      let self = this;
      return new Promise((resolve, reject) => {
        self._deletePatterns(appId, versionId, patternIds, options, (err, result, request, response) => {
          let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
          httpOperationResponse.body = result;
          if (err) { reject(err); }
          else { resolve(httpOperationResponse); }
          return;
        });
      });
    }
  
    /**
     * @summary Deletes the patterns with the specified IDs.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {array} patternIds The patterns IDs.
     *
     * @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 {OperationStatus} - 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 OperationStatus} 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.
     */
    deletePatterns(appId, versionId, patternIds, 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._deletePatterns(appId, versionId, patternIds, options, (err, result, request, response) => {
            if (err) { reject(err); }
            else { resolve(result); }
            return;
          });
        });
      } else {
        return self._deletePatterns(appId, versionId, patternIds, options, optionalCallback);
      }
    }
  
    /**
     * @summary Updates a pattern
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {uuid} patternId The pattern ID.
     *
     * @param {object} pattern An object representing a pattern.
     *
     * @param {uuid} [pattern.id] The pattern ID.
     *
     * @param {string} [pattern.pattern] The pattern text.
     *
     * @param {string} [pattern.intent] The intent's name which the pattern belongs
     * to.
     *
     * @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<PatternRuleInfo>} - The deserialized result object.
     *
     * @reject {Error} - The error object.
     */
    updatePatternWithHttpOperationResponse(appId, versionId, patternId, pattern, options) {
      let client = this.client;
      let self = this;
      return new Promise((resolve, reject) => {
        self._updatePattern(appId, versionId, patternId, pattern, options, (err, result, request, response) => {
          let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
          httpOperationResponse.body = result;
          if (err) { reject(err); }
          else { resolve(httpOperationResponse); }
          return;
        });
      });
    }
  
    /**
     * @summary Updates a pattern
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {uuid} patternId The pattern ID.
     *
     * @param {object} pattern An object representing a pattern.
     *
     * @param {uuid} [pattern.id] The pattern ID.
     *
     * @param {string} [pattern.pattern] The pattern text.
     *
     * @param {string} [pattern.intent] The intent's name which the pattern belongs
     * to.
     *
     * @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 {PatternRuleInfo} - 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 PatternRuleInfo} 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.
     */
    updatePattern(appId, versionId, patternId, pattern, 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._updatePattern(appId, versionId, patternId, pattern, options, (err, result, request, response) => {
            if (err) { reject(err); }
            else { resolve(result); }
            return;
          });
        });
      } else {
        return self._updatePattern(appId, versionId, patternId, pattern, options, optionalCallback);
      }
    }
  
    /**
     * @summary Deletes the pattern with the specified ID.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {uuid} patternId The pattern ID.
     *
     * @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<OperationStatus>} - The deserialized result object.
     *
     * @reject {Error} - The error object.
     */
    deletePatternWithHttpOperationResponse(appId, versionId, patternId, options) {
      let client = this.client;
      let self = this;
      return new Promise((resolve, reject) => {
        self._deletePattern(appId, versionId, patternId, options, (err, result, request, response) => {
          let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
          httpOperationResponse.body = result;
          if (err) { reject(err); }
          else { resolve(httpOperationResponse); }
          return;
        });
      });
    }
  
    /**
     * @summary Deletes the pattern with the specified ID.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {uuid} patternId The pattern ID.
     *
     * @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 {OperationStatus} - 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 OperationStatus} 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.
     */
    deletePattern(appId, versionId, patternId, 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._deletePattern(appId, versionId, patternId, options, (err, result, request, response) => {
            if (err) { reject(err); }
            else { resolve(result); }
            return;
          });
        });
      } else {
        return self._deletePattern(appId, versionId, patternId, options, optionalCallback);
      }
    }
  
    /**
     * @summary Returns patterns to be retrieved for the specific intent.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {uuid} intentId The intent classifier ID.
     *
     * @param {object} [options] Optional Parameters.
     *
     * @param {number} [options.skip] The number of entries to skip. Default value
     * is 0.
     *
     * @param {number} [options.take] The number of entries to return. Maximum page
     * size is 500. Default is 100.
     *
     * @param {object} [options.customHeaders] Headers that will be added to the
     * request
     *
     * @returns {Promise} A promise is returned
     *
     * @resolve {HttpOperationResponse<Array>} - The deserialized result object.
     *
     * @reject {Error} - The error object.
     */
    getIntentPatternsWithHttpOperationResponse(appId, versionId, intentId, options) {
      let client = this.client;
      let self = this;
      return new Promise((resolve, reject) => {
        self._getIntentPatterns(appId, versionId, intentId, options, (err, result, request, response) => {
          let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
          httpOperationResponse.body = result;
          if (err) { reject(err); }
          else { resolve(httpOperationResponse); }
          return;
        });
      });
    }
  
    /**
     * @summary Returns patterns to be retrieved for the specific intent.
     *
     * @param {uuid} appId The application ID.
     *
     * @param {string} versionId The version ID.
     *
     * @param {uuid} intentId The intent classifier ID.
     *
     * @param {object} [options] Optional Parameters.
     *
     * @param {number} [options.skip] The number of entries to skip. Default value
     * is 0.
     *
     * @param {number} [options.take] The number of entries to return. Maximum page
     * size is 500. Default is 100.
     *
     * @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 {Array} - 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.
     *
     *                      {array} [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.
     */
    getIntentPatterns(appId, versionId, intentId, 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._getIntentPatterns(appId, versionId, intentId, options, (err, result, request, response) => {
            if (err) { reject(err); }
            else { resolve(result); }
            return;
          });
        });
      } else {
        return self._getIntentPatterns(appId, versionId, intentId, options, optionalCallback);
      }
    }
  
  }
  
  module.exports = Pattern;
  