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

/**
 * Queries policy tracked resources under the management group.
 *
 * @param {string} managementGroupName Management group name.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.queryOptions] Additional parameters for the
 * operation
 *
 * @param {number} [options.queryOptions.top] Maximum number of records to
 * return.
 *
 * @param {string} [options.queryOptions.filter] OData filter expression.
 *
 * @param {string} [options.queryOptions.orderBy] Ordering expression using
 * OData notation. One or more comma-separated column names with an optional
 * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
 * asc".
 *
 * @param {string} [options.queryOptions.select] Select expression using OData
 * notation. Limits the columns on each record to just those requested, e.g.
 * "$select=PolicyAssignmentId, ResourceId".
 *
 * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
 * specifying the start time of the interval to query. When not specified, the
 * service uses ($to - 1-day).
 *
 * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
 * specifying the end time of the interval to query. When not specified, the
 * service uses request time.
 *
 * @param {string} [options.queryOptions.apply] OData apply expression for
 * aggregations.
 *
 * @param {string} [options.queryOptions.expand] The $expand query parameter.
 * For example, to expand policyEvaluationDetails, use
 * $expand=policyEvaluationDetails
 *
 * @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 PolicyTrackedResourcesQueryResults} 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 _listQueryResultsForManagementGroup(managementGroupName, 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 queryOptions = (options && options.queryOptions !== undefined) ? options.queryOptions : undefined;
  let managementGroupsNamespace = 'Microsoft.Management';
  let policyTrackedResourcesResource = 'default';
  let apiVersion = '2018-07-01-preview';
  // Validate
  try {
    if (managementGroupName === null || managementGroupName === undefined || typeof managementGroupName.valueOf() !== 'string') {
      throw new Error('managementGroupName 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);
  }
  let top;
  let filter;
  try {
    if (queryOptions !== null && queryOptions !== undefined) {
      top = queryOptions.top;
      if (top !== null && top !== undefined && typeof top !== 'number') {
        throw new Error('top must be of type number.');
      }
    }
    if (queryOptions !== null && queryOptions !== undefined) {
      filter = queryOptions.filter;
      if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
        throw new Error('filter must be of type string.');
      }
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'providers/{managementGroupsNamespace}/managementGroups/{managementGroupName}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults';
  requestUrl = requestUrl.replace('{managementGroupsNamespace}', encodeURIComponent(managementGroupsNamespace));
  requestUrl = requestUrl.replace('{managementGroupName}', encodeURIComponent(managementGroupName));
  requestUrl = requestUrl.replace('{policyTrackedResourcesResource}', encodeURIComponent(policyTrackedResourcesResource));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

/**
 * Queries policy tracked resources under the subscription.
 *
 * @param {string} subscriptionId Microsoft Azure subscription ID.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.queryOptions] Additional parameters for the
 * operation
 *
 * @param {number} [options.queryOptions.top] Maximum number of records to
 * return.
 *
 * @param {string} [options.queryOptions.filter] OData filter expression.
 *
 * @param {string} [options.queryOptions.orderBy] Ordering expression using
 * OData notation. One or more comma-separated column names with an optional
 * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
 * asc".
 *
 * @param {string} [options.queryOptions.select] Select expression using OData
 * notation. Limits the columns on each record to just those requested, e.g.
 * "$select=PolicyAssignmentId, ResourceId".
 *
 * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
 * specifying the start time of the interval to query. When not specified, the
 * service uses ($to - 1-day).
 *
 * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
 * specifying the end time of the interval to query. When not specified, the
 * service uses request time.
 *
 * @param {string} [options.queryOptions.apply] OData apply expression for
 * aggregations.
 *
 * @param {string} [options.queryOptions.expand] The $expand query parameter.
 * For example, to expand policyEvaluationDetails, use
 * $expand=policyEvaluationDetails
 *
 * @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 PolicyTrackedResourcesQueryResults} 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 _listQueryResultsForSubscription(subscriptionId, 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 queryOptions = (options && options.queryOptions !== undefined) ? options.queryOptions : undefined;
  let policyTrackedResourcesResource = 'default';
  let apiVersion = '2018-07-01-preview';
  // Validate
  try {
    if (subscriptionId === null || subscriptionId === undefined || typeof subscriptionId.valueOf() !== 'string') {
      throw new Error('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);
  }
  let top;
  let filter;
  try {
    if (queryOptions !== null && queryOptions !== undefined) {
      top = queryOptions.top;
      if (top !== null && top !== undefined && typeof top !== 'number') {
        throw new Error('top must be of type number.');
      }
    }
    if (queryOptions !== null && queryOptions !== undefined) {
      filter = queryOptions.filter;
      if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
        throw new Error('filter must be of type string.');
      }
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults';
  requestUrl = requestUrl.replace('{policyTrackedResourcesResource}', encodeURIComponent(policyTrackedResourcesResource));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

/**
 * Queries policy tracked resources under the resource group.
 *
 * @param {string} resourceGroupName Resource group name.
 *
 * @param {string} subscriptionId Microsoft Azure subscription ID.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.queryOptions] Additional parameters for the
 * operation
 *
 * @param {number} [options.queryOptions.top] Maximum number of records to
 * return.
 *
 * @param {string} [options.queryOptions.filter] OData filter expression.
 *
 * @param {string} [options.queryOptions.orderBy] Ordering expression using
 * OData notation. One or more comma-separated column names with an optional
 * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
 * asc".
 *
 * @param {string} [options.queryOptions.select] Select expression using OData
 * notation. Limits the columns on each record to just those requested, e.g.
 * "$select=PolicyAssignmentId, ResourceId".
 *
 * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
 * specifying the start time of the interval to query. When not specified, the
 * service uses ($to - 1-day).
 *
 * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
 * specifying the end time of the interval to query. When not specified, the
 * service uses request time.
 *
 * @param {string} [options.queryOptions.apply] OData apply expression for
 * aggregations.
 *
 * @param {string} [options.queryOptions.expand] The $expand query parameter.
 * For example, to expand policyEvaluationDetails, use
 * $expand=policyEvaluationDetails
 *
 * @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 PolicyTrackedResourcesQueryResults} 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 _listQueryResultsForResourceGroup(resourceGroupName, subscriptionId, 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 queryOptions = (options && options.queryOptions !== undefined) ? options.queryOptions : undefined;
  let policyTrackedResourcesResource = 'default';
  let apiVersion = '2018-07-01-preview';
  // 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 (subscriptionId === null || subscriptionId === undefined || typeof subscriptionId.valueOf() !== 'string') {
      throw new Error('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);
  }
  let top;
  let filter;
  try {
    if (queryOptions !== null && queryOptions !== undefined) {
      top = queryOptions.top;
      if (top !== null && top !== undefined && typeof top !== 'number') {
        throw new Error('top must be of type number.');
      }
    }
    if (queryOptions !== null && queryOptions !== undefined) {
      filter = queryOptions.filter;
      if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
        throw new Error('filter 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.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{policyTrackedResourcesResource}', encodeURIComponent(policyTrackedResourcesResource));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

/**
 * Queries policy tracked resources under the resource.
 *
 * @param {string} resourceId Resource ID.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.queryOptions] Additional parameters for the
 * operation
 *
 * @param {number} [options.queryOptions.top] Maximum number of records to
 * return.
 *
 * @param {string} [options.queryOptions.filter] OData filter expression.
 *
 * @param {string} [options.queryOptions.orderBy] Ordering expression using
 * OData notation. One or more comma-separated column names with an optional
 * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
 * asc".
 *
 * @param {string} [options.queryOptions.select] Select expression using OData
 * notation. Limits the columns on each record to just those requested, e.g.
 * "$select=PolicyAssignmentId, ResourceId".
 *
 * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
 * specifying the start time of the interval to query. When not specified, the
 * service uses ($to - 1-day).
 *
 * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
 * specifying the end time of the interval to query. When not specified, the
 * service uses request time.
 *
 * @param {string} [options.queryOptions.apply] OData apply expression for
 * aggregations.
 *
 * @param {string} [options.queryOptions.expand] The $expand query parameter.
 * For example, to expand policyEvaluationDetails, use
 * $expand=policyEvaluationDetails
 *
 * @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 PolicyTrackedResourcesQueryResults} 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 _listQueryResultsForResource(resourceId, 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 queryOptions = (options && options.queryOptions !== undefined) ? options.queryOptions : undefined;
  let policyTrackedResourcesResource = 'default';
  let apiVersion = '2018-07-01-preview';
  // Validate
  try {
    if (resourceId === null || resourceId === undefined || typeof resourceId.valueOf() !== 'string') {
      throw new Error('resourceId 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);
  }
  let top;
  let filter;
  try {
    if (queryOptions !== null && queryOptions !== undefined) {
      top = queryOptions.top;
      if (top !== null && top !== undefined && typeof top !== 'number') {
        throw new Error('top must be of type number.');
      }
    }
    if (queryOptions !== null && queryOptions !== undefined) {
      filter = queryOptions.filter;
      if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
        throw new Error('filter must be of type string.');
      }
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{resourceId}/providers/Microsoft.PolicyInsights/policyTrackedResources/{policyTrackedResourcesResource}/queryResults';
  requestUrl = requestUrl.replace('{resourceId}', resourceId);
  requestUrl = requestUrl.replace('{policyTrackedResourcesResource}', encodeURIComponent(policyTrackedResourcesResource));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (top !== null && top !== undefined) {
    queryParameters.push('$top=' + encodeURIComponent(top.toString()));
  }
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

/**
 * Queries policy tracked resources under the management group.
 *
 * @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 PolicyTrackedResourcesQueryResults} 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 _listQueryResultsForManagementGroupNext(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 = 'POST';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['QueryFailure']().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['PolicyTrackedResourcesQueryResults']().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);
  });
}

/**
 * Queries policy tracked resources under the subscription.
 *
 * @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 PolicyTrackedResourcesQueryResults} 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 _listQueryResultsForSubscriptionNext(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 = 'POST';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['QueryFailure']().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['PolicyTrackedResourcesQueryResults']().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);
  });
}

/**
 * Queries policy tracked resources under the resource group.
 *
 * @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 PolicyTrackedResourcesQueryResults} 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 _listQueryResultsForResourceGroupNext(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 = 'POST';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['QueryFailure']().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['PolicyTrackedResourcesQueryResults']().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);
  });
}

/**
 * Queries policy tracked resources under the resource.
 *
 * @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 PolicyTrackedResourcesQueryResults} 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 _listQueryResultsForResourceNext(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 = 'POST';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['QueryFailure']().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['PolicyTrackedResourcesQueryResults']().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 PolicyTrackedResources. */
class PolicyTrackedResources {
  /**
   * Create a PolicyTrackedResources.
   * @param {PolicyInsightsClient} client Reference to the service client.
   */
  constructor(client) {
    this.client = client;
    this._listQueryResultsForManagementGroup = _listQueryResultsForManagementGroup;
    this._listQueryResultsForSubscription = _listQueryResultsForSubscription;
    this._listQueryResultsForResourceGroup = _listQueryResultsForResourceGroup;
    this._listQueryResultsForResource = _listQueryResultsForResource;
    this._listQueryResultsForManagementGroupNext = _listQueryResultsForManagementGroupNext;
    this._listQueryResultsForSubscriptionNext = _listQueryResultsForSubscriptionNext;
    this._listQueryResultsForResourceGroupNext = _listQueryResultsForResourceGroupNext;
    this._listQueryResultsForResourceNext = _listQueryResultsForResourceNext;
  }

  /**
   * Queries policy tracked resources under the management group.
   *
   * @param {string} managementGroupName Management group name.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.queryOptions] Additional parameters for the
   * operation
   *
   * @param {number} [options.queryOptions.top] Maximum number of records to
   * return.
   *
   * @param {string} [options.queryOptions.filter] OData filter expression.
   *
   * @param {string} [options.queryOptions.orderBy] Ordering expression using
   * OData notation. One or more comma-separated column names with an optional
   * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
   * asc".
   *
   * @param {string} [options.queryOptions.select] Select expression using OData
   * notation. Limits the columns on each record to just those requested, e.g.
   * "$select=PolicyAssignmentId, ResourceId".
   *
   * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
   * specifying the start time of the interval to query. When not specified, the
   * service uses ($to - 1-day).
   *
   * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
   * specifying the end time of the interval to query. When not specified, the
   * service uses request time.
   *
   * @param {string} [options.queryOptions.apply] OData apply expression for
   * aggregations.
   *
   * @param {string} [options.queryOptions.expand] The $expand query parameter.
   * For example, to expand policyEvaluationDetails, use
   * $expand=policyEvaluationDetails
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<PolicyTrackedResourcesQueryResults>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listQueryResultsForManagementGroupWithHttpOperationResponse(managementGroupName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listQueryResultsForManagementGroup(managementGroupName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Queries policy tracked resources under the management group.
   *
   * @param {string} managementGroupName Management group name.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.queryOptions] Additional parameters for the
   * operation
   *
   * @param {number} [options.queryOptions.top] Maximum number of records to
   * return.
   *
   * @param {string} [options.queryOptions.filter] OData filter expression.
   *
   * @param {string} [options.queryOptions.orderBy] Ordering expression using
   * OData notation. One or more comma-separated column names with an optional
   * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
   * asc".
   *
   * @param {string} [options.queryOptions.select] Select expression using OData
   * notation. Limits the columns on each record to just those requested, e.g.
   * "$select=PolicyAssignmentId, ResourceId".
   *
   * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
   * specifying the start time of the interval to query. When not specified, the
   * service uses ($to - 1-day).
   *
   * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
   * specifying the end time of the interval to query. When not specified, the
   * service uses request time.
   *
   * @param {string} [options.queryOptions.apply] OData apply expression for
   * aggregations.
   *
   * @param {string} [options.queryOptions.expand] The $expand query parameter.
   * For example, to expand policyEvaluationDetails, use
   * $expand=policyEvaluationDetails
   *
   * @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 {PolicyTrackedResourcesQueryResults} - 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 PolicyTrackedResourcesQueryResults} 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.
   */
  listQueryResultsForManagementGroup(managementGroupName, 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._listQueryResultsForManagementGroup(managementGroupName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listQueryResultsForManagementGroup(managementGroupName, options, optionalCallback);
    }
  }

  /**
   * Queries policy tracked resources under the subscription.
   *
   * @param {string} subscriptionId Microsoft Azure subscription ID.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.queryOptions] Additional parameters for the
   * operation
   *
   * @param {number} [options.queryOptions.top] Maximum number of records to
   * return.
   *
   * @param {string} [options.queryOptions.filter] OData filter expression.
   *
   * @param {string} [options.queryOptions.orderBy] Ordering expression using
   * OData notation. One or more comma-separated column names with an optional
   * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
   * asc".
   *
   * @param {string} [options.queryOptions.select] Select expression using OData
   * notation. Limits the columns on each record to just those requested, e.g.
   * "$select=PolicyAssignmentId, ResourceId".
   *
   * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
   * specifying the start time of the interval to query. When not specified, the
   * service uses ($to - 1-day).
   *
   * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
   * specifying the end time of the interval to query. When not specified, the
   * service uses request time.
   *
   * @param {string} [options.queryOptions.apply] OData apply expression for
   * aggregations.
   *
   * @param {string} [options.queryOptions.expand] The $expand query parameter.
   * For example, to expand policyEvaluationDetails, use
   * $expand=policyEvaluationDetails
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<PolicyTrackedResourcesQueryResults>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listQueryResultsForSubscriptionWithHttpOperationResponse(subscriptionId, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listQueryResultsForSubscription(subscriptionId, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Queries policy tracked resources under the subscription.
   *
   * @param {string} subscriptionId Microsoft Azure subscription ID.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.queryOptions] Additional parameters for the
   * operation
   *
   * @param {number} [options.queryOptions.top] Maximum number of records to
   * return.
   *
   * @param {string} [options.queryOptions.filter] OData filter expression.
   *
   * @param {string} [options.queryOptions.orderBy] Ordering expression using
   * OData notation. One or more comma-separated column names with an optional
   * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
   * asc".
   *
   * @param {string} [options.queryOptions.select] Select expression using OData
   * notation. Limits the columns on each record to just those requested, e.g.
   * "$select=PolicyAssignmentId, ResourceId".
   *
   * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
   * specifying the start time of the interval to query. When not specified, the
   * service uses ($to - 1-day).
   *
   * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
   * specifying the end time of the interval to query. When not specified, the
   * service uses request time.
   *
   * @param {string} [options.queryOptions.apply] OData apply expression for
   * aggregations.
   *
   * @param {string} [options.queryOptions.expand] The $expand query parameter.
   * For example, to expand policyEvaluationDetails, use
   * $expand=policyEvaluationDetails
   *
   * @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 {PolicyTrackedResourcesQueryResults} - 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 PolicyTrackedResourcesQueryResults} 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.
   */
  listQueryResultsForSubscription(subscriptionId, 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._listQueryResultsForSubscription(subscriptionId, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listQueryResultsForSubscription(subscriptionId, options, optionalCallback);
    }
  }

  /**
   * Queries policy tracked resources under the resource group.
   *
   * @param {string} resourceGroupName Resource group name.
   *
   * @param {string} subscriptionId Microsoft Azure subscription ID.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.queryOptions] Additional parameters for the
   * operation
   *
   * @param {number} [options.queryOptions.top] Maximum number of records to
   * return.
   *
   * @param {string} [options.queryOptions.filter] OData filter expression.
   *
   * @param {string} [options.queryOptions.orderBy] Ordering expression using
   * OData notation. One or more comma-separated column names with an optional
   * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
   * asc".
   *
   * @param {string} [options.queryOptions.select] Select expression using OData
   * notation. Limits the columns on each record to just those requested, e.g.
   * "$select=PolicyAssignmentId, ResourceId".
   *
   * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
   * specifying the start time of the interval to query. When not specified, the
   * service uses ($to - 1-day).
   *
   * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
   * specifying the end time of the interval to query. When not specified, the
   * service uses request time.
   *
   * @param {string} [options.queryOptions.apply] OData apply expression for
   * aggregations.
   *
   * @param {string} [options.queryOptions.expand] The $expand query parameter.
   * For example, to expand policyEvaluationDetails, use
   * $expand=policyEvaluationDetails
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<PolicyTrackedResourcesQueryResults>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listQueryResultsForResourceGroupWithHttpOperationResponse(resourceGroupName, subscriptionId, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listQueryResultsForResourceGroup(resourceGroupName, subscriptionId, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Queries policy tracked resources under the resource group.
   *
   * @param {string} resourceGroupName Resource group name.
   *
   * @param {string} subscriptionId Microsoft Azure subscription ID.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.queryOptions] Additional parameters for the
   * operation
   *
   * @param {number} [options.queryOptions.top] Maximum number of records to
   * return.
   *
   * @param {string} [options.queryOptions.filter] OData filter expression.
   *
   * @param {string} [options.queryOptions.orderBy] Ordering expression using
   * OData notation. One or more comma-separated column names with an optional
   * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
   * asc".
   *
   * @param {string} [options.queryOptions.select] Select expression using OData
   * notation. Limits the columns on each record to just those requested, e.g.
   * "$select=PolicyAssignmentId, ResourceId".
   *
   * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
   * specifying the start time of the interval to query. When not specified, the
   * service uses ($to - 1-day).
   *
   * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
   * specifying the end time of the interval to query. When not specified, the
   * service uses request time.
   *
   * @param {string} [options.queryOptions.apply] OData apply expression for
   * aggregations.
   *
   * @param {string} [options.queryOptions.expand] The $expand query parameter.
   * For example, to expand policyEvaluationDetails, use
   * $expand=policyEvaluationDetails
   *
   * @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 {PolicyTrackedResourcesQueryResults} - 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 PolicyTrackedResourcesQueryResults} 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.
   */
  listQueryResultsForResourceGroup(resourceGroupName, subscriptionId, 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._listQueryResultsForResourceGroup(resourceGroupName, subscriptionId, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listQueryResultsForResourceGroup(resourceGroupName, subscriptionId, options, optionalCallback);
    }
  }

  /**
   * Queries policy tracked resources under the resource.
   *
   * @param {string} resourceId Resource ID.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.queryOptions] Additional parameters for the
   * operation
   *
   * @param {number} [options.queryOptions.top] Maximum number of records to
   * return.
   *
   * @param {string} [options.queryOptions.filter] OData filter expression.
   *
   * @param {string} [options.queryOptions.orderBy] Ordering expression using
   * OData notation. One or more comma-separated column names with an optional
   * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
   * asc".
   *
   * @param {string} [options.queryOptions.select] Select expression using OData
   * notation. Limits the columns on each record to just those requested, e.g.
   * "$select=PolicyAssignmentId, ResourceId".
   *
   * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
   * specifying the start time of the interval to query. When not specified, the
   * service uses ($to - 1-day).
   *
   * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
   * specifying the end time of the interval to query. When not specified, the
   * service uses request time.
   *
   * @param {string} [options.queryOptions.apply] OData apply expression for
   * aggregations.
   *
   * @param {string} [options.queryOptions.expand] The $expand query parameter.
   * For example, to expand policyEvaluationDetails, use
   * $expand=policyEvaluationDetails
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<PolicyTrackedResourcesQueryResults>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listQueryResultsForResourceWithHttpOperationResponse(resourceId, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listQueryResultsForResource(resourceId, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Queries policy tracked resources under the resource.
   *
   * @param {string} resourceId Resource ID.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.queryOptions] Additional parameters for the
   * operation
   *
   * @param {number} [options.queryOptions.top] Maximum number of records to
   * return.
   *
   * @param {string} [options.queryOptions.filter] OData filter expression.
   *
   * @param {string} [options.queryOptions.orderBy] Ordering expression using
   * OData notation. One or more comma-separated column names with an optional
   * "desc" (the default) or "asc", e.g. "$orderby=PolicyAssignmentId, ResourceId
   * asc".
   *
   * @param {string} [options.queryOptions.select] Select expression using OData
   * notation. Limits the columns on each record to just those requested, e.g.
   * "$select=PolicyAssignmentId, ResourceId".
   *
   * @param {date} [options.queryOptions.from] ISO 8601 formatted timestamp
   * specifying the start time of the interval to query. When not specified, the
   * service uses ($to - 1-day).
   *
   * @param {date} [options.queryOptions.to] ISO 8601 formatted timestamp
   * specifying the end time of the interval to query. When not specified, the
   * service uses request time.
   *
   * @param {string} [options.queryOptions.apply] OData apply expression for
   * aggregations.
   *
   * @param {string} [options.queryOptions.expand] The $expand query parameter.
   * For example, to expand policyEvaluationDetails, use
   * $expand=policyEvaluationDetails
   *
   * @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 {PolicyTrackedResourcesQueryResults} - 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 PolicyTrackedResourcesQueryResults} 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.
   */
  listQueryResultsForResource(resourceId, 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._listQueryResultsForResource(resourceId, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listQueryResultsForResource(resourceId, options, optionalCallback);
    }
  }

  /**
   * Queries policy tracked resources under the management group.
   *
   * @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<PolicyTrackedResourcesQueryResults>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listQueryResultsForManagementGroupNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listQueryResultsForManagementGroupNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Queries policy tracked resources under the management group.
   *
   * @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 {PolicyTrackedResourcesQueryResults} - 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 PolicyTrackedResourcesQueryResults} 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.
   */
  listQueryResultsForManagementGroupNext(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._listQueryResultsForManagementGroupNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listQueryResultsForManagementGroupNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * Queries policy tracked resources under the subscription.
   *
   * @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<PolicyTrackedResourcesQueryResults>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listQueryResultsForSubscriptionNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listQueryResultsForSubscriptionNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Queries policy tracked resources under the subscription.
   *
   * @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 {PolicyTrackedResourcesQueryResults} - 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 PolicyTrackedResourcesQueryResults} 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.
   */
  listQueryResultsForSubscriptionNext(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._listQueryResultsForSubscriptionNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listQueryResultsForSubscriptionNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * Queries policy tracked resources under the resource group.
   *
   * @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<PolicyTrackedResourcesQueryResults>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listQueryResultsForResourceGroupNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listQueryResultsForResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Queries policy tracked resources under the resource group.
   *
   * @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 {PolicyTrackedResourcesQueryResults} - 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 PolicyTrackedResourcesQueryResults} 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.
   */
  listQueryResultsForResourceGroupNext(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._listQueryResultsForResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listQueryResultsForResourceGroupNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * Queries policy tracked resources under the resource.
   *
   * @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<PolicyTrackedResourcesQueryResults>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listQueryResultsForResourceNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listQueryResultsForResourceNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Queries policy tracked resources under the resource.
   *
   * @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 {PolicyTrackedResourcesQueryResults} - 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 PolicyTrackedResourcesQueryResults} 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.
   */
  listQueryResultsForResourceNext(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._listQueryResultsForResourceNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listQueryResultsForResourceNext(nextPageLink, options, optionalCallback);
    }
  }

}

module.exports = PolicyTrackedResources;
