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

/**
 * @summary Deletes a policy assignment.
 *
 * This operation deletes a policy assignment, given its name and the scope it
 * was created in. The scope of a policy assignment is the part of its ID
 * preceding
 * '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
 *
 * @param {string} scope The scope of the policy assignment. Valid scopes are:
 * management group (format:
 * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
 * subscription (format: '/subscriptions/{subscriptionId}'), resource group
 * (format:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
 * resource (format:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
 *
 * @param {string} policyAssignmentName The name of the policy assignment to
 * delete.
 *
 * @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 PolicyAssignment} 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 _deleteMethod(scope, policyAssignmentName, 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 (scope === null || scope === undefined || typeof scope.valueOf() !== 'string') {
      throw new Error('scope cannot be null or undefined and it must be of type string.');
    }
    if (policyAssignmentName === null || policyAssignmentName === undefined || typeof policyAssignmentName.valueOf() !== 'string') {
      throw new Error('policyAssignmentName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}';
  requestUrl = requestUrl.replace('{scope}', scope);
  requestUrl = requestUrl.replace('{policyAssignmentName}', encodeURIComponent(policyAssignmentName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'DELETE';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200 && statusCode !== 204) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['PolicyAssignment']().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 Creates or updates a policy assignment.
 *
 * This operation creates or updates a policy assignment with the given scope
 * and name. Policy assignments apply to all resources contained within their
 * scope. For example, when you assign a policy at resource group scope, that
 * policy applies to all resources in the group.
 *
 * @param {string} scope The scope of the policy assignment. Valid scopes are:
 * management group (format:
 * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
 * subscription (format: '/subscriptions/{subscriptionId}'), resource group
 * (format:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
 * resource (format:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
 *
 * @param {string} policyAssignmentName The name of the policy assignment.
 *
 * @param {object} parameters Parameters for the policy assignment.
 *
 * @param {string} [parameters.displayName] The display name of the policy
 * assignment.
 *
 * @param {string} [parameters.policyDefinitionId] The ID of the policy
 * definition or policy set definition being assigned.
 *
 * @param {string} [parameters.scope] The scope for the policy assignment.
 *
 * @param {array} [parameters.notScopes] The policy's excluded scopes.
 *
 * @param {object} [parameters.parameters] Required if a parameter is used in
 * policy rule.
 *
 * @param {string} [parameters.description] This message will be part of
 * response in case of policy violation.
 *
 * @param {object} [parameters.metadata] The policy assignment metadata.
 *
 * @param {object} [parameters.sku] The policy sku. This property is optional,
 * obsolete, and will be ignored.
 *
 * @param {string} parameters.sku.name The name of the policy sku. Possible
 * values are A0 and A1.
 *
 * @param {string} [parameters.sku.tier] The policy sku tier. Possible values
 * are Free and Standard.
 *
 * @param {string} [parameters.location] The location of the policy assignment.
 * Only required when utilizing managed identity.
 *
 * @param {object} [parameters.identity] The managed identity associated with
 * the policy assignment.
 *
 * @param {string} [parameters.identity.type] The identity type. Possible
 * values include: 'SystemAssigned', 'None'
 *
 * @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 PolicyAssignment} 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 _create(scope, policyAssignmentName, parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (scope === null || scope === undefined || typeof scope.valueOf() !== 'string') {
      throw new Error('scope cannot be null or undefined and it must be of type string.');
    }
    if (policyAssignmentName === null || policyAssignmentName === undefined || typeof policyAssignmentName.valueOf() !== 'string') {
      throw new Error('policyAssignmentName cannot be null or undefined and it must be of type string.');
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}';
  requestUrl = requestUrl.replace('{scope}', scope);
  requestUrl = requestUrl.replace('{policyAssignmentName}', encodeURIComponent(policyAssignmentName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'PUT';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  // Serialize Request
  let requestContent = null;
  let requestModel = null;
  try {
    if (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['PolicyAssignment']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 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['PolicyAssignment']().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 Retrieves a policy assignment.
 *
 * This operation retrieves a single policy assignment, given its name and the
 * scope it was created at.
 *
 * @param {string} scope The scope of the policy assignment. Valid scopes are:
 * management group (format:
 * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
 * subscription (format: '/subscriptions/{subscriptionId}'), resource group
 * (format:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
 * resource (format:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
 *
 * @param {string} policyAssignmentName The name of the policy assignment to
 * get.
 *
 * @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 PolicyAssignment} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _get(scope, policyAssignmentName, 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 (scope === null || scope === undefined || typeof scope.valueOf() !== 'string') {
      throw new Error('scope cannot be null or undefined and it must be of type string.');
    }
    if (policyAssignmentName === null || policyAssignmentName === undefined || typeof policyAssignmentName.valueOf() !== 'string') {
      throw new Error('policyAssignmentName cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}';
  requestUrl = requestUrl.replace('{scope}', scope);
  requestUrl = requestUrl.replace('{policyAssignmentName}', encodeURIComponent(policyAssignmentName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['PolicyAssignment']().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 Retrieves all policy assignments that apply to a resource group.
 *
 * This operation retrieves the list of all policy assignments associated with
 * the given resource group in the given subscription that match the optional
 * given $filter. Valid values for $filter are: 'atScope()' or
 * 'policyDefinitionId eq '{value}''. If $filter is not provided, the
 * unfiltered list includes all policy assignments associated with the resource
 * group, including those that apply directly or apply from containing scopes,
 * as well as any applied to resources contained within the resource group. If
 * $filter=atScope() is provided, the returned list includes all policy
 * assignments that apply to the resource group, which is everything in the
 * unfiltered list except those applied to resources contained within the
 * resource group. If $filter=policyDefinitionId eq '{value}' is provided, the
 * returned list includes only policy assignments that apply to the resource
 * group and assign the policy definition whose id is {value}.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains policy assignments.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] The filter to apply on the operation. Valid
 * values for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
 * $filter is not provided, no filtering is performed.
 *
 * @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 PolicyAssignmentListResult} 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 _listForResourceGroup(resourceGroupName, 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 filter = (options && options.filter !== undefined) ? options.filter : undefined;
  // 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['PolicyAssignmentListResult']().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 Retrieves all policy assignments that apply to a resource.
 *
 * This operation retrieves the list of all policy assignments associated with
 * the specified resource in the given resource group and subscription that
 * match the optional given $filter. Valid values for $filter are: 'atScope()'
 * or 'policyDefinitionId eq '{value}''. If $filter is not provided, the
 * unfiltered list includes all policy assignments associated with the
 * resource, including those that apply directly or from all containing scopes,
 * as well as any applied to resources contained within the resource. If
 * $filter=atScope() is provided, the returned list includes all policy
 * assignments that apply to the resource, which is everything in the
 * unfiltered list except those applied to resources contained within the
 * resource. If $filter=policyDefinitionId eq '{value}' is provided, the
 * returned list includes only policy assignments that apply to the resource
 * and assign the policy definition whose id is {value}. Three parameters plus
 * the resource name are used to identify a specific resource. If the resource
 * is not part of a parent resource (the more common case), the parent resource
 * path should not be provided (or provided as ''). For example a web app could
 * be specified as ({resourceProviderNamespace} == 'Microsoft.Web',
 * {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} ==
 * 'MyWebApp'). If the resource is part of a parent resource, then all
 * parameters should be provided. For example a virtual machine DNS name could
 * be specified as ({resourceProviderNamespace} == 'Microsoft.Compute',
 * {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType}
 * == 'domainNames', {resourceName} == 'MyComputerName'). A convenient
 * alternative to providing the namespace and type name separately is to
 * provide both in the {resourceType} parameter, format:
 * ({resourceProviderNamespace} == '', {parentResourcePath} == '',
 * {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp').
 *
 * @param {string} resourceGroupName The name of the resource group containing
 * the resource.
 *
 * @param {string} resourceProviderNamespace The namespace of the resource
 * provider. For example, the namespace of a virtual machine is
 * Microsoft.Compute (from Microsoft.Compute/virtualMachines)
 *
 * @param {string} parentResourcePath The parent resource path. Use empty
 * string if there is none.
 *
 * @param {string} resourceType The resource type name. For example the type
 * name of a web app is 'sites' (from Microsoft.Web/sites).
 *
 * @param {string} resourceName The name of the resource.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] The filter to apply on the operation. Valid
 * values for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
 * $filter is not provided, no filtering is performed.
 *
 * @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 PolicyAssignmentListResult} 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 _listForResource(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, 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 filter = (options && options.filter !== undefined) ? options.filter : undefined;
  // 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 (resourceGroupName !== null && resourceGroupName !== undefined) {
      if (resourceGroupName.length > 90)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MaxLength": 90');
      }
      if (resourceGroupName.length < 1)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "MinLength": 1');
      }
      if (resourceGroupName.match(/^[-\w\._\(\)]+$/) === null)
      {
        throw new Error('"resourceGroupName" should satisfy the constraint - "Pattern": /^[-\w\._\(\)]+$/');
      }
    }
    if (resourceProviderNamespace === null || resourceProviderNamespace === undefined || typeof resourceProviderNamespace.valueOf() !== 'string') {
      throw new Error('resourceProviderNamespace cannot be null or undefined and it must be of type string.');
    }
    if (parentResourcePath === null || parentResourcePath === undefined || typeof parentResourcePath.valueOf() !== 'string') {
      throw new Error('parentResourcePath cannot be null or undefined and it must be of type string.');
    }
    if (resourceType === null || resourceType === undefined || typeof resourceType.valueOf() !== 'string') {
      throw new Error('resourceType cannot be null or undefined and it must be of type string.');
    }
    if (resourceName === null || resourceName === undefined || typeof resourceName.valueOf() !== 'string') {
      throw new Error('resourceName cannot be null or undefined and it must be of type string.');
    }
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + 'subscriptions/{subscriptionId}/resourcegroups/{resourceGroupName}/providers/{resourceProviderNamespace}/{parentResourcePath}/{resourceType}/{resourceName}/providers/Microsoft.Authorization/policyAssignments';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{resourceProviderNamespace}', encodeURIComponent(resourceProviderNamespace));
  requestUrl = requestUrl.replace('{parentResourcePath}', parentResourcePath);
  requestUrl = requestUrl.replace('{resourceType}', resourceType);
  requestUrl = requestUrl.replace('{resourceName}', encodeURIComponent(resourceName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  if (filter !== null && filter !== undefined) {
    queryParameters.push('$filter=' + encodeURIComponent(filter));
  }
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['PolicyAssignmentListResult']().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 Retrieves all policy assignments that apply to a subscription.
 *
 * This operation retrieves the list of all policy assignments associated with
 * the given subscription that match the optional given $filter. Valid values
 * for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
 * $filter is not provided, the unfiltered list includes all policy assignments
 * associated with the subscription, including those that apply directly or
 * from management groups that contain the given subscription, as well as any
 * applied to objects contained within the subscription. If $filter=atScope()
 * is provided, the returned list includes all policy assignments that apply to
 * the subscription, which is everything in the unfiltered list except those
 * applied to objects contained within the subscription. If
 * $filter=policyDefinitionId eq '{value}' is provided, the returned list
 * includes only policy assignments that apply to the subscription and assign
 * the policy definition whose id is {value}.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {string} [options.filter] The filter to apply on the operation. Valid
 * values for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
 * $filter is not provided, no filtering is performed.
 *
 * @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 PolicyAssignmentListResult} 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 _list(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 filter = (options && options.filter !== undefined) ? options.filter : undefined;
  // Validate
  try {
    if (filter !== null && filter !== undefined && typeof filter.valueOf() !== 'string') {
      throw new Error('filter must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.subscriptionId === null || this.client.subscriptionId === undefined || typeof this.client.subscriptionId.valueOf() !== 'string') {
      throw new Error('this.client.subscriptionId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['PolicyAssignmentListResult']().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 a policy assignment.
 *
 * This operation deletes the policy with the given ID. Policy assignment IDs
 * have this format:
 * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
 * Valid formats for {scope} are:
 * '/providers/Microsoft.Management/managementGroups/{managementGroup}'
 * (management group), '/subscriptions/{subscriptionId}' (subscription),
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}'
 * (resource group), or
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
 * (resource).
 *
 * @param {string} policyAssignmentId The ID of the policy assignment to
 * delete. Use the format
 * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
 *
 * @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 PolicyAssignment} 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 _deleteById(policyAssignmentId, 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 (policyAssignmentId === null || policyAssignmentId === undefined || typeof policyAssignmentId.valueOf() !== 'string') {
      throw new Error('policyAssignmentId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{policyAssignmentId}';
  requestUrl = requestUrl.replace('{policyAssignmentId}', policyAssignmentId);
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'DELETE';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200 && statusCode !== 204) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['PolicyAssignment']().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 Creates or updates a policy assignment.
 *
 * This operation creates or updates the policy assignment with the given ID.
 * Policy assignments made on a scope apply to all resources contained in that
 * scope. For example, when you assign a policy to a resource group that policy
 * applies to all resources in the group. Policy assignment IDs have this
 * format:
 * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
 * Valid scopes are: management group (format:
 * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
 * subscription (format: '/subscriptions/{subscriptionId}'), resource group
 * (format:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
 * resource (format:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'.
 *
 * @param {string} policyAssignmentId The ID of the policy assignment to
 * create. Use the format
 * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
 *
 * @param {object} parameters Parameters for policy assignment.
 *
 * @param {string} [parameters.displayName] The display name of the policy
 * assignment.
 *
 * @param {string} [parameters.policyDefinitionId] The ID of the policy
 * definition or policy set definition being assigned.
 *
 * @param {string} [parameters.scope] The scope for the policy assignment.
 *
 * @param {array} [parameters.notScopes] The policy's excluded scopes.
 *
 * @param {object} [parameters.parameters] Required if a parameter is used in
 * policy rule.
 *
 * @param {string} [parameters.description] This message will be part of
 * response in case of policy violation.
 *
 * @param {object} [parameters.metadata] The policy assignment metadata.
 *
 * @param {object} [parameters.sku] The policy sku. This property is optional,
 * obsolete, and will be ignored.
 *
 * @param {string} parameters.sku.name The name of the policy sku. Possible
 * values are A0 and A1.
 *
 * @param {string} [parameters.sku.tier] The policy sku tier. Possible values
 * are Free and Standard.
 *
 * @param {string} [parameters.location] The location of the policy assignment.
 * Only required when utilizing managed identity.
 *
 * @param {object} [parameters.identity] The managed identity associated with
 * the policy assignment.
 *
 * @param {string} [parameters.identity.type] The identity type. Possible
 * values include: 'SystemAssigned', 'None'
 *
 * @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 PolicyAssignment} 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 _createById(policyAssignmentId, parameters, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (policyAssignmentId === null || policyAssignmentId === undefined || typeof policyAssignmentId.valueOf() !== 'string') {
      throw new Error('policyAssignmentId cannot be null or undefined and it must be of type string.');
    }
    if (parameters === null || parameters === undefined) {
      throw new Error('parameters cannot be null or undefined.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{policyAssignmentId}';
  requestUrl = requestUrl.replace('{policyAssignmentId}', policyAssignmentId);
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'PUT';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  // Serialize Request
  let requestContent = null;
  let requestModel = null;
  try {
    if (parameters !== null && parameters !== undefined) {
      let requestModelMapper = new client.models['PolicyAssignment']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 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['PolicyAssignment']().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 Retrieves the policy assignment with the given ID.
 *
 * The operation retrieves the policy assignment with the given ID. Policy
 * assignment IDs have this format:
 * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
 * Valid scopes are: management group (format:
 * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
 * subscription (format: '/subscriptions/{subscriptionId}'), resource group
 * (format:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
 * resource (format:
 * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'.
 *
 * @param {string} policyAssignmentId The ID of the policy assignment to get.
 * Use the format
 * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
 *
 * @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 PolicyAssignment} 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 _getById(policyAssignmentId, 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 (policyAssignmentId === null || policyAssignmentId === undefined || typeof policyAssignmentId.valueOf() !== 'string') {
      throw new Error('policyAssignmentId cannot be null or undefined and it must be of type string.');
    }
    if (this.client.apiVersion === null || this.client.apiVersion === undefined || typeof this.client.apiVersion.valueOf() !== 'string') {
      throw new Error('this.client.apiVersion cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

  // Construct URL
  let baseUrl = this.client.baseUri;
  let requestUrl = baseUrl + (baseUrl.endsWith('/') ? '' : '/') + '{policyAssignmentId}';
  requestUrl = requestUrl.replace('{policyAssignmentId}', policyAssignmentId);
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(this.client.apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['PolicyAssignment']().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 Retrieves all policy assignments that apply to a resource group.
 *
 * This operation retrieves the list of all policy assignments associated with
 * the given resource group in the given subscription that match the optional
 * given $filter. Valid values for $filter are: 'atScope()' or
 * 'policyDefinitionId eq '{value}''. If $filter is not provided, the
 * unfiltered list includes all policy assignments associated with the resource
 * group, including those that apply directly or apply from containing scopes,
 * as well as any applied to resources contained within the resource group. If
 * $filter=atScope() is provided, the returned list includes all policy
 * assignments that apply to the resource group, which is everything in the
 * unfiltered list except those applied to resources contained within the
 * resource group. If $filter=policyDefinitionId eq '{value}' is provided, the
 * returned list includes only policy assignments that apply to the resource
 * group and assign the policy definition whose id is {value}.
 *
 * @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 PolicyAssignmentListResult} 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 _listForResourceGroupNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['PolicyAssignmentListResult']().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 Retrieves all policy assignments that apply to a resource.
 *
 * This operation retrieves the list of all policy assignments associated with
 * the specified resource in the given resource group and subscription that
 * match the optional given $filter. Valid values for $filter are: 'atScope()'
 * or 'policyDefinitionId eq '{value}''. If $filter is not provided, the
 * unfiltered list includes all policy assignments associated with the
 * resource, including those that apply directly or from all containing scopes,
 * as well as any applied to resources contained within the resource. If
 * $filter=atScope() is provided, the returned list includes all policy
 * assignments that apply to the resource, which is everything in the
 * unfiltered list except those applied to resources contained within the
 * resource. If $filter=policyDefinitionId eq '{value}' is provided, the
 * returned list includes only policy assignments that apply to the resource
 * and assign the policy definition whose id is {value}. Three parameters plus
 * the resource name are used to identify a specific resource. If the resource
 * is not part of a parent resource (the more common case), the parent resource
 * path should not be provided (or provided as ''). For example a web app could
 * be specified as ({resourceProviderNamespace} == 'Microsoft.Web',
 * {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} ==
 * 'MyWebApp'). If the resource is part of a parent resource, then all
 * parameters should be provided. For example a virtual machine DNS name could
 * be specified as ({resourceProviderNamespace} == 'Microsoft.Compute',
 * {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType}
 * == 'domainNames', {resourceName} == 'MyComputerName'). A convenient
 * alternative to providing the namespace and type name separately is to
 * provide both in the {resourceType} parameter, format:
 * ({resourceProviderNamespace} == '', {parentResourcePath} == '',
 * {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp').
 *
 * @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 PolicyAssignmentListResult} 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 _listForResourceNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['PolicyAssignmentListResult']().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 Retrieves all policy assignments that apply to a subscription.
 *
 * This operation retrieves the list of all policy assignments associated with
 * the given subscription that match the optional given $filter. Valid values
 * for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
 * $filter is not provided, the unfiltered list includes all policy assignments
 * associated with the subscription, including those that apply directly or
 * from management groups that contain the given subscription, as well as any
 * applied to objects contained within the subscription. If $filter=atScope()
 * is provided, the returned list includes all policy assignments that apply to
 * the subscription, which is everything in the unfiltered list except those
 * applied to objects contained within the subscription. If
 * $filter=policyDefinitionId eq '{value}' is provided, the returned list
 * includes only policy assignments that apply to the subscription and assign
 * the policy definition whose id is {value}.
 *
 * @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 PolicyAssignmentListResult} 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 _listNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          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['PolicyAssignmentListResult']().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 PolicyAssignments. */
class PolicyAssignments {
  /**
   * Create a PolicyAssignments.
   * @param {PolicyClient} client Reference to the service client.
   */
  constructor(client) {
    this.client = client;
    this._deleteMethod = _deleteMethod;
    this._create = _create;
    this._get = _get;
    this._listForResourceGroup = _listForResourceGroup;
    this._listForResource = _listForResource;
    this._list = _list;
    this._deleteById = _deleteById;
    this._createById = _createById;
    this._getById = _getById;
    this._listForResourceGroupNext = _listForResourceGroupNext;
    this._listForResourceNext = _listForResourceNext;
    this._listNext = _listNext;
  }

  /**
   * @summary Deletes a policy assignment.
   *
   * This operation deletes a policy assignment, given its name and the scope it
   * was created in. The scope of a policy assignment is the part of its ID
   * preceding
   * '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   *
   * @param {string} scope The scope of the policy assignment. Valid scopes are:
   * management group (format:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
   * subscription (format: '/subscriptions/{subscriptionId}'), resource group
   * (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
   * resource (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   *
   * @param {string} policyAssignmentName The name of the policy assignment to
   * delete.
   *
   * @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<PolicyAssignment>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  deleteMethodWithHttpOperationResponse(scope, policyAssignmentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._deleteMethod(scope, policyAssignmentName, 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 a policy assignment.
   *
   * This operation deletes a policy assignment, given its name and the scope it
   * was created in. The scope of a policy assignment is the part of its ID
   * preceding
   * '/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   *
   * @param {string} scope The scope of the policy assignment. Valid scopes are:
   * management group (format:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
   * subscription (format: '/subscriptions/{subscriptionId}'), resource group
   * (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
   * resource (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   *
   * @param {string} policyAssignmentName The name of the policy assignment to
   * delete.
   *
   * @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 {PolicyAssignment} - 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 PolicyAssignment} 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.
   */
  deleteMethod(scope, policyAssignmentName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._deleteMethod(scope, policyAssignmentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._deleteMethod(scope, policyAssignmentName, options, optionalCallback);
    }
  }

  /**
   * @summary Creates or updates a policy assignment.
   *
   * This operation creates or updates a policy assignment with the given scope
   * and name. Policy assignments apply to all resources contained within their
   * scope. For example, when you assign a policy at resource group scope, that
   * policy applies to all resources in the group.
   *
   * @param {string} scope The scope of the policy assignment. Valid scopes are:
   * management group (format:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
   * subscription (format: '/subscriptions/{subscriptionId}'), resource group
   * (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
   * resource (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   *
   * @param {string} policyAssignmentName The name of the policy assignment.
   *
   * @param {object} parameters Parameters for the policy assignment.
   *
   * @param {string} [parameters.displayName] The display name of the policy
   * assignment.
   *
   * @param {string} [parameters.policyDefinitionId] The ID of the policy
   * definition or policy set definition being assigned.
   *
   * @param {string} [parameters.scope] The scope for the policy assignment.
   *
   * @param {array} [parameters.notScopes] The policy's excluded scopes.
   *
   * @param {object} [parameters.parameters] Required if a parameter is used in
   * policy rule.
   *
   * @param {string} [parameters.description] This message will be part of
   * response in case of policy violation.
   *
   * @param {object} [parameters.metadata] The policy assignment metadata.
   *
   * @param {object} [parameters.sku] The policy sku. This property is optional,
   * obsolete, and will be ignored.
   *
   * @param {string} parameters.sku.name The name of the policy sku. Possible
   * values are A0 and A1.
   *
   * @param {string} [parameters.sku.tier] The policy sku tier. Possible values
   * are Free and Standard.
   *
   * @param {string} [parameters.location] The location of the policy assignment.
   * Only required when utilizing managed identity.
   *
   * @param {object} [parameters.identity] The managed identity associated with
   * the policy assignment.
   *
   * @param {string} [parameters.identity.type] The identity type. Possible
   * values include: 'SystemAssigned', 'None'
   *
   * @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<PolicyAssignment>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createWithHttpOperationResponse(scope, policyAssignmentName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._create(scope, policyAssignmentName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Creates or updates a policy assignment.
   *
   * This operation creates or updates a policy assignment with the given scope
   * and name. Policy assignments apply to all resources contained within their
   * scope. For example, when you assign a policy at resource group scope, that
   * policy applies to all resources in the group.
   *
   * @param {string} scope The scope of the policy assignment. Valid scopes are:
   * management group (format:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
   * subscription (format: '/subscriptions/{subscriptionId}'), resource group
   * (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
   * resource (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   *
   * @param {string} policyAssignmentName The name of the policy assignment.
   *
   * @param {object} parameters Parameters for the policy assignment.
   *
   * @param {string} [parameters.displayName] The display name of the policy
   * assignment.
   *
   * @param {string} [parameters.policyDefinitionId] The ID of the policy
   * definition or policy set definition being assigned.
   *
   * @param {string} [parameters.scope] The scope for the policy assignment.
   *
   * @param {array} [parameters.notScopes] The policy's excluded scopes.
   *
   * @param {object} [parameters.parameters] Required if a parameter is used in
   * policy rule.
   *
   * @param {string} [parameters.description] This message will be part of
   * response in case of policy violation.
   *
   * @param {object} [parameters.metadata] The policy assignment metadata.
   *
   * @param {object} [parameters.sku] The policy sku. This property is optional,
   * obsolete, and will be ignored.
   *
   * @param {string} parameters.sku.name The name of the policy sku. Possible
   * values are A0 and A1.
   *
   * @param {string} [parameters.sku.tier] The policy sku tier. Possible values
   * are Free and Standard.
   *
   * @param {string} [parameters.location] The location of the policy assignment.
   * Only required when utilizing managed identity.
   *
   * @param {object} [parameters.identity] The managed identity associated with
   * the policy assignment.
   *
   * @param {string} [parameters.identity.type] The identity type. Possible
   * values include: 'SystemAssigned', 'None'
   *
   * @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 {PolicyAssignment} - 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 PolicyAssignment} 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.
   */
  create(scope, policyAssignmentName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._create(scope, policyAssignmentName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._create(scope, policyAssignmentName, parameters, options, optionalCallback);
    }
  }

  /**
   * @summary Retrieves a policy assignment.
   *
   * This operation retrieves a single policy assignment, given its name and the
   * scope it was created at.
   *
   * @param {string} scope The scope of the policy assignment. Valid scopes are:
   * management group (format:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
   * subscription (format: '/subscriptions/{subscriptionId}'), resource group
   * (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
   * resource (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   *
   * @param {string} policyAssignmentName The name of the policy assignment to
   * get.
   *
   * @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<PolicyAssignment>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getWithHttpOperationResponse(scope, policyAssignmentName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._get(scope, policyAssignmentName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Retrieves a policy assignment.
   *
   * This operation retrieves a single policy assignment, given its name and the
   * scope it was created at.
   *
   * @param {string} scope The scope of the policy assignment. Valid scopes are:
   * management group (format:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
   * subscription (format: '/subscriptions/{subscriptionId}'), resource group
   * (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
   * resource (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   *
   * @param {string} policyAssignmentName The name of the policy assignment to
   * get.
   *
   * @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 {PolicyAssignment} - 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 PolicyAssignment} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  get(scope, policyAssignmentName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._get(scope, policyAssignmentName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._get(scope, policyAssignmentName, options, optionalCallback);
    }
  }

  /**
   * @summary Retrieves all policy assignments that apply to a resource group.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the given resource group in the given subscription that match the optional
   * given $filter. Valid values for $filter are: 'atScope()' or
   * 'policyDefinitionId eq '{value}''. If $filter is not provided, the
   * unfiltered list includes all policy assignments associated with the resource
   * group, including those that apply directly or apply from containing scopes,
   * as well as any applied to resources contained within the resource group. If
   * $filter=atScope() is provided, the returned list includes all policy
   * assignments that apply to the resource group, which is everything in the
   * unfiltered list except those applied to resources contained within the
   * resource group. If $filter=policyDefinitionId eq '{value}' is provided, the
   * returned list includes only policy assignments that apply to the resource
   * group and assign the policy definition whose id is {value}.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains policy assignments.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] The filter to apply on the operation. Valid
   * values for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
   * $filter is not provided, no filtering is performed.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<PolicyAssignmentListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listForResourceGroupWithHttpOperationResponse(resourceGroupName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listForResourceGroup(resourceGroupName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Retrieves all policy assignments that apply to a resource group.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the given resource group in the given subscription that match the optional
   * given $filter. Valid values for $filter are: 'atScope()' or
   * 'policyDefinitionId eq '{value}''. If $filter is not provided, the
   * unfiltered list includes all policy assignments associated with the resource
   * group, including those that apply directly or apply from containing scopes,
   * as well as any applied to resources contained within the resource group. If
   * $filter=atScope() is provided, the returned list includes all policy
   * assignments that apply to the resource group, which is everything in the
   * unfiltered list except those applied to resources contained within the
   * resource group. If $filter=policyDefinitionId eq '{value}' is provided, the
   * returned list includes only policy assignments that apply to the resource
   * group and assign the policy definition whose id is {value}.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains policy assignments.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] The filter to apply on the operation. Valid
   * values for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
   * $filter is not provided, no filtering is performed.
   *
   * @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 {PolicyAssignmentListResult} - 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 PolicyAssignmentListResult} 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.
   */
  listForResourceGroup(resourceGroupName, 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._listForResourceGroup(resourceGroupName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listForResourceGroup(resourceGroupName, options, optionalCallback);
    }
  }

  /**
   * @summary Retrieves all policy assignments that apply to a resource.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the specified resource in the given resource group and subscription that
   * match the optional given $filter. Valid values for $filter are: 'atScope()'
   * or 'policyDefinitionId eq '{value}''. If $filter is not provided, the
   * unfiltered list includes all policy assignments associated with the
   * resource, including those that apply directly or from all containing scopes,
   * as well as any applied to resources contained within the resource. If
   * $filter=atScope() is provided, the returned list includes all policy
   * assignments that apply to the resource, which is everything in the
   * unfiltered list except those applied to resources contained within the
   * resource. If $filter=policyDefinitionId eq '{value}' is provided, the
   * returned list includes only policy assignments that apply to the resource
   * and assign the policy definition whose id is {value}. Three parameters plus
   * the resource name are used to identify a specific resource. If the resource
   * is not part of a parent resource (the more common case), the parent resource
   * path should not be provided (or provided as ''). For example a web app could
   * be specified as ({resourceProviderNamespace} == 'Microsoft.Web',
   * {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} ==
   * 'MyWebApp'). If the resource is part of a parent resource, then all
   * parameters should be provided. For example a virtual machine DNS name could
   * be specified as ({resourceProviderNamespace} == 'Microsoft.Compute',
   * {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType}
   * == 'domainNames', {resourceName} == 'MyComputerName'). A convenient
   * alternative to providing the namespace and type name separately is to
   * provide both in the {resourceType} parameter, format:
   * ({resourceProviderNamespace} == '', {parentResourcePath} == '',
   * {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp').
   *
   * @param {string} resourceGroupName The name of the resource group containing
   * the resource.
   *
   * @param {string} resourceProviderNamespace The namespace of the resource
   * provider. For example, the namespace of a virtual machine is
   * Microsoft.Compute (from Microsoft.Compute/virtualMachines)
   *
   * @param {string} parentResourcePath The parent resource path. Use empty
   * string if there is none.
   *
   * @param {string} resourceType The resource type name. For example the type
   * name of a web app is 'sites' (from Microsoft.Web/sites).
   *
   * @param {string} resourceName The name of the resource.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] The filter to apply on the operation. Valid
   * values for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
   * $filter is not provided, no filtering is performed.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<PolicyAssignmentListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listForResourceWithHttpOperationResponse(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listForResource(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Retrieves all policy assignments that apply to a resource.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the specified resource in the given resource group and subscription that
   * match the optional given $filter. Valid values for $filter are: 'atScope()'
   * or 'policyDefinitionId eq '{value}''. If $filter is not provided, the
   * unfiltered list includes all policy assignments associated with the
   * resource, including those that apply directly or from all containing scopes,
   * as well as any applied to resources contained within the resource. If
   * $filter=atScope() is provided, the returned list includes all policy
   * assignments that apply to the resource, which is everything in the
   * unfiltered list except those applied to resources contained within the
   * resource. If $filter=policyDefinitionId eq '{value}' is provided, the
   * returned list includes only policy assignments that apply to the resource
   * and assign the policy definition whose id is {value}. Three parameters plus
   * the resource name are used to identify a specific resource. If the resource
   * is not part of a parent resource (the more common case), the parent resource
   * path should not be provided (or provided as ''). For example a web app could
   * be specified as ({resourceProviderNamespace} == 'Microsoft.Web',
   * {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} ==
   * 'MyWebApp'). If the resource is part of a parent resource, then all
   * parameters should be provided. For example a virtual machine DNS name could
   * be specified as ({resourceProviderNamespace} == 'Microsoft.Compute',
   * {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType}
   * == 'domainNames', {resourceName} == 'MyComputerName'). A convenient
   * alternative to providing the namespace and type name separately is to
   * provide both in the {resourceType} parameter, format:
   * ({resourceProviderNamespace} == '', {parentResourcePath} == '',
   * {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp').
   *
   * @param {string} resourceGroupName The name of the resource group containing
   * the resource.
   *
   * @param {string} resourceProviderNamespace The namespace of the resource
   * provider. For example, the namespace of a virtual machine is
   * Microsoft.Compute (from Microsoft.Compute/virtualMachines)
   *
   * @param {string} parentResourcePath The parent resource path. Use empty
   * string if there is none.
   *
   * @param {string} resourceType The resource type name. For example the type
   * name of a web app is 'sites' (from Microsoft.Web/sites).
   *
   * @param {string} resourceName The name of the resource.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] The filter to apply on the operation. Valid
   * values for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
   * $filter is not provided, no filtering is performed.
   *
   * @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 {PolicyAssignmentListResult} - 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 PolicyAssignmentListResult} 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.
   */
  listForResource(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, 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._listForResource(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listForResource(resourceGroupName, resourceProviderNamespace, parentResourcePath, resourceType, resourceName, options, optionalCallback);
    }
  }

  /**
   * @summary Retrieves all policy assignments that apply to a subscription.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the given subscription that match the optional given $filter. Valid values
   * for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
   * $filter is not provided, the unfiltered list includes all policy assignments
   * associated with the subscription, including those that apply directly or
   * from management groups that contain the given subscription, as well as any
   * applied to objects contained within the subscription. If $filter=atScope()
   * is provided, the returned list includes all policy assignments that apply to
   * the subscription, which is everything in the unfiltered list except those
   * applied to objects contained within the subscription. If
   * $filter=policyDefinitionId eq '{value}' is provided, the returned list
   * includes only policy assignments that apply to the subscription and assign
   * the policy definition whose id is {value}.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] The filter to apply on the operation. Valid
   * values for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
   * $filter is not provided, no filtering is performed.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<PolicyAssignmentListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listWithHttpOperationResponse(options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._list(options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Retrieves all policy assignments that apply to a subscription.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the given subscription that match the optional given $filter. Valid values
   * for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
   * $filter is not provided, the unfiltered list includes all policy assignments
   * associated with the subscription, including those that apply directly or
   * from management groups that contain the given subscription, as well as any
   * applied to objects contained within the subscription. If $filter=atScope()
   * is provided, the returned list includes all policy assignments that apply to
   * the subscription, which is everything in the unfiltered list except those
   * applied to objects contained within the subscription. If
   * $filter=policyDefinitionId eq '{value}' is provided, the returned list
   * includes only policy assignments that apply to the subscription and assign
   * the policy definition whose id is {value}.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {string} [options.filter] The filter to apply on the operation. Valid
   * values for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
   * $filter is not provided, no filtering is performed.
   *
   * @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 {PolicyAssignmentListResult} - 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 PolicyAssignmentListResult} 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.
   */
  list(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._list(options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._list(options, optionalCallback);
    }
  }

  /**
   * @summary Deletes a policy assignment.
   *
   * This operation deletes the policy with the given ID. Policy assignment IDs
   * have this format:
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   * Valid formats for {scope} are:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'
   * (management group), '/subscriptions/{subscriptionId}' (subscription),
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}'
   * (resource group), or
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   * (resource).
   *
   * @param {string} policyAssignmentId The ID of the policy assignment to
   * delete. Use the format
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   *
   * @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<PolicyAssignment>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  deleteByIdWithHttpOperationResponse(policyAssignmentId, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._deleteById(policyAssignmentId, 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 a policy assignment.
   *
   * This operation deletes the policy with the given ID. Policy assignment IDs
   * have this format:
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   * Valid formats for {scope} are:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'
   * (management group), '/subscriptions/{subscriptionId}' (subscription),
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}'
   * (resource group), or
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'
   * (resource).
   *
   * @param {string} policyAssignmentId The ID of the policy assignment to
   * delete. Use the format
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   *
   * @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 {PolicyAssignment} - 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 PolicyAssignment} 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.
   */
  deleteById(policyAssignmentId, 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._deleteById(policyAssignmentId, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._deleteById(policyAssignmentId, options, optionalCallback);
    }
  }

  /**
   * @summary Creates or updates a policy assignment.
   *
   * This operation creates or updates the policy assignment with the given ID.
   * Policy assignments made on a scope apply to all resources contained in that
   * scope. For example, when you assign a policy to a resource group that policy
   * applies to all resources in the group. Policy assignment IDs have this
   * format:
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   * Valid scopes are: management group (format:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
   * subscription (format: '/subscriptions/{subscriptionId}'), resource group
   * (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
   * resource (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'.
   *
   * @param {string} policyAssignmentId The ID of the policy assignment to
   * create. Use the format
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   *
   * @param {object} parameters Parameters for policy assignment.
   *
   * @param {string} [parameters.displayName] The display name of the policy
   * assignment.
   *
   * @param {string} [parameters.policyDefinitionId] The ID of the policy
   * definition or policy set definition being assigned.
   *
   * @param {string} [parameters.scope] The scope for the policy assignment.
   *
   * @param {array} [parameters.notScopes] The policy's excluded scopes.
   *
   * @param {object} [parameters.parameters] Required if a parameter is used in
   * policy rule.
   *
   * @param {string} [parameters.description] This message will be part of
   * response in case of policy violation.
   *
   * @param {object} [parameters.metadata] The policy assignment metadata.
   *
   * @param {object} [parameters.sku] The policy sku. This property is optional,
   * obsolete, and will be ignored.
   *
   * @param {string} parameters.sku.name The name of the policy sku. Possible
   * values are A0 and A1.
   *
   * @param {string} [parameters.sku.tier] The policy sku tier. Possible values
   * are Free and Standard.
   *
   * @param {string} [parameters.location] The location of the policy assignment.
   * Only required when utilizing managed identity.
   *
   * @param {object} [parameters.identity] The managed identity associated with
   * the policy assignment.
   *
   * @param {string} [parameters.identity.type] The identity type. Possible
   * values include: 'SystemAssigned', 'None'
   *
   * @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<PolicyAssignment>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createByIdWithHttpOperationResponse(policyAssignmentId, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._createById(policyAssignmentId, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Creates or updates a policy assignment.
   *
   * This operation creates or updates the policy assignment with the given ID.
   * Policy assignments made on a scope apply to all resources contained in that
   * scope. For example, when you assign a policy to a resource group that policy
   * applies to all resources in the group. Policy assignment IDs have this
   * format:
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   * Valid scopes are: management group (format:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
   * subscription (format: '/subscriptions/{subscriptionId}'), resource group
   * (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
   * resource (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'.
   *
   * @param {string} policyAssignmentId The ID of the policy assignment to
   * create. Use the format
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   *
   * @param {object} parameters Parameters for policy assignment.
   *
   * @param {string} [parameters.displayName] The display name of the policy
   * assignment.
   *
   * @param {string} [parameters.policyDefinitionId] The ID of the policy
   * definition or policy set definition being assigned.
   *
   * @param {string} [parameters.scope] The scope for the policy assignment.
   *
   * @param {array} [parameters.notScopes] The policy's excluded scopes.
   *
   * @param {object} [parameters.parameters] Required if a parameter is used in
   * policy rule.
   *
   * @param {string} [parameters.description] This message will be part of
   * response in case of policy violation.
   *
   * @param {object} [parameters.metadata] The policy assignment metadata.
   *
   * @param {object} [parameters.sku] The policy sku. This property is optional,
   * obsolete, and will be ignored.
   *
   * @param {string} parameters.sku.name The name of the policy sku. Possible
   * values are A0 and A1.
   *
   * @param {string} [parameters.sku.tier] The policy sku tier. Possible values
   * are Free and Standard.
   *
   * @param {string} [parameters.location] The location of the policy assignment.
   * Only required when utilizing managed identity.
   *
   * @param {object} [parameters.identity] The managed identity associated with
   * the policy assignment.
   *
   * @param {string} [parameters.identity.type] The identity type. Possible
   * values include: 'SystemAssigned', 'None'
   *
   * @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 {PolicyAssignment} - 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 PolicyAssignment} 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.
   */
  createById(policyAssignmentId, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._createById(policyAssignmentId, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._createById(policyAssignmentId, parameters, options, optionalCallback);
    }
  }

  /**
   * @summary Retrieves the policy assignment with the given ID.
   *
   * The operation retrieves the policy assignment with the given ID. Policy
   * assignment IDs have this format:
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   * Valid scopes are: management group (format:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
   * subscription (format: '/subscriptions/{subscriptionId}'), resource group
   * (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
   * resource (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'.
   *
   * @param {string} policyAssignmentId The ID of the policy assignment to get.
   * Use the format
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   *
   * @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<PolicyAssignment>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getByIdWithHttpOperationResponse(policyAssignmentId, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._getById(policyAssignmentId, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Retrieves the policy assignment with the given ID.
   *
   * The operation retrieves the policy assignment with the given ID. Policy
   * assignment IDs have this format:
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   * Valid scopes are: management group (format:
   * '/providers/Microsoft.Management/managementGroups/{managementGroup}'),
   * subscription (format: '/subscriptions/{subscriptionId}'), resource group
   * (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}', or
   * resource (format:
   * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{resourceProviderNamespace}/[{parentResourcePath}/]{resourceType}/{resourceName}'.
   *
   * @param {string} policyAssignmentId The ID of the policy assignment to get.
   * Use the format
   * '{scope}/providers/Microsoft.Authorization/policyAssignments/{policyAssignmentName}'.
   *
   * @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 {PolicyAssignment} - 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 PolicyAssignment} 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.
   */
  getById(policyAssignmentId, 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._getById(policyAssignmentId, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._getById(policyAssignmentId, options, optionalCallback);
    }
  }

  /**
   * @summary Retrieves all policy assignments that apply to a resource group.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the given resource group in the given subscription that match the optional
   * given $filter. Valid values for $filter are: 'atScope()' or
   * 'policyDefinitionId eq '{value}''. If $filter is not provided, the
   * unfiltered list includes all policy assignments associated with the resource
   * group, including those that apply directly or apply from containing scopes,
   * as well as any applied to resources contained within the resource group. If
   * $filter=atScope() is provided, the returned list includes all policy
   * assignments that apply to the resource group, which is everything in the
   * unfiltered list except those applied to resources contained within the
   * resource group. If $filter=policyDefinitionId eq '{value}' is provided, the
   * returned list includes only policy assignments that apply to the resource
   * group and assign the policy definition whose id is {value}.
   *
   * @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<PolicyAssignmentListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listForResourceGroupNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listForResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Retrieves all policy assignments that apply to a resource group.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the given resource group in the given subscription that match the optional
   * given $filter. Valid values for $filter are: 'atScope()' or
   * 'policyDefinitionId eq '{value}''. If $filter is not provided, the
   * unfiltered list includes all policy assignments associated with the resource
   * group, including those that apply directly or apply from containing scopes,
   * as well as any applied to resources contained within the resource group. If
   * $filter=atScope() is provided, the returned list includes all policy
   * assignments that apply to the resource group, which is everything in the
   * unfiltered list except those applied to resources contained within the
   * resource group. If $filter=policyDefinitionId eq '{value}' is provided, the
   * returned list includes only policy assignments that apply to the resource
   * group and assign the policy definition whose id is {value}.
   *
   * @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 {PolicyAssignmentListResult} - 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 PolicyAssignmentListResult} 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.
   */
  listForResourceGroupNext(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._listForResourceGroupNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listForResourceGroupNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * @summary Retrieves all policy assignments that apply to a resource.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the specified resource in the given resource group and subscription that
   * match the optional given $filter. Valid values for $filter are: 'atScope()'
   * or 'policyDefinitionId eq '{value}''. If $filter is not provided, the
   * unfiltered list includes all policy assignments associated with the
   * resource, including those that apply directly or from all containing scopes,
   * as well as any applied to resources contained within the resource. If
   * $filter=atScope() is provided, the returned list includes all policy
   * assignments that apply to the resource, which is everything in the
   * unfiltered list except those applied to resources contained within the
   * resource. If $filter=policyDefinitionId eq '{value}' is provided, the
   * returned list includes only policy assignments that apply to the resource
   * and assign the policy definition whose id is {value}. Three parameters plus
   * the resource name are used to identify a specific resource. If the resource
   * is not part of a parent resource (the more common case), the parent resource
   * path should not be provided (or provided as ''). For example a web app could
   * be specified as ({resourceProviderNamespace} == 'Microsoft.Web',
   * {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} ==
   * 'MyWebApp'). If the resource is part of a parent resource, then all
   * parameters should be provided. For example a virtual machine DNS name could
   * be specified as ({resourceProviderNamespace} == 'Microsoft.Compute',
   * {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType}
   * == 'domainNames', {resourceName} == 'MyComputerName'). A convenient
   * alternative to providing the namespace and type name separately is to
   * provide both in the {resourceType} parameter, format:
   * ({resourceProviderNamespace} == '', {parentResourcePath} == '',
   * {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp').
   *
   * @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<PolicyAssignmentListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listForResourceNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listForResourceNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Retrieves all policy assignments that apply to a resource.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the specified resource in the given resource group and subscription that
   * match the optional given $filter. Valid values for $filter are: 'atScope()'
   * or 'policyDefinitionId eq '{value}''. If $filter is not provided, the
   * unfiltered list includes all policy assignments associated with the
   * resource, including those that apply directly or from all containing scopes,
   * as well as any applied to resources contained within the resource. If
   * $filter=atScope() is provided, the returned list includes all policy
   * assignments that apply to the resource, which is everything in the
   * unfiltered list except those applied to resources contained within the
   * resource. If $filter=policyDefinitionId eq '{value}' is provided, the
   * returned list includes only policy assignments that apply to the resource
   * and assign the policy definition whose id is {value}. Three parameters plus
   * the resource name are used to identify a specific resource. If the resource
   * is not part of a parent resource (the more common case), the parent resource
   * path should not be provided (or provided as ''). For example a web app could
   * be specified as ({resourceProviderNamespace} == 'Microsoft.Web',
   * {parentResourcePath} == '', {resourceType} == 'sites', {resourceName} ==
   * 'MyWebApp'). If the resource is part of a parent resource, then all
   * parameters should be provided. For example a virtual machine DNS name could
   * be specified as ({resourceProviderNamespace} == 'Microsoft.Compute',
   * {parentResourcePath} == 'virtualMachines/MyVirtualMachine', {resourceType}
   * == 'domainNames', {resourceName} == 'MyComputerName'). A convenient
   * alternative to providing the namespace and type name separately is to
   * provide both in the {resourceType} parameter, format:
   * ({resourceProviderNamespace} == '', {parentResourcePath} == '',
   * {resourceType} == 'Microsoft.Web/sites', {resourceName} == 'MyWebApp').
   *
   * @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 {PolicyAssignmentListResult} - 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 PolicyAssignmentListResult} 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.
   */
  listForResourceNext(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._listForResourceNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listForResourceNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * @summary Retrieves all policy assignments that apply to a subscription.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the given subscription that match the optional given $filter. Valid values
   * for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
   * $filter is not provided, the unfiltered list includes all policy assignments
   * associated with the subscription, including those that apply directly or
   * from management groups that contain the given subscription, as well as any
   * applied to objects contained within the subscription. If $filter=atScope()
   * is provided, the returned list includes all policy assignments that apply to
   * the subscription, which is everything in the unfiltered list except those
   * applied to objects contained within the subscription. If
   * $filter=policyDefinitionId eq '{value}' is provided, the returned list
   * includes only policy assignments that apply to the subscription and assign
   * the policy definition whose id is {value}.
   *
   * @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<PolicyAssignmentListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * @summary Retrieves all policy assignments that apply to a subscription.
   *
   * This operation retrieves the list of all policy assignments associated with
   * the given subscription that match the optional given $filter. Valid values
   * for $filter are: 'atScope()' or 'policyDefinitionId eq '{value}''. If
   * $filter is not provided, the unfiltered list includes all policy assignments
   * associated with the subscription, including those that apply directly or
   * from management groups that contain the given subscription, as well as any
   * applied to objects contained within the subscription. If $filter=atScope()
   * is provided, the returned list includes all policy assignments that apply to
   * the subscription, which is everything in the unfiltered list except those
   * applied to objects contained within the subscription. If
   * $filter=policyDefinitionId eq '{value}' is provided, the returned list
   * includes only policy assignments that apply to the subscription and assign
   * the policy definition whose id is {value}.
   *
   * @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 {PolicyAssignmentListResult} - 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 PolicyAssignmentListResult} 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.
   */
  listNext(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._listNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listNext(nextPageLink, options, optionalCallback);
    }
  }

}

module.exports = PolicyAssignments;
