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


/**
 * Imports a bacpac into a new database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {object} parameters The required parameters for importing a Bacpac
 * into a database.
 *
 * @param {string} parameters.databaseName The name of the database to import.
 *
 * @param {string} parameters.edition The edition for the database being
 * created. Possible values include: 'Web', 'Business', 'Basic', 'Standard',
 * 'Premium', 'PremiumRS', 'Free', 'Stretch', 'DataWarehouse', 'System',
 * 'System2'
 *
 * @param {string} parameters.serviceObjectiveName The name of the service
 * objective to assign to the database. Possible values include: 'System',
 * 'System0', 'System1', 'System2', 'System3', 'System4', 'System2L',
 * 'System3L', 'System4L', 'Free', 'Basic', 'S0', 'S1', 'S2', 'S3', 'S4', 'S6',
 * 'S7', 'S9', 'S12', 'P1', 'P2', 'P3', 'P4', 'P6', 'P11', 'P15', 'PRS1',
 * 'PRS2', 'PRS4', 'PRS6', 'DW100', 'DW200', 'DW300', 'DW400', 'DW500',
 * 'DW600', 'DW1000', 'DW1200', 'DW1000c', 'DW1500', 'DW1500c', 'DW2000',
 * 'DW2000c', 'DW3000', 'DW2500c', 'DW3000c', 'DW6000', 'DW5000c', 'DW6000c',
 * 'DW7500c', 'DW10000c', 'DW15000c', 'DW30000c', 'DS100', 'DS200', 'DS300',
 * 'DS400', 'DS500', 'DS600', 'DS1000', 'DS1200', 'DS1500', 'DS2000',
 * 'ElasticPool'
 *
 * @param {string} parameters.maxSizeBytes The maximum size for the newly
 * imported database.
 *
 * @param {string} parameters.storageKeyType The type of the storage key to
 * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
 *
 * @param {string} parameters.storageKey The storage key to use.  If storage
 * key type is SharedAccessKey, it must be preceded with a "?."
 *
 * @param {string} parameters.storageUri The storage uri to use.
 *
 * @param {string} parameters.administratorLogin The name of the SQL
 * administrator.
 *
 * @param {string} parameters.administratorLoginPassword The password of the
 * SQL administrator.
 *
 * @param {string} [parameters.authenticationType] The authentication type.
 * Possible values include: 'SQL', 'ADPassword'
 *
 * @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 ImportExportResponse} 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 _importMethod(resourceGroupName, serverName, 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.');
  }

  // Send request
  this.beginImportMethod(resourceGroupName, serverName, parameters, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['ImportExportResponse']().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);
    });
  });
}


/**
 * Creates an import operation that imports a bacpac into an existing database.
 * The existing database must be empty.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database to import into
 *
 * @param {object} parameters The required parameters for importing a Bacpac
 * into a database.
 *
 * @param {string} [parameters.name] The name of the extension.
 *
 * @param {string} [parameters.type] The type of the extension.
 *
 * @param {string} parameters.storageKeyType The type of the storage key to
 * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
 *
 * @param {string} parameters.storageKey The storage key to use.  If storage
 * key type is SharedAccessKey, it must be preceded with a "?."
 *
 * @param {string} parameters.storageUri The storage uri to use.
 *
 * @param {string} parameters.administratorLogin The name of the SQL
 * administrator.
 *
 * @param {string} parameters.administratorLoginPassword The password of the
 * SQL administrator.
 *
 * @param {string} [parameters.authenticationType] The authentication type.
 * Possible values include: 'SQL', 'ADPassword'
 *
 * @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 ImportExportResponse} 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 _createImportOperation(resourceGroupName, serverName, databaseName, 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.');
  }

  // Send request
  this.beginCreateImportOperation(resourceGroupName, serverName, databaseName, parameters, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['ImportExportResponse']().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);
    });
  });
}


/**
 * Exports a database to a bacpac.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database to be exported.
 *
 * @param {object} parameters The required parameters for exporting a database.
 *
 * @param {string} parameters.storageKeyType The type of the storage key to
 * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
 *
 * @param {string} parameters.storageKey The storage key to use.  If storage
 * key type is SharedAccessKey, it must be preceded with a "?."
 *
 * @param {string} parameters.storageUri The storage uri to use.
 *
 * @param {string} parameters.administratorLogin The name of the SQL
 * administrator.
 *
 * @param {string} parameters.administratorLoginPassword The password of the
 * SQL administrator.
 *
 * @param {string} [parameters.authenticationType] The authentication type.
 * Possible values include: 'SQL', 'ADPassword'
 *
 * @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 ImportExportResponse} 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 _exportMethod(resourceGroupName, serverName, databaseName, 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.');
  }

  // Send request
  this.beginExportMethod(resourceGroupName, serverName, databaseName, parameters, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['ImportExportResponse']().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);
    });
  });
}

/**
 * Returns database metrics.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database.
 *
 * @param {string} filter An OData filter expression that describes a subset of
 * metrics to return.
 *
 * @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 MetricListResult} 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 _listMetrics(resourceGroupName, serverName, databaseName, filter, 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 apiVersion = '2014-04-01';
  // Validate
  try {
    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 (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 (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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 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.Sql/servers/{serverName}/databases/{databaseName}/metrics';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  queryParameters.push('$filter=' + encodeURIComponent(filter));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

/**
 * Returns database metric definitions.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database.
 *
 * @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 MetricDefinitionListResult} 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 _listMetricDefinitions(resourceGroupName, serverName, databaseName, 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 apiVersion = '2014-04-01';
  // Validate
  try {
    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 (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 (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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.Sql/servers/{serverName}/databases/{databaseName}/metricDefinitions';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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


/**
 * Upgrades a data warehouse.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database to be upgraded.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _upgradeDataWarehouse(resourceGroupName, serverName, databaseName, 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.');
  }

  // Send request
  this.beginUpgradeDataWarehouse(resourceGroupName, serverName, databaseName, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response

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

/**
 * Gets a list of databases.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @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 DatabaseListResult} 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 _listByServer(resourceGroupName, serverName, 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 apiVersion = '2017-10-01-preview';
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName 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.Sql/servers/{serverName}/databases';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

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

/**
 * Gets a database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database.
 *
 * @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 Database} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _get(resourceGroupName, serverName, databaseName, 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 apiVersion = '2017-10-01-preview';
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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.Sql/servers/{serverName}/databases/{databaseName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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


/**
 * Creates a new database or updates an existing database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database.
 *
 * @param {object} parameters The requested database resource state.
 *
 * @param {object} [parameters.sku] The name and tier of the SKU.
 *
 * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
 * typically a letter+number code
 *
 * @param {string} [parameters.sku.tier] This field is required to be
 * implemented by the Resource Provider if the service has more than one tier,
 * but is not required on a PUT.
 *
 * @param {string} [parameters.sku.size] The SKU size. When the name field is
 * the combination of tier and some other value, this would be the standalone
 * code.
 *
 * @param {string} [parameters.sku.family] If the service has different
 * generations of hardware, for the same SKU, then that can be captured here.
 *
 * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
 * then the capacity integer should be included. If scale out/in is not
 * possible for the resource this may be omitted.
 *
 * @param {string} [parameters.createMode] Specifies the mode of database
 * creation.
 *
 * Default: regular database creation.
 *
 * Copy: creates a database as a copy of an existing database. sourceDatabaseId
 * must be specified as the resource ID of the source database.
 *
 * Secondary: creates a database as a secondary replica of an existing
 * database. sourceDatabaseId must be specified as the resource ID of the
 * existing primary database.
 *
 * PointInTimeRestore: Creates a database by restoring a point in time backup
 * of an existing database. sourceDatabaseId must be specified as the resource
 * ID of the existing database, and restorePointInTime must be specified.
 *
 * Recovery: Creates a database by restoring a geo-replicated backup.
 * sourceDatabaseId must be specified as the recoverable database resource ID
 * to restore.
 *
 * Restore: Creates a database by restoring a backup of a deleted database.
 * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
 * original resource ID, then sourceDatabaseDeletionDate must be specified.
 * Otherwise sourceDatabaseId must be the restorable dropped database resource
 * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
 * specified to restore from an earlier point in time.
 *
 * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
 * term retention vault. recoveryServicesRecoveryPointResourceId must be
 * specified as the recovery point resource ID.
 *
 * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
 * DataWarehouse edition. Possible values include: 'Default', 'Copy',
 * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
 * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
 * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
 *
 * @param {string} [parameters.collation] The collation of the database.
 *
 * @param {number} [parameters.maxSizeBytes] The max size of the database
 * expressed in bytes.
 *
 * @param {string} [parameters.sampleName] The name of the sample schema to
 * apply when creating this database. Possible values include:
 * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
 *
 * @param {string} [parameters.elasticPoolId] The resource identifier of the
 * elastic pool containing this database.
 *
 * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
 * source database associated with create operation of this database.
 *
 * @param {date} [parameters.restorePointInTime] Specifies the point in time
 * (ISO8601 format) of the source database that will be restored to create the
 * new database.
 *
 * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
 * that the database was deleted.
 *
 * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
 * identifier of the recovery point associated with create operation of this
 * database.
 *
 * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
 * identifier of the long term retention backup associated with create
 * operation of this database.
 *
 * @param {string} [parameters.recoverableDatabaseId] The resource identifier
 * of the recoverable database associated with create operation of this
 * database.
 *
 * @param {string} [parameters.restorableDroppedDatabaseId] The resource
 * identifier of the restorable dropped database associated with create
 * operation of this database.
 *
 * @param {string} [parameters.catalogCollation] Collation of the metadata
 * catalog. Possible values include: 'DATABASE_DEFAULT',
 * 'SQL_Latin1_General_CP1_CI_AS'
 *
 * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
 * zone redundant, which means the replicas of this database will be spread
 * across multiple availability zones.
 *
 * @param {string} [parameters.licenseType] The license type to apply for this
 * database. Possible values include: 'LicenseIncluded', 'BasePrice'
 *
 * @param {string} [parameters.readScale] The state of read-only routing. If
 * enabled, connections that have application intent set to readonly in their
 * connection string may be routed to a readonly secondary replica in the same
 * region. Possible values include: 'Enabled', 'Disabled'
 *
 * @param {string} parameters.location Resource location.
 *
 * @param {object} [parameters.tags] Resource tags.
 *
 * @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 Database} for more information.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _createOrUpdate(resourceGroupName, serverName, databaseName, 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.');
  }

  // Send request
  this.beginCreateOrUpdate(resourceGroupName, serverName, databaseName, parameters, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Database']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }

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


/**
 * Deletes the database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _deleteMethod(resourceGroupName, serverName, databaseName, 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.');
  }

  // Send request
  this.beginDeleteMethod(resourceGroupName, serverName, databaseName, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response

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


/**
 * Updates an existing database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database.
 *
 * @param {object} parameters The requested database resource state.
 *
 * @param {object} [parameters.sku] The name and tier of the SKU.
 *
 * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
 * typically a letter+number code
 *
 * @param {string} [parameters.sku.tier] This field is required to be
 * implemented by the Resource Provider if the service has more than one tier,
 * but is not required on a PUT.
 *
 * @param {string} [parameters.sku.size] The SKU size. When the name field is
 * the combination of tier and some other value, this would be the standalone
 * code.
 *
 * @param {string} [parameters.sku.family] If the service has different
 * generations of hardware, for the same SKU, then that can be captured here.
 *
 * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
 * then the capacity integer should be included. If scale out/in is not
 * possible for the resource this may be omitted.
 *
 * @param {string} [parameters.createMode] Specifies the mode of database
 * creation.
 *
 * Default: regular database creation.
 *
 * Copy: creates a database as a copy of an existing database. sourceDatabaseId
 * must be specified as the resource ID of the source database.
 *
 * Secondary: creates a database as a secondary replica of an existing
 * database. sourceDatabaseId must be specified as the resource ID of the
 * existing primary database.
 *
 * PointInTimeRestore: Creates a database by restoring a point in time backup
 * of an existing database. sourceDatabaseId must be specified as the resource
 * ID of the existing database, and restorePointInTime must be specified.
 *
 * Recovery: Creates a database by restoring a geo-replicated backup.
 * sourceDatabaseId must be specified as the recoverable database resource ID
 * to restore.
 *
 * Restore: Creates a database by restoring a backup of a deleted database.
 * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
 * original resource ID, then sourceDatabaseDeletionDate must be specified.
 * Otherwise sourceDatabaseId must be the restorable dropped database resource
 * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
 * specified to restore from an earlier point in time.
 *
 * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
 * term retention vault. recoveryServicesRecoveryPointResourceId must be
 * specified as the recovery point resource ID.
 *
 * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
 * DataWarehouse edition. Possible values include: 'Default', 'Copy',
 * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
 * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
 * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
 *
 * @param {string} [parameters.collation] The collation of the database.
 *
 * @param {number} [parameters.maxSizeBytes] The max size of the database
 * expressed in bytes.
 *
 * @param {string} [parameters.sampleName] The name of the sample schema to
 * apply when creating this database. Possible values include:
 * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
 *
 * @param {string} [parameters.elasticPoolId] The resource identifier of the
 * elastic pool containing this database.
 *
 * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
 * source database associated with create operation of this database.
 *
 * @param {date} [parameters.restorePointInTime] Specifies the point in time
 * (ISO8601 format) of the source database that will be restored to create the
 * new database.
 *
 * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
 * that the database was deleted.
 *
 * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
 * identifier of the recovery point associated with create operation of this
 * database.
 *
 * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
 * identifier of the long term retention backup associated with create
 * operation of this database.
 *
 * @param {string} [parameters.recoverableDatabaseId] The resource identifier
 * of the recoverable database associated with create operation of this
 * database.
 *
 * @param {string} [parameters.restorableDroppedDatabaseId] The resource
 * identifier of the restorable dropped database associated with create
 * operation of this database.
 *
 * @param {string} [parameters.catalogCollation] Collation of the metadata
 * catalog. Possible values include: 'DATABASE_DEFAULT',
 * 'SQL_Latin1_General_CP1_CI_AS'
 *
 * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
 * zone redundant, which means the replicas of this database will be spread
 * across multiple availability zones.
 *
 * @param {string} [parameters.licenseType] The license type to apply for this
 * database. Possible values include: 'LicenseIncluded', 'BasePrice'
 *
 * @param {string} [parameters.readScale] The state of read-only routing. If
 * enabled, connections that have application intent set to readonly in their
 * connection string may be routed to a readonly secondary replica in the same
 * region. Possible values include: 'Enabled', 'Disabled'
 *
 * @param {object} [parameters.tags] Resource tags.
 *
 * @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 Database} 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 _update(resourceGroupName, serverName, databaseName, 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.');
  }

  // Send request
  this.beginUpdate(resourceGroupName, serverName, databaseName, parameters, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Database']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }

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

/**
 * Gets a list of databases in an elastic pool.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} elasticPoolName The name of the elastic pool.
 *
 * @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 DatabaseListResult} 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 _listByElasticPool(resourceGroupName, serverName, elasticPoolName, 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 apiVersion = '2017-10-01-preview';
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (elasticPoolName === null || elasticPoolName === undefined || typeof elasticPoolName.valueOf() !== 'string') {
      throw new Error('elasticPoolName 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.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/databases';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{elasticPoolName}', encodeURIComponent(elasticPoolName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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


/**
 * Pauses a database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database to be paused.
 *
 * @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 Database} 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 _pause(resourceGroupName, serverName, databaseName, 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.');
  }

  // Send request
  this.beginPause(resourceGroupName, serverName, databaseName, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Database']().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);
    });
  });
}


/**
 * Resumes a database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database to be resumed.
 *
 * @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 Database} 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 _resume(resourceGroupName, serverName, databaseName, 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.');
  }

  // Send request
  this.beginResume(resourceGroupName, serverName, databaseName, options, (err, parsedResult, httpRequest, response) => {
    if (err) return callback(err);

    let initialResult = new msRest.HttpOperationResponse();
    initialResult.request = httpRequest;
    initialResult.response = response;
    initialResult.body = response.body;
    client.getLongRunningOperationResult(initialResult, options, (err, pollingResult) => {
      if (err) return callback(err);

      // Create Result
      let result = null;

      httpRequest = pollingResult.request;
      response = pollingResult.response;
      let responseBody = pollingResult.body;
      if (responseBody === '') responseBody = null;

      // Deserialize Response
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Database']().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);
    });
  });
}

/**
 * Renames a database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database to rename.
 *
 * @param {object} parameters The resource move definition for renaming this
 * database.
 *
 * @param {string} parameters.id The target ID for the resource
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _rename(resourceGroupName, serverName, databaseName, 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.');
  }
  let apiVersion = '2017-10-01-preview';
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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.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.Sql/servers/{serverName}/databases/{databaseName}/move';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

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

/**
 * Imports a bacpac into a new database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {object} parameters The required parameters for importing a Bacpac
 * into a database.
 *
 * @param {string} parameters.databaseName The name of the database to import.
 *
 * @param {string} parameters.edition The edition for the database being
 * created. Possible values include: 'Web', 'Business', 'Basic', 'Standard',
 * 'Premium', 'PremiumRS', 'Free', 'Stretch', 'DataWarehouse', 'System',
 * 'System2'
 *
 * @param {string} parameters.serviceObjectiveName The name of the service
 * objective to assign to the database. Possible values include: 'System',
 * 'System0', 'System1', 'System2', 'System3', 'System4', 'System2L',
 * 'System3L', 'System4L', 'Free', 'Basic', 'S0', 'S1', 'S2', 'S3', 'S4', 'S6',
 * 'S7', 'S9', 'S12', 'P1', 'P2', 'P3', 'P4', 'P6', 'P11', 'P15', 'PRS1',
 * 'PRS2', 'PRS4', 'PRS6', 'DW100', 'DW200', 'DW300', 'DW400', 'DW500',
 * 'DW600', 'DW1000', 'DW1200', 'DW1000c', 'DW1500', 'DW1500c', 'DW2000',
 * 'DW2000c', 'DW3000', 'DW2500c', 'DW3000c', 'DW6000', 'DW5000c', 'DW6000c',
 * 'DW7500c', 'DW10000c', 'DW15000c', 'DW30000c', 'DS100', 'DS200', 'DS300',
 * 'DS400', 'DS500', 'DS600', 'DS1000', 'DS1200', 'DS1500', 'DS2000',
 * 'ElasticPool'
 *
 * @param {string} parameters.maxSizeBytes The maximum size for the newly
 * imported database.
 *
 * @param {string} parameters.storageKeyType The type of the storage key to
 * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
 *
 * @param {string} parameters.storageKey The storage key to use.  If storage
 * key type is SharedAccessKey, it must be preceded with a "?."
 *
 * @param {string} parameters.storageUri The storage uri to use.
 *
 * @param {string} parameters.administratorLogin The name of the SQL
 * administrator.
 *
 * @param {string} parameters.administratorLoginPassword The password of the
 * SQL administrator.
 *
 * @param {string} [parameters.authenticationType] The authentication type.
 * Possible values include: 'SQL', 'ADPassword'
 *
 * @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 ImportExportResponse} 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 _beginImportMethod(resourceGroupName, serverName, 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.');
  }
  let apiVersion = '2014-04-01';
  // Validate
  try {
    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 (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 (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName 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.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.Sql/servers/{serverName}/import';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

/**
 * Creates an import operation that imports a bacpac into an existing database.
 * The existing database must be empty.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database to import into
 *
 * @param {object} parameters The required parameters for importing a Bacpac
 * into a database.
 *
 * @param {string} [parameters.name] The name of the extension.
 *
 * @param {string} [parameters.type] The type of the extension.
 *
 * @param {string} parameters.storageKeyType The type of the storage key to
 * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
 *
 * @param {string} parameters.storageKey The storage key to use.  If storage
 * key type is SharedAccessKey, it must be preceded with a "?."
 *
 * @param {string} parameters.storageUri The storage uri to use.
 *
 * @param {string} parameters.administratorLogin The name of the SQL
 * administrator.
 *
 * @param {string} parameters.administratorLoginPassword The password of the
 * SQL administrator.
 *
 * @param {string} [parameters.authenticationType] The authentication type.
 * Possible values include: 'SQL', 'ADPassword'
 *
 * @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 ImportExportResponse} 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 _beginCreateImportOperation(resourceGroupName, serverName, databaseName, 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.');
  }
  let apiVersion = '2014-04-01';
  let extensionName = 'import';
  if (parameters === null || parameters === undefined)
  {
    parameters = {};
  }
  // Validate
  try {
    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 (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 (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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.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.Sql/servers/{serverName}/databases/{databaseName}/extensions/{extensionName}';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  requestUrl = requestUrl.replace('{extensionName}', encodeURIComponent(extensionName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(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['ImportExtensionRequest']().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 && statusCode !== 202) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 201) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['ImportExportResponse']().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);
  });
}

/**
 * Exports a database to a bacpac.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database to be exported.
 *
 * @param {object} parameters The required parameters for exporting a database.
 *
 * @param {string} parameters.storageKeyType The type of the storage key to
 * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
 *
 * @param {string} parameters.storageKey The storage key to use.  If storage
 * key type is SharedAccessKey, it must be preceded with a "?."
 *
 * @param {string} parameters.storageUri The storage uri to use.
 *
 * @param {string} parameters.administratorLogin The name of the SQL
 * administrator.
 *
 * @param {string} parameters.administratorLoginPassword The password of the
 * SQL administrator.
 *
 * @param {string} [parameters.authenticationType] The authentication type.
 * Possible values include: 'SQL', 'ADPassword'
 *
 * @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 ImportExportResponse} 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 _beginExportMethod(resourceGroupName, serverName, databaseName, 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.');
  }
  let apiVersion = '2014-04-01';
  // Validate
  try {
    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 (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 (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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.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.Sql/servers/{serverName}/databases/{databaseName}/export';
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

/**
 * Upgrades a data warehouse.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database to be upgraded.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _beginUpgradeDataWarehouse(resourceGroupName, serverName, databaseName, 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 apiVersion = '2017-10-01-preview';
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

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

/**
 * Creates a new database or updates an existing database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database.
 *
 * @param {object} parameters The requested database resource state.
 *
 * @param {object} [parameters.sku] The name and tier of the SKU.
 *
 * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
 * typically a letter+number code
 *
 * @param {string} [parameters.sku.tier] This field is required to be
 * implemented by the Resource Provider if the service has more than one tier,
 * but is not required on a PUT.
 *
 * @param {string} [parameters.sku.size] The SKU size. When the name field is
 * the combination of tier and some other value, this would be the standalone
 * code.
 *
 * @param {string} [parameters.sku.family] If the service has different
 * generations of hardware, for the same SKU, then that can be captured here.
 *
 * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
 * then the capacity integer should be included. If scale out/in is not
 * possible for the resource this may be omitted.
 *
 * @param {string} [parameters.createMode] Specifies the mode of database
 * creation.
 *
 * Default: regular database creation.
 *
 * Copy: creates a database as a copy of an existing database. sourceDatabaseId
 * must be specified as the resource ID of the source database.
 *
 * Secondary: creates a database as a secondary replica of an existing
 * database. sourceDatabaseId must be specified as the resource ID of the
 * existing primary database.
 *
 * PointInTimeRestore: Creates a database by restoring a point in time backup
 * of an existing database. sourceDatabaseId must be specified as the resource
 * ID of the existing database, and restorePointInTime must be specified.
 *
 * Recovery: Creates a database by restoring a geo-replicated backup.
 * sourceDatabaseId must be specified as the recoverable database resource ID
 * to restore.
 *
 * Restore: Creates a database by restoring a backup of a deleted database.
 * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
 * original resource ID, then sourceDatabaseDeletionDate must be specified.
 * Otherwise sourceDatabaseId must be the restorable dropped database resource
 * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
 * specified to restore from an earlier point in time.
 *
 * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
 * term retention vault. recoveryServicesRecoveryPointResourceId must be
 * specified as the recovery point resource ID.
 *
 * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
 * DataWarehouse edition. Possible values include: 'Default', 'Copy',
 * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
 * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
 * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
 *
 * @param {string} [parameters.collation] The collation of the database.
 *
 * @param {number} [parameters.maxSizeBytes] The max size of the database
 * expressed in bytes.
 *
 * @param {string} [parameters.sampleName] The name of the sample schema to
 * apply when creating this database. Possible values include:
 * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
 *
 * @param {string} [parameters.elasticPoolId] The resource identifier of the
 * elastic pool containing this database.
 *
 * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
 * source database associated with create operation of this database.
 *
 * @param {date} [parameters.restorePointInTime] Specifies the point in time
 * (ISO8601 format) of the source database that will be restored to create the
 * new database.
 *
 * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
 * that the database was deleted.
 *
 * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
 * identifier of the recovery point associated with create operation of this
 * database.
 *
 * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
 * identifier of the long term retention backup associated with create
 * operation of this database.
 *
 * @param {string} [parameters.recoverableDatabaseId] The resource identifier
 * of the recoverable database associated with create operation of this
 * database.
 *
 * @param {string} [parameters.restorableDroppedDatabaseId] The resource
 * identifier of the restorable dropped database associated with create
 * operation of this database.
 *
 * @param {string} [parameters.catalogCollation] Collation of the metadata
 * catalog. Possible values include: 'DATABASE_DEFAULT',
 * 'SQL_Latin1_General_CP1_CI_AS'
 *
 * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
 * zone redundant, which means the replicas of this database will be spread
 * across multiple availability zones.
 *
 * @param {string} [parameters.licenseType] The license type to apply for this
 * database. Possible values include: 'LicenseIncluded', 'BasePrice'
 *
 * @param {string} [parameters.readScale] The state of read-only routing. If
 * enabled, connections that have application intent set to readonly in their
 * connection string may be routed to a readonly secondary replica in the same
 * region. Possible values include: 'Enabled', 'Disabled'
 *
 * @param {string} parameters.location Resource location.
 *
 * @param {object} [parameters.tags] Resource tags.
 *
 * @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 Database} 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 _beginCreateOrUpdate(resourceGroupName, serverName, databaseName, 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.');
  }
  let apiVersion = '2017-10-01-preview';
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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.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.Sql/servers/{serverName}/databases/{databaseName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(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['Database']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200 && statusCode !== 201 && statusCode !== 202) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Database']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError.request = msRest.stripRequest(httpRequest);
        deserializationError.response = msRest.stripResponse(response);
        return callback(deserializationError);
      }
    }
    // Deserialize Response
    if (statusCode === 201) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Database']().mapper();
          result = client.deserialize(resultMapper, parsedResponse, 'result');
        }
      } catch (error) {
        let deserializationError1 = new Error(`Error ${error} occurred in deserializing the responseBody - ${responseBody}`);
        deserializationError1.request = msRest.stripRequest(httpRequest);
        deserializationError1.response = msRest.stripResponse(response);
        return callback(deserializationError1);
      }
    }

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

/**
 * Deletes the database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database.
 *
 * @param {object} [options] Optional Parameters.
 *
 * @param {object} [options.customHeaders] Headers that will be added to the
 * request
 *
 * @param {function} callback - The callback.
 *
 * @returns {function} callback(err, result, request, response)
 *
 *                      {Error}  err        - The Error object if an error occurred, null otherwise.
 *
 *                      {null} [result]   - The deserialized result object if an error did not occur.
 *
 *                      {object} [request]  - The HTTP Request object if an error did not occur.
 *
 *                      {stream} [response] - The HTTP Response stream if an error did not occur.
 */
function _beginDeleteMethod(resourceGroupName, serverName, databaseName, 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 apiVersion = '2017-10-01-preview';
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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.Sql/servers/{serverName}/databases/{databaseName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(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 !== 202 && statusCode !== 204) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;

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

/**
 * Updates an existing database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database.
 *
 * @param {object} parameters The requested database resource state.
 *
 * @param {object} [parameters.sku] The name and tier of the SKU.
 *
 * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
 * typically a letter+number code
 *
 * @param {string} [parameters.sku.tier] This field is required to be
 * implemented by the Resource Provider if the service has more than one tier,
 * but is not required on a PUT.
 *
 * @param {string} [parameters.sku.size] The SKU size. When the name field is
 * the combination of tier and some other value, this would be the standalone
 * code.
 *
 * @param {string} [parameters.sku.family] If the service has different
 * generations of hardware, for the same SKU, then that can be captured here.
 *
 * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
 * then the capacity integer should be included. If scale out/in is not
 * possible for the resource this may be omitted.
 *
 * @param {string} [parameters.createMode] Specifies the mode of database
 * creation.
 *
 * Default: regular database creation.
 *
 * Copy: creates a database as a copy of an existing database. sourceDatabaseId
 * must be specified as the resource ID of the source database.
 *
 * Secondary: creates a database as a secondary replica of an existing
 * database. sourceDatabaseId must be specified as the resource ID of the
 * existing primary database.
 *
 * PointInTimeRestore: Creates a database by restoring a point in time backup
 * of an existing database. sourceDatabaseId must be specified as the resource
 * ID of the existing database, and restorePointInTime must be specified.
 *
 * Recovery: Creates a database by restoring a geo-replicated backup.
 * sourceDatabaseId must be specified as the recoverable database resource ID
 * to restore.
 *
 * Restore: Creates a database by restoring a backup of a deleted database.
 * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
 * original resource ID, then sourceDatabaseDeletionDate must be specified.
 * Otherwise sourceDatabaseId must be the restorable dropped database resource
 * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
 * specified to restore from an earlier point in time.
 *
 * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
 * term retention vault. recoveryServicesRecoveryPointResourceId must be
 * specified as the recovery point resource ID.
 *
 * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
 * DataWarehouse edition. Possible values include: 'Default', 'Copy',
 * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
 * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
 * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
 *
 * @param {string} [parameters.collation] The collation of the database.
 *
 * @param {number} [parameters.maxSizeBytes] The max size of the database
 * expressed in bytes.
 *
 * @param {string} [parameters.sampleName] The name of the sample schema to
 * apply when creating this database. Possible values include:
 * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
 *
 * @param {string} [parameters.elasticPoolId] The resource identifier of the
 * elastic pool containing this database.
 *
 * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
 * source database associated with create operation of this database.
 *
 * @param {date} [parameters.restorePointInTime] Specifies the point in time
 * (ISO8601 format) of the source database that will be restored to create the
 * new database.
 *
 * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
 * that the database was deleted.
 *
 * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
 * identifier of the recovery point associated with create operation of this
 * database.
 *
 * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
 * identifier of the long term retention backup associated with create
 * operation of this database.
 *
 * @param {string} [parameters.recoverableDatabaseId] The resource identifier
 * of the recoverable database associated with create operation of this
 * database.
 *
 * @param {string} [parameters.restorableDroppedDatabaseId] The resource
 * identifier of the restorable dropped database associated with create
 * operation of this database.
 *
 * @param {string} [parameters.catalogCollation] Collation of the metadata
 * catalog. Possible values include: 'DATABASE_DEFAULT',
 * 'SQL_Latin1_General_CP1_CI_AS'
 *
 * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
 * zone redundant, which means the replicas of this database will be spread
 * across multiple availability zones.
 *
 * @param {string} [parameters.licenseType] The license type to apply for this
 * database. Possible values include: 'LicenseIncluded', 'BasePrice'
 *
 * @param {string} [parameters.readScale] The state of read-only routing. If
 * enabled, connections that have application intent set to readonly in their
 * connection string may be routed to a readonly secondary replica in the same
 * region. Possible values include: 'Enabled', 'Disabled'
 *
 * @param {object} [parameters.tags] Resource tags.
 *
 * @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 Database} 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 _beginUpdate(resourceGroupName, serverName, databaseName, 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.');
  }
  let apiVersion = '2017-10-01-preview';
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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.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.Sql/servers/{serverName}/databases/{databaseName}';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'PATCH';
  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['DatabaseUpdate']().mapper();
      requestModel = client.serialize(requestModelMapper, parameters, 'parameters');
      requestContent = JSON.stringify(requestModel);
    }
  } catch (error) {
    let serializationError = new Error(`Error "${error.message}" occurred in serializing the ` +
        `payload - ${JSON.stringify(parameters, null, 2)}.`);
    return callback(serializationError);
  }
  httpRequest.body = requestContent;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200 && statusCode !== 202) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['Database']().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);
  });
}

/**
 * Pauses a database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database to be paused.
 *
 * @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 Database} 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 _beginPause(resourceGroupName, serverName, databaseName, 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 apiVersion = '2017-10-01-preview';
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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.Sql/servers/{serverName}/databases/{databaseName}/pause';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

/**
 * Resumes a database.
 *
 * @param {string} resourceGroupName The name of the resource group that
 * contains the resource. You can obtain this value from the Azure Resource
 * Manager API or the portal.
 *
 * @param {string} serverName The name of the server.
 *
 * @param {string} databaseName The name of the database to be resumed.
 *
 * @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 Database} 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 _beginResume(resourceGroupName, serverName, databaseName, 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 apiVersion = '2017-10-01-preview';
  // Validate
  try {
    if (resourceGroupName === null || resourceGroupName === undefined || typeof resourceGroupName.valueOf() !== 'string') {
      throw new Error('resourceGroupName cannot be null or undefined and it must be of type string.');
    }
    if (serverName === null || serverName === undefined || typeof serverName.valueOf() !== 'string') {
      throw new Error('serverName cannot be null or undefined and it must be of type string.');
    }
    if (databaseName === null || databaseName === undefined || typeof databaseName.valueOf() !== 'string') {
      throw new Error('databaseName 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.Sql/servers/{serverName}/databases/{databaseName}/resume';
  requestUrl = requestUrl.replace('{resourceGroupName}', encodeURIComponent(resourceGroupName));
  requestUrl = requestUrl.replace('{serverName}', encodeURIComponent(serverName));
  requestUrl = requestUrl.replace('{databaseName}', encodeURIComponent(databaseName));
  requestUrl = requestUrl.replace('{subscriptionId}', encodeURIComponent(this.client.subscriptionId));
  let queryParameters = [];
  queryParameters.push('api-version=' + encodeURIComponent(apiVersion));
  if (queryParameters.length > 0) {
    requestUrl += '?' + queryParameters.join('&');
  }

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

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

/**
 * Gets a list of databases.
 *
 * @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 DatabaseListResult} 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 _listByServerNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

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

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

/**
 * Gets a list of databases in an elastic pool.
 *
 * @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 DatabaseListResult} 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 _listByElasticPoolNext(nextPageLink, options, callback) {
   /* jshint validthis: true */
  let client = this.client;
  if(!callback && typeof options === 'function') {
    callback = options;
    options = null;
  }
  if (!callback) {
    throw new Error('callback cannot be null.');
  }
  // Validate
  try {
    if (nextPageLink === null || nextPageLink === undefined || typeof nextPageLink.valueOf() !== 'string') {
      throw new Error('nextPageLink cannot be null or undefined and it must be of type string.');
    }
    if (this.client.acceptLanguage !== null && this.client.acceptLanguage !== undefined && typeof this.client.acceptLanguage.valueOf() !== 'string') {
      throw new Error('this.client.acceptLanguage must be of type string.');
    }
  } catch (error) {
    return callback(error);
  }

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

  // Create HTTP transport objects
  let httpRequest = new WebResource();
  httpRequest.method = 'GET';
  httpRequest.url = requestUrl;
  httpRequest.headers = {};
  // Set Headers
  httpRequest.headers['Content-Type'] = 'application/json; charset=utf-8';
  if (this.client.generateClientRequestId) {
      httpRequest.headers['x-ms-client-request-id'] = msRestAzure.generateUuid();
  }
  if (this.client.acceptLanguage !== undefined && this.client.acceptLanguage !== null) {
    httpRequest.headers['accept-language'] = this.client.acceptLanguage;
  }
  if(options) {
    for(let headerName in options['customHeaders']) {
      if (options['customHeaders'].hasOwnProperty(headerName)) {
        httpRequest.headers[headerName] = options['customHeaders'][headerName];
      }
    }
  }
  httpRequest.body = null;
  // Send Request
  return client.pipeline(httpRequest, (err, response, responseBody) => {
    if (err) {
      return callback(err);
    }
    let statusCode = response.statusCode;
    if (statusCode !== 200) {
      let error = new Error(responseBody);
      error.statusCode = response.statusCode;
      error.request = msRest.stripRequest(httpRequest);
      error.response = msRest.stripResponse(response);
      if (responseBody === '') responseBody = null;
      let parsedErrorResponse;
      try {
        parsedErrorResponse = JSON.parse(responseBody);
        if (parsedErrorResponse) {
          if (parsedErrorResponse.error) parsedErrorResponse = parsedErrorResponse.error;
          if (parsedErrorResponse.code) error.code = parsedErrorResponse.code;
          if (parsedErrorResponse.message) error.message = parsedErrorResponse.message;
        }
        if (parsedErrorResponse !== null && parsedErrorResponse !== undefined) {
          let resultMapper = new client.models['CloudError']().mapper();
          error.body = client.deserialize(resultMapper, parsedErrorResponse, 'error.body');
        }
      } catch (defaultError) {
        error.message = `Error "${defaultError.message}" occurred in deserializing the responseBody ` +
                         `- "${responseBody}" for the default response.`;
        return callback(error);
      }
      return callback(error);
    }
    // Create Result
    let result = null;
    if (responseBody === '') responseBody = null;
    // Deserialize Response
    if (statusCode === 200) {
      let parsedResponse = null;
      try {
        parsedResponse = JSON.parse(responseBody);
        result = JSON.parse(responseBody);
        if (parsedResponse !== null && parsedResponse !== undefined) {
          let resultMapper = new client.models['DatabaseListResult']().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 Databases. */
class Databases {
  /**
   * Create a Databases.
   * @param {SqlManagementClient} client Reference to the service client.
   */
  constructor(client) {
    this.client = client;
    this._importMethod = _importMethod;
    this._createImportOperation = _createImportOperation;
    this._exportMethod = _exportMethod;
    this._listMetrics = _listMetrics;
    this._listMetricDefinitions = _listMetricDefinitions;
    this._upgradeDataWarehouse = _upgradeDataWarehouse;
    this._listByServer = _listByServer;
    this._get = _get;
    this._createOrUpdate = _createOrUpdate;
    this._deleteMethod = _deleteMethod;
    this._update = _update;
    this._listByElasticPool = _listByElasticPool;
    this._pause = _pause;
    this._resume = _resume;
    this._rename = _rename;
    this._beginImportMethod = _beginImportMethod;
    this._beginCreateImportOperation = _beginCreateImportOperation;
    this._beginExportMethod = _beginExportMethod;
    this._beginUpgradeDataWarehouse = _beginUpgradeDataWarehouse;
    this._beginCreateOrUpdate = _beginCreateOrUpdate;
    this._beginDeleteMethod = _beginDeleteMethod;
    this._beginUpdate = _beginUpdate;
    this._beginPause = _beginPause;
    this._beginResume = _beginResume;
    this._listByServerNext = _listByServerNext;
    this._listByElasticPoolNext = _listByElasticPoolNext;
  }

  /**
   * Imports a bacpac into a new database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {object} parameters The required parameters for importing a Bacpac
   * into a database.
   *
   * @param {string} parameters.databaseName The name of the database to import.
   *
   * @param {string} parameters.edition The edition for the database being
   * created. Possible values include: 'Web', 'Business', 'Basic', 'Standard',
   * 'Premium', 'PremiumRS', 'Free', 'Stretch', 'DataWarehouse', 'System',
   * 'System2'
   *
   * @param {string} parameters.serviceObjectiveName The name of the service
   * objective to assign to the database. Possible values include: 'System',
   * 'System0', 'System1', 'System2', 'System3', 'System4', 'System2L',
   * 'System3L', 'System4L', 'Free', 'Basic', 'S0', 'S1', 'S2', 'S3', 'S4', 'S6',
   * 'S7', 'S9', 'S12', 'P1', 'P2', 'P3', 'P4', 'P6', 'P11', 'P15', 'PRS1',
   * 'PRS2', 'PRS4', 'PRS6', 'DW100', 'DW200', 'DW300', 'DW400', 'DW500',
   * 'DW600', 'DW1000', 'DW1200', 'DW1000c', 'DW1500', 'DW1500c', 'DW2000',
   * 'DW2000c', 'DW3000', 'DW2500c', 'DW3000c', 'DW6000', 'DW5000c', 'DW6000c',
   * 'DW7500c', 'DW10000c', 'DW15000c', 'DW30000c', 'DS100', 'DS200', 'DS300',
   * 'DS400', 'DS500', 'DS600', 'DS1000', 'DS1200', 'DS1500', 'DS2000',
   * 'ElasticPool'
   *
   * @param {string} parameters.maxSizeBytes The maximum size for the newly
   * imported database.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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<ImportExportResponse>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  importMethodWithHttpOperationResponse(resourceGroupName, serverName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._importMethod(resourceGroupName, serverName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Imports a bacpac into a new database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {object} parameters The required parameters for importing a Bacpac
   * into a database.
   *
   * @param {string} parameters.databaseName The name of the database to import.
   *
   * @param {string} parameters.edition The edition for the database being
   * created. Possible values include: 'Web', 'Business', 'Basic', 'Standard',
   * 'Premium', 'PremiumRS', 'Free', 'Stretch', 'DataWarehouse', 'System',
   * 'System2'
   *
   * @param {string} parameters.serviceObjectiveName The name of the service
   * objective to assign to the database. Possible values include: 'System',
   * 'System0', 'System1', 'System2', 'System3', 'System4', 'System2L',
   * 'System3L', 'System4L', 'Free', 'Basic', 'S0', 'S1', 'S2', 'S3', 'S4', 'S6',
   * 'S7', 'S9', 'S12', 'P1', 'P2', 'P3', 'P4', 'P6', 'P11', 'P15', 'PRS1',
   * 'PRS2', 'PRS4', 'PRS6', 'DW100', 'DW200', 'DW300', 'DW400', 'DW500',
   * 'DW600', 'DW1000', 'DW1200', 'DW1000c', 'DW1500', 'DW1500c', 'DW2000',
   * 'DW2000c', 'DW3000', 'DW2500c', 'DW3000c', 'DW6000', 'DW5000c', 'DW6000c',
   * 'DW7500c', 'DW10000c', 'DW15000c', 'DW30000c', 'DS100', 'DS200', 'DS300',
   * 'DS400', 'DS500', 'DS600', 'DS1000', 'DS1200', 'DS1500', 'DS2000',
   * 'ElasticPool'
   *
   * @param {string} parameters.maxSizeBytes The maximum size for the newly
   * imported database.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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 {ImportExportResponse} - 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 ImportExportResponse} 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.
   */
  importMethod(resourceGroupName, serverName, 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._importMethod(resourceGroupName, serverName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._importMethod(resourceGroupName, serverName, parameters, options, optionalCallback);
    }
  }

  /**
   * Creates an import operation that imports a bacpac into an existing database.
   * The existing database must be empty.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to import into
   *
   * @param {object} parameters The required parameters for importing a Bacpac
   * into a database.
   *
   * @param {string} [parameters.name] The name of the extension.
   *
   * @param {string} [parameters.type] The type of the extension.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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<ImportExportResponse>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createImportOperationWithHttpOperationResponse(resourceGroupName, serverName, databaseName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._createImportOperation(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates an import operation that imports a bacpac into an existing database.
   * The existing database must be empty.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to import into
   *
   * @param {object} parameters The required parameters for importing a Bacpac
   * into a database.
   *
   * @param {string} [parameters.name] The name of the extension.
   *
   * @param {string} [parameters.type] The type of the extension.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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 {ImportExportResponse} - 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 ImportExportResponse} 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.
   */
  createImportOperation(resourceGroupName, serverName, databaseName, 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._createImportOperation(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._createImportOperation(resourceGroupName, serverName, databaseName, parameters, options, optionalCallback);
    }
  }

  /**
   * Exports a database to a bacpac.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be exported.
   *
   * @param {object} parameters The required parameters for exporting a database.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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<ImportExportResponse>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  exportMethodWithHttpOperationResponse(resourceGroupName, serverName, databaseName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._exportMethod(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Exports a database to a bacpac.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be exported.
   *
   * @param {object} parameters The required parameters for exporting a database.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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 {ImportExportResponse} - 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 ImportExportResponse} 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.
   */
  exportMethod(resourceGroupName, serverName, databaseName, 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._exportMethod(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._exportMethod(resourceGroupName, serverName, databaseName, parameters, options, optionalCallback);
    }
  }

  /**
   * Returns database metrics.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {string} filter An OData filter expression that describes a subset of
   * metrics to return.
   *
   * @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<MetricListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listMetricsWithHttpOperationResponse(resourceGroupName, serverName, databaseName, filter, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listMetrics(resourceGroupName, serverName, databaseName, filter, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Returns database metrics.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {string} filter An OData filter expression that describes a subset of
   * metrics to return.
   *
   * @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 {MetricListResult} - 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 MetricListResult} 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.
   */
  listMetrics(resourceGroupName, serverName, databaseName, filter, 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._listMetrics(resourceGroupName, serverName, databaseName, filter, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listMetrics(resourceGroupName, serverName, databaseName, filter, options, optionalCallback);
    }
  }

  /**
   * Returns database metric definitions.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @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<MetricDefinitionListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listMetricDefinitionsWithHttpOperationResponse(resourceGroupName, serverName, databaseName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listMetricDefinitions(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Returns database metric definitions.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @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 {MetricDefinitionListResult} - 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 MetricDefinitionListResult} 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.
   */
  listMetricDefinitions(resourceGroupName, serverName, databaseName, 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._listMetricDefinitions(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listMetricDefinitions(resourceGroupName, serverName, databaseName, options, optionalCallback);
    }
  }

  /**
   * Upgrades a data warehouse.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be upgraded.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  upgradeDataWarehouseWithHttpOperationResponse(resourceGroupName, serverName, databaseName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._upgradeDataWarehouse(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Upgrades a data warehouse.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be upgraded.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {null} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  upgradeDataWarehouse(resourceGroupName, serverName, databaseName, 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._upgradeDataWarehouse(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._upgradeDataWarehouse(resourceGroupName, serverName, databaseName, options, optionalCallback);
    }
  }

  /**
   * Gets a list of databases.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @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<DatabaseListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByServerWithHttpOperationResponse(resourceGroupName, serverName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByServer(resourceGroupName, serverName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets a list of databases.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @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 {DatabaseListResult} - 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 DatabaseListResult} 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.
   */
  listByServer(resourceGroupName, serverName, 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._listByServer(resourceGroupName, serverName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByServer(resourceGroupName, serverName, options, optionalCallback);
    }
  }

  /**
   * Gets a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @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<Database>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  getWithHttpOperationResponse(resourceGroupName, serverName, databaseName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._get(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @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 {Database} - 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 Database} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  get(resourceGroupName, serverName, databaseName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._get(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._get(resourceGroupName, serverName, databaseName, options, optionalCallback);
    }
  }

  /**
   * Creates a new database or updates an existing database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} parameters The requested database resource state.
   *
   * @param {object} [parameters.sku] The name and tier of the SKU.
   *
   * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
   * typically a letter+number code
   *
   * @param {string} [parameters.sku.tier] This field is required to be
   * implemented by the Resource Provider if the service has more than one tier,
   * but is not required on a PUT.
   *
   * @param {string} [parameters.sku.size] The SKU size. When the name field is
   * the combination of tier and some other value, this would be the standalone
   * code.
   *
   * @param {string} [parameters.sku.family] If the service has different
   * generations of hardware, for the same SKU, then that can be captured here.
   *
   * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
   * then the capacity integer should be included. If scale out/in is not
   * possible for the resource this may be omitted.
   *
   * @param {string} [parameters.createMode] Specifies the mode of database
   * creation.
   *
   * Default: regular database creation.
   *
   * Copy: creates a database as a copy of an existing database. sourceDatabaseId
   * must be specified as the resource ID of the source database.
   *
   * Secondary: creates a database as a secondary replica of an existing
   * database. sourceDatabaseId must be specified as the resource ID of the
   * existing primary database.
   *
   * PointInTimeRestore: Creates a database by restoring a point in time backup
   * of an existing database. sourceDatabaseId must be specified as the resource
   * ID of the existing database, and restorePointInTime must be specified.
   *
   * Recovery: Creates a database by restoring a geo-replicated backup.
   * sourceDatabaseId must be specified as the recoverable database resource ID
   * to restore.
   *
   * Restore: Creates a database by restoring a backup of a deleted database.
   * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
   * original resource ID, then sourceDatabaseDeletionDate must be specified.
   * Otherwise sourceDatabaseId must be the restorable dropped database resource
   * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
   * specified to restore from an earlier point in time.
   *
   * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
   * term retention vault. recoveryServicesRecoveryPointResourceId must be
   * specified as the recovery point resource ID.
   *
   * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
   * DataWarehouse edition. Possible values include: 'Default', 'Copy',
   * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
   * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
   * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
   *
   * @param {string} [parameters.collation] The collation of the database.
   *
   * @param {number} [parameters.maxSizeBytes] The max size of the database
   * expressed in bytes.
   *
   * @param {string} [parameters.sampleName] The name of the sample schema to
   * apply when creating this database. Possible values include:
   * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
   *
   * @param {string} [parameters.elasticPoolId] The resource identifier of the
   * elastic pool containing this database.
   *
   * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
   * source database associated with create operation of this database.
   *
   * @param {date} [parameters.restorePointInTime] Specifies the point in time
   * (ISO8601 format) of the source database that will be restored to create the
   * new database.
   *
   * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
   * that the database was deleted.
   *
   * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
   * identifier of the recovery point associated with create operation of this
   * database.
   *
   * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
   * identifier of the long term retention backup associated with create
   * operation of this database.
   *
   * @param {string} [parameters.recoverableDatabaseId] The resource identifier
   * of the recoverable database associated with create operation of this
   * database.
   *
   * @param {string} [parameters.restorableDroppedDatabaseId] The resource
   * identifier of the restorable dropped database associated with create
   * operation of this database.
   *
   * @param {string} [parameters.catalogCollation] Collation of the metadata
   * catalog. Possible values include: 'DATABASE_DEFAULT',
   * 'SQL_Latin1_General_CP1_CI_AS'
   *
   * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
   * zone redundant, which means the replicas of this database will be spread
   * across multiple availability zones.
   *
   * @param {string} [parameters.licenseType] The license type to apply for this
   * database. Possible values include: 'LicenseIncluded', 'BasePrice'
   *
   * @param {string} [parameters.readScale] The state of read-only routing. If
   * enabled, connections that have application intent set to readonly in their
   * connection string may be routed to a readonly secondary replica in the same
   * region. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {string} parameters.location Resource location.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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<Database>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  createOrUpdateWithHttpOperationResponse(resourceGroupName, serverName, databaseName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._createOrUpdate(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates a new database or updates an existing database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} parameters The requested database resource state.
   *
   * @param {object} [parameters.sku] The name and tier of the SKU.
   *
   * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
   * typically a letter+number code
   *
   * @param {string} [parameters.sku.tier] This field is required to be
   * implemented by the Resource Provider if the service has more than one tier,
   * but is not required on a PUT.
   *
   * @param {string} [parameters.sku.size] The SKU size. When the name field is
   * the combination of tier and some other value, this would be the standalone
   * code.
   *
   * @param {string} [parameters.sku.family] If the service has different
   * generations of hardware, for the same SKU, then that can be captured here.
   *
   * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
   * then the capacity integer should be included. If scale out/in is not
   * possible for the resource this may be omitted.
   *
   * @param {string} [parameters.createMode] Specifies the mode of database
   * creation.
   *
   * Default: regular database creation.
   *
   * Copy: creates a database as a copy of an existing database. sourceDatabaseId
   * must be specified as the resource ID of the source database.
   *
   * Secondary: creates a database as a secondary replica of an existing
   * database. sourceDatabaseId must be specified as the resource ID of the
   * existing primary database.
   *
   * PointInTimeRestore: Creates a database by restoring a point in time backup
   * of an existing database. sourceDatabaseId must be specified as the resource
   * ID of the existing database, and restorePointInTime must be specified.
   *
   * Recovery: Creates a database by restoring a geo-replicated backup.
   * sourceDatabaseId must be specified as the recoverable database resource ID
   * to restore.
   *
   * Restore: Creates a database by restoring a backup of a deleted database.
   * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
   * original resource ID, then sourceDatabaseDeletionDate must be specified.
   * Otherwise sourceDatabaseId must be the restorable dropped database resource
   * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
   * specified to restore from an earlier point in time.
   *
   * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
   * term retention vault. recoveryServicesRecoveryPointResourceId must be
   * specified as the recovery point resource ID.
   *
   * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
   * DataWarehouse edition. Possible values include: 'Default', 'Copy',
   * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
   * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
   * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
   *
   * @param {string} [parameters.collation] The collation of the database.
   *
   * @param {number} [parameters.maxSizeBytes] The max size of the database
   * expressed in bytes.
   *
   * @param {string} [parameters.sampleName] The name of the sample schema to
   * apply when creating this database. Possible values include:
   * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
   *
   * @param {string} [parameters.elasticPoolId] The resource identifier of the
   * elastic pool containing this database.
   *
   * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
   * source database associated with create operation of this database.
   *
   * @param {date} [parameters.restorePointInTime] Specifies the point in time
   * (ISO8601 format) of the source database that will be restored to create the
   * new database.
   *
   * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
   * that the database was deleted.
   *
   * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
   * identifier of the recovery point associated with create operation of this
   * database.
   *
   * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
   * identifier of the long term retention backup associated with create
   * operation of this database.
   *
   * @param {string} [parameters.recoverableDatabaseId] The resource identifier
   * of the recoverable database associated with create operation of this
   * database.
   *
   * @param {string} [parameters.restorableDroppedDatabaseId] The resource
   * identifier of the restorable dropped database associated with create
   * operation of this database.
   *
   * @param {string} [parameters.catalogCollation] Collation of the metadata
   * catalog. Possible values include: 'DATABASE_DEFAULT',
   * 'SQL_Latin1_General_CP1_CI_AS'
   *
   * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
   * zone redundant, which means the replicas of this database will be spread
   * across multiple availability zones.
   *
   * @param {string} [parameters.licenseType] The license type to apply for this
   * database. Possible values include: 'LicenseIncluded', 'BasePrice'
   *
   * @param {string} [parameters.readScale] The state of read-only routing. If
   * enabled, connections that have application intent set to readonly in their
   * connection string may be routed to a readonly secondary replica in the same
   * region. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {string} parameters.location Resource location.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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 {Database} - 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 Database} for more information.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  createOrUpdate(resourceGroupName, serverName, databaseName, parameters, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._createOrUpdate(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._createOrUpdate(resourceGroupName, serverName, databaseName, parameters, options, optionalCallback);
    }
  }

  /**
   * Deletes the database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  deleteMethodWithHttpOperationResponse(resourceGroupName, serverName, databaseName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._deleteMethod(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Deletes the database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {null} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  deleteMethod(resourceGroupName, serverName, databaseName, options, optionalCallback) {
    let client = this.client;
    let self = this;
    if (!optionalCallback && typeof options === 'function') {
      optionalCallback = options;
      options = null;
    }
    if (!optionalCallback) {
      return new Promise((resolve, reject) => {
        self._deleteMethod(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._deleteMethod(resourceGroupName, serverName, databaseName, options, optionalCallback);
    }
  }

  /**
   * Updates an existing database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} parameters The requested database resource state.
   *
   * @param {object} [parameters.sku] The name and tier of the SKU.
   *
   * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
   * typically a letter+number code
   *
   * @param {string} [parameters.sku.tier] This field is required to be
   * implemented by the Resource Provider if the service has more than one tier,
   * but is not required on a PUT.
   *
   * @param {string} [parameters.sku.size] The SKU size. When the name field is
   * the combination of tier and some other value, this would be the standalone
   * code.
   *
   * @param {string} [parameters.sku.family] If the service has different
   * generations of hardware, for the same SKU, then that can be captured here.
   *
   * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
   * then the capacity integer should be included. If scale out/in is not
   * possible for the resource this may be omitted.
   *
   * @param {string} [parameters.createMode] Specifies the mode of database
   * creation.
   *
   * Default: regular database creation.
   *
   * Copy: creates a database as a copy of an existing database. sourceDatabaseId
   * must be specified as the resource ID of the source database.
   *
   * Secondary: creates a database as a secondary replica of an existing
   * database. sourceDatabaseId must be specified as the resource ID of the
   * existing primary database.
   *
   * PointInTimeRestore: Creates a database by restoring a point in time backup
   * of an existing database. sourceDatabaseId must be specified as the resource
   * ID of the existing database, and restorePointInTime must be specified.
   *
   * Recovery: Creates a database by restoring a geo-replicated backup.
   * sourceDatabaseId must be specified as the recoverable database resource ID
   * to restore.
   *
   * Restore: Creates a database by restoring a backup of a deleted database.
   * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
   * original resource ID, then sourceDatabaseDeletionDate must be specified.
   * Otherwise sourceDatabaseId must be the restorable dropped database resource
   * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
   * specified to restore from an earlier point in time.
   *
   * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
   * term retention vault. recoveryServicesRecoveryPointResourceId must be
   * specified as the recovery point resource ID.
   *
   * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
   * DataWarehouse edition. Possible values include: 'Default', 'Copy',
   * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
   * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
   * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
   *
   * @param {string} [parameters.collation] The collation of the database.
   *
   * @param {number} [parameters.maxSizeBytes] The max size of the database
   * expressed in bytes.
   *
   * @param {string} [parameters.sampleName] The name of the sample schema to
   * apply when creating this database. Possible values include:
   * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
   *
   * @param {string} [parameters.elasticPoolId] The resource identifier of the
   * elastic pool containing this database.
   *
   * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
   * source database associated with create operation of this database.
   *
   * @param {date} [parameters.restorePointInTime] Specifies the point in time
   * (ISO8601 format) of the source database that will be restored to create the
   * new database.
   *
   * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
   * that the database was deleted.
   *
   * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
   * identifier of the recovery point associated with create operation of this
   * database.
   *
   * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
   * identifier of the long term retention backup associated with create
   * operation of this database.
   *
   * @param {string} [parameters.recoverableDatabaseId] The resource identifier
   * of the recoverable database associated with create operation of this
   * database.
   *
   * @param {string} [parameters.restorableDroppedDatabaseId] The resource
   * identifier of the restorable dropped database associated with create
   * operation of this database.
   *
   * @param {string} [parameters.catalogCollation] Collation of the metadata
   * catalog. Possible values include: 'DATABASE_DEFAULT',
   * 'SQL_Latin1_General_CP1_CI_AS'
   *
   * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
   * zone redundant, which means the replicas of this database will be spread
   * across multiple availability zones.
   *
   * @param {string} [parameters.licenseType] The license type to apply for this
   * database. Possible values include: 'LicenseIncluded', 'BasePrice'
   *
   * @param {string} [parameters.readScale] The state of read-only routing. If
   * enabled, connections that have application intent set to readonly in their
   * connection string may be routed to a readonly secondary replica in the same
   * region. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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<Database>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  updateWithHttpOperationResponse(resourceGroupName, serverName, databaseName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._update(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Updates an existing database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} parameters The requested database resource state.
   *
   * @param {object} [parameters.sku] The name and tier of the SKU.
   *
   * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
   * typically a letter+number code
   *
   * @param {string} [parameters.sku.tier] This field is required to be
   * implemented by the Resource Provider if the service has more than one tier,
   * but is not required on a PUT.
   *
   * @param {string} [parameters.sku.size] The SKU size. When the name field is
   * the combination of tier and some other value, this would be the standalone
   * code.
   *
   * @param {string} [parameters.sku.family] If the service has different
   * generations of hardware, for the same SKU, then that can be captured here.
   *
   * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
   * then the capacity integer should be included. If scale out/in is not
   * possible for the resource this may be omitted.
   *
   * @param {string} [parameters.createMode] Specifies the mode of database
   * creation.
   *
   * Default: regular database creation.
   *
   * Copy: creates a database as a copy of an existing database. sourceDatabaseId
   * must be specified as the resource ID of the source database.
   *
   * Secondary: creates a database as a secondary replica of an existing
   * database. sourceDatabaseId must be specified as the resource ID of the
   * existing primary database.
   *
   * PointInTimeRestore: Creates a database by restoring a point in time backup
   * of an existing database. sourceDatabaseId must be specified as the resource
   * ID of the existing database, and restorePointInTime must be specified.
   *
   * Recovery: Creates a database by restoring a geo-replicated backup.
   * sourceDatabaseId must be specified as the recoverable database resource ID
   * to restore.
   *
   * Restore: Creates a database by restoring a backup of a deleted database.
   * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
   * original resource ID, then sourceDatabaseDeletionDate must be specified.
   * Otherwise sourceDatabaseId must be the restorable dropped database resource
   * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
   * specified to restore from an earlier point in time.
   *
   * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
   * term retention vault. recoveryServicesRecoveryPointResourceId must be
   * specified as the recovery point resource ID.
   *
   * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
   * DataWarehouse edition. Possible values include: 'Default', 'Copy',
   * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
   * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
   * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
   *
   * @param {string} [parameters.collation] The collation of the database.
   *
   * @param {number} [parameters.maxSizeBytes] The max size of the database
   * expressed in bytes.
   *
   * @param {string} [parameters.sampleName] The name of the sample schema to
   * apply when creating this database. Possible values include:
   * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
   *
   * @param {string} [parameters.elasticPoolId] The resource identifier of the
   * elastic pool containing this database.
   *
   * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
   * source database associated with create operation of this database.
   *
   * @param {date} [parameters.restorePointInTime] Specifies the point in time
   * (ISO8601 format) of the source database that will be restored to create the
   * new database.
   *
   * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
   * that the database was deleted.
   *
   * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
   * identifier of the recovery point associated with create operation of this
   * database.
   *
   * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
   * identifier of the long term retention backup associated with create
   * operation of this database.
   *
   * @param {string} [parameters.recoverableDatabaseId] The resource identifier
   * of the recoverable database associated with create operation of this
   * database.
   *
   * @param {string} [parameters.restorableDroppedDatabaseId] The resource
   * identifier of the restorable dropped database associated with create
   * operation of this database.
   *
   * @param {string} [parameters.catalogCollation] Collation of the metadata
   * catalog. Possible values include: 'DATABASE_DEFAULT',
   * 'SQL_Latin1_General_CP1_CI_AS'
   *
   * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
   * zone redundant, which means the replicas of this database will be spread
   * across multiple availability zones.
   *
   * @param {string} [parameters.licenseType] The license type to apply for this
   * database. Possible values include: 'LicenseIncluded', 'BasePrice'
   *
   * @param {string} [parameters.readScale] The state of read-only routing. If
   * enabled, connections that have application intent set to readonly in their
   * connection string may be routed to a readonly secondary replica in the same
   * region. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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 {Database} - 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 Database} 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.
   */
  update(resourceGroupName, serverName, databaseName, 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._update(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._update(resourceGroupName, serverName, databaseName, parameters, options, optionalCallback);
    }
  }

  /**
   * Gets a list of databases in an elastic pool.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} elasticPoolName The name of the elastic pool.
   *
   * @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<DatabaseListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByElasticPoolWithHttpOperationResponse(resourceGroupName, serverName, elasticPoolName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByElasticPool(resourceGroupName, serverName, elasticPoolName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets a list of databases in an elastic pool.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} elasticPoolName The name of the elastic pool.
   *
   * @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 {DatabaseListResult} - 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 DatabaseListResult} 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.
   */
  listByElasticPool(resourceGroupName, serverName, elasticPoolName, 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._listByElasticPool(resourceGroupName, serverName, elasticPoolName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByElasticPool(resourceGroupName, serverName, elasticPoolName, options, optionalCallback);
    }
  }

  /**
   * Pauses a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be paused.
   *
   * @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<Database>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  pauseWithHttpOperationResponse(resourceGroupName, serverName, databaseName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._pause(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Pauses a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be paused.
   *
   * @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 {Database} - 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 Database} 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.
   */
  pause(resourceGroupName, serverName, databaseName, 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._pause(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._pause(resourceGroupName, serverName, databaseName, options, optionalCallback);
    }
  }

  /**
   * Resumes a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be resumed.
   *
   * @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<Database>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  resumeWithHttpOperationResponse(resourceGroupName, serverName, databaseName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._resume(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Resumes a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be resumed.
   *
   * @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 {Database} - 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 Database} 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.
   */
  resume(resourceGroupName, serverName, databaseName, 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._resume(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._resume(resourceGroupName, serverName, databaseName, options, optionalCallback);
    }
  }

  /**
   * Renames a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to rename.
   *
   * @param {object} parameters The resource move definition for renaming this
   * database.
   *
   * @param {string} parameters.id The target ID for the resource
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  renameWithHttpOperationResponse(resourceGroupName, serverName, databaseName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._rename(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Renames a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to rename.
   *
   * @param {object} parameters The resource move definition for renaming this
   * database.
   *
   * @param {string} parameters.id The target ID for the resource
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {null} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  rename(resourceGroupName, serverName, databaseName, 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._rename(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._rename(resourceGroupName, serverName, databaseName, parameters, options, optionalCallback);
    }
  }

  /**
   * Imports a bacpac into a new database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {object} parameters The required parameters for importing a Bacpac
   * into a database.
   *
   * @param {string} parameters.databaseName The name of the database to import.
   *
   * @param {string} parameters.edition The edition for the database being
   * created. Possible values include: 'Web', 'Business', 'Basic', 'Standard',
   * 'Premium', 'PremiumRS', 'Free', 'Stretch', 'DataWarehouse', 'System',
   * 'System2'
   *
   * @param {string} parameters.serviceObjectiveName The name of the service
   * objective to assign to the database. Possible values include: 'System',
   * 'System0', 'System1', 'System2', 'System3', 'System4', 'System2L',
   * 'System3L', 'System4L', 'Free', 'Basic', 'S0', 'S1', 'S2', 'S3', 'S4', 'S6',
   * 'S7', 'S9', 'S12', 'P1', 'P2', 'P3', 'P4', 'P6', 'P11', 'P15', 'PRS1',
   * 'PRS2', 'PRS4', 'PRS6', 'DW100', 'DW200', 'DW300', 'DW400', 'DW500',
   * 'DW600', 'DW1000', 'DW1200', 'DW1000c', 'DW1500', 'DW1500c', 'DW2000',
   * 'DW2000c', 'DW3000', 'DW2500c', 'DW3000c', 'DW6000', 'DW5000c', 'DW6000c',
   * 'DW7500c', 'DW10000c', 'DW15000c', 'DW30000c', 'DS100', 'DS200', 'DS300',
   * 'DS400', 'DS500', 'DS600', 'DS1000', 'DS1200', 'DS1500', 'DS2000',
   * 'ElasticPool'
   *
   * @param {string} parameters.maxSizeBytes The maximum size for the newly
   * imported database.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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<ImportExportResponse>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginImportMethodWithHttpOperationResponse(resourceGroupName, serverName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginImportMethod(resourceGroupName, serverName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Imports a bacpac into a new database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {object} parameters The required parameters for importing a Bacpac
   * into a database.
   *
   * @param {string} parameters.databaseName The name of the database to import.
   *
   * @param {string} parameters.edition The edition for the database being
   * created. Possible values include: 'Web', 'Business', 'Basic', 'Standard',
   * 'Premium', 'PremiumRS', 'Free', 'Stretch', 'DataWarehouse', 'System',
   * 'System2'
   *
   * @param {string} parameters.serviceObjectiveName The name of the service
   * objective to assign to the database. Possible values include: 'System',
   * 'System0', 'System1', 'System2', 'System3', 'System4', 'System2L',
   * 'System3L', 'System4L', 'Free', 'Basic', 'S0', 'S1', 'S2', 'S3', 'S4', 'S6',
   * 'S7', 'S9', 'S12', 'P1', 'P2', 'P3', 'P4', 'P6', 'P11', 'P15', 'PRS1',
   * 'PRS2', 'PRS4', 'PRS6', 'DW100', 'DW200', 'DW300', 'DW400', 'DW500',
   * 'DW600', 'DW1000', 'DW1200', 'DW1000c', 'DW1500', 'DW1500c', 'DW2000',
   * 'DW2000c', 'DW3000', 'DW2500c', 'DW3000c', 'DW6000', 'DW5000c', 'DW6000c',
   * 'DW7500c', 'DW10000c', 'DW15000c', 'DW30000c', 'DS100', 'DS200', 'DS300',
   * 'DS400', 'DS500', 'DS600', 'DS1000', 'DS1200', 'DS1500', 'DS2000',
   * 'ElasticPool'
   *
   * @param {string} parameters.maxSizeBytes The maximum size for the newly
   * imported database.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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 {ImportExportResponse} - 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 ImportExportResponse} 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.
   */
  beginImportMethod(resourceGroupName, serverName, 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._beginImportMethod(resourceGroupName, serverName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginImportMethod(resourceGroupName, serverName, parameters, options, optionalCallback);
    }
  }

  /**
   * Creates an import operation that imports a bacpac into an existing database.
   * The existing database must be empty.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to import into
   *
   * @param {object} parameters The required parameters for importing a Bacpac
   * into a database.
   *
   * @param {string} [parameters.name] The name of the extension.
   *
   * @param {string} [parameters.type] The type of the extension.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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<ImportExportResponse>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginCreateImportOperationWithHttpOperationResponse(resourceGroupName, serverName, databaseName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginCreateImportOperation(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates an import operation that imports a bacpac into an existing database.
   * The existing database must be empty.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to import into
   *
   * @param {object} parameters The required parameters for importing a Bacpac
   * into a database.
   *
   * @param {string} [parameters.name] The name of the extension.
   *
   * @param {string} [parameters.type] The type of the extension.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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 {ImportExportResponse} - 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 ImportExportResponse} 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.
   */
  beginCreateImportOperation(resourceGroupName, serverName, databaseName, 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._beginCreateImportOperation(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginCreateImportOperation(resourceGroupName, serverName, databaseName, parameters, options, optionalCallback);
    }
  }

  /**
   * Exports a database to a bacpac.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be exported.
   *
   * @param {object} parameters The required parameters for exporting a database.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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<ImportExportResponse>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginExportMethodWithHttpOperationResponse(resourceGroupName, serverName, databaseName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginExportMethod(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Exports a database to a bacpac.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be exported.
   *
   * @param {object} parameters The required parameters for exporting a database.
   *
   * @param {string} parameters.storageKeyType The type of the storage key to
   * use. Possible values include: 'StorageAccessKey', 'SharedAccessKey'
   *
   * @param {string} parameters.storageKey The storage key to use.  If storage
   * key type is SharedAccessKey, it must be preceded with a "?."
   *
   * @param {string} parameters.storageUri The storage uri to use.
   *
   * @param {string} parameters.administratorLogin The name of the SQL
   * administrator.
   *
   * @param {string} parameters.administratorLoginPassword The password of the
   * SQL administrator.
   *
   * @param {string} [parameters.authenticationType] The authentication type.
   * Possible values include: 'SQL', 'ADPassword'
   *
   * @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 {ImportExportResponse} - 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 ImportExportResponse} 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.
   */
  beginExportMethod(resourceGroupName, serverName, databaseName, 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._beginExportMethod(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginExportMethod(resourceGroupName, serverName, databaseName, parameters, options, optionalCallback);
    }
  }

  /**
   * Upgrades a data warehouse.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be upgraded.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginUpgradeDataWarehouseWithHttpOperationResponse(resourceGroupName, serverName, databaseName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginUpgradeDataWarehouse(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Upgrades a data warehouse.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be upgraded.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {null} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  beginUpgradeDataWarehouse(resourceGroupName, serverName, databaseName, 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._beginUpgradeDataWarehouse(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginUpgradeDataWarehouse(resourceGroupName, serverName, databaseName, options, optionalCallback);
    }
  }

  /**
   * Creates a new database or updates an existing database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} parameters The requested database resource state.
   *
   * @param {object} [parameters.sku] The name and tier of the SKU.
   *
   * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
   * typically a letter+number code
   *
   * @param {string} [parameters.sku.tier] This field is required to be
   * implemented by the Resource Provider if the service has more than one tier,
   * but is not required on a PUT.
   *
   * @param {string} [parameters.sku.size] The SKU size. When the name field is
   * the combination of tier and some other value, this would be the standalone
   * code.
   *
   * @param {string} [parameters.sku.family] If the service has different
   * generations of hardware, for the same SKU, then that can be captured here.
   *
   * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
   * then the capacity integer should be included. If scale out/in is not
   * possible for the resource this may be omitted.
   *
   * @param {string} [parameters.createMode] Specifies the mode of database
   * creation.
   *
   * Default: regular database creation.
   *
   * Copy: creates a database as a copy of an existing database. sourceDatabaseId
   * must be specified as the resource ID of the source database.
   *
   * Secondary: creates a database as a secondary replica of an existing
   * database. sourceDatabaseId must be specified as the resource ID of the
   * existing primary database.
   *
   * PointInTimeRestore: Creates a database by restoring a point in time backup
   * of an existing database. sourceDatabaseId must be specified as the resource
   * ID of the existing database, and restorePointInTime must be specified.
   *
   * Recovery: Creates a database by restoring a geo-replicated backup.
   * sourceDatabaseId must be specified as the recoverable database resource ID
   * to restore.
   *
   * Restore: Creates a database by restoring a backup of a deleted database.
   * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
   * original resource ID, then sourceDatabaseDeletionDate must be specified.
   * Otherwise sourceDatabaseId must be the restorable dropped database resource
   * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
   * specified to restore from an earlier point in time.
   *
   * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
   * term retention vault. recoveryServicesRecoveryPointResourceId must be
   * specified as the recovery point resource ID.
   *
   * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
   * DataWarehouse edition. Possible values include: 'Default', 'Copy',
   * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
   * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
   * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
   *
   * @param {string} [parameters.collation] The collation of the database.
   *
   * @param {number} [parameters.maxSizeBytes] The max size of the database
   * expressed in bytes.
   *
   * @param {string} [parameters.sampleName] The name of the sample schema to
   * apply when creating this database. Possible values include:
   * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
   *
   * @param {string} [parameters.elasticPoolId] The resource identifier of the
   * elastic pool containing this database.
   *
   * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
   * source database associated with create operation of this database.
   *
   * @param {date} [parameters.restorePointInTime] Specifies the point in time
   * (ISO8601 format) of the source database that will be restored to create the
   * new database.
   *
   * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
   * that the database was deleted.
   *
   * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
   * identifier of the recovery point associated with create operation of this
   * database.
   *
   * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
   * identifier of the long term retention backup associated with create
   * operation of this database.
   *
   * @param {string} [parameters.recoverableDatabaseId] The resource identifier
   * of the recoverable database associated with create operation of this
   * database.
   *
   * @param {string} [parameters.restorableDroppedDatabaseId] The resource
   * identifier of the restorable dropped database associated with create
   * operation of this database.
   *
   * @param {string} [parameters.catalogCollation] Collation of the metadata
   * catalog. Possible values include: 'DATABASE_DEFAULT',
   * 'SQL_Latin1_General_CP1_CI_AS'
   *
   * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
   * zone redundant, which means the replicas of this database will be spread
   * across multiple availability zones.
   *
   * @param {string} [parameters.licenseType] The license type to apply for this
   * database. Possible values include: 'LicenseIncluded', 'BasePrice'
   *
   * @param {string} [parameters.readScale] The state of read-only routing. If
   * enabled, connections that have application intent set to readonly in their
   * connection string may be routed to a readonly secondary replica in the same
   * region. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {string} parameters.location Resource location.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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<Database>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginCreateOrUpdateWithHttpOperationResponse(resourceGroupName, serverName, databaseName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginCreateOrUpdate(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Creates a new database or updates an existing database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} parameters The requested database resource state.
   *
   * @param {object} [parameters.sku] The name and tier of the SKU.
   *
   * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
   * typically a letter+number code
   *
   * @param {string} [parameters.sku.tier] This field is required to be
   * implemented by the Resource Provider if the service has more than one tier,
   * but is not required on a PUT.
   *
   * @param {string} [parameters.sku.size] The SKU size. When the name field is
   * the combination of tier and some other value, this would be the standalone
   * code.
   *
   * @param {string} [parameters.sku.family] If the service has different
   * generations of hardware, for the same SKU, then that can be captured here.
   *
   * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
   * then the capacity integer should be included. If scale out/in is not
   * possible for the resource this may be omitted.
   *
   * @param {string} [parameters.createMode] Specifies the mode of database
   * creation.
   *
   * Default: regular database creation.
   *
   * Copy: creates a database as a copy of an existing database. sourceDatabaseId
   * must be specified as the resource ID of the source database.
   *
   * Secondary: creates a database as a secondary replica of an existing
   * database. sourceDatabaseId must be specified as the resource ID of the
   * existing primary database.
   *
   * PointInTimeRestore: Creates a database by restoring a point in time backup
   * of an existing database. sourceDatabaseId must be specified as the resource
   * ID of the existing database, and restorePointInTime must be specified.
   *
   * Recovery: Creates a database by restoring a geo-replicated backup.
   * sourceDatabaseId must be specified as the recoverable database resource ID
   * to restore.
   *
   * Restore: Creates a database by restoring a backup of a deleted database.
   * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
   * original resource ID, then sourceDatabaseDeletionDate must be specified.
   * Otherwise sourceDatabaseId must be the restorable dropped database resource
   * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
   * specified to restore from an earlier point in time.
   *
   * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
   * term retention vault. recoveryServicesRecoveryPointResourceId must be
   * specified as the recovery point resource ID.
   *
   * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
   * DataWarehouse edition. Possible values include: 'Default', 'Copy',
   * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
   * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
   * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
   *
   * @param {string} [parameters.collation] The collation of the database.
   *
   * @param {number} [parameters.maxSizeBytes] The max size of the database
   * expressed in bytes.
   *
   * @param {string} [parameters.sampleName] The name of the sample schema to
   * apply when creating this database. Possible values include:
   * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
   *
   * @param {string} [parameters.elasticPoolId] The resource identifier of the
   * elastic pool containing this database.
   *
   * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
   * source database associated with create operation of this database.
   *
   * @param {date} [parameters.restorePointInTime] Specifies the point in time
   * (ISO8601 format) of the source database that will be restored to create the
   * new database.
   *
   * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
   * that the database was deleted.
   *
   * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
   * identifier of the recovery point associated with create operation of this
   * database.
   *
   * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
   * identifier of the long term retention backup associated with create
   * operation of this database.
   *
   * @param {string} [parameters.recoverableDatabaseId] The resource identifier
   * of the recoverable database associated with create operation of this
   * database.
   *
   * @param {string} [parameters.restorableDroppedDatabaseId] The resource
   * identifier of the restorable dropped database associated with create
   * operation of this database.
   *
   * @param {string} [parameters.catalogCollation] Collation of the metadata
   * catalog. Possible values include: 'DATABASE_DEFAULT',
   * 'SQL_Latin1_General_CP1_CI_AS'
   *
   * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
   * zone redundant, which means the replicas of this database will be spread
   * across multiple availability zones.
   *
   * @param {string} [parameters.licenseType] The license type to apply for this
   * database. Possible values include: 'LicenseIncluded', 'BasePrice'
   *
   * @param {string} [parameters.readScale] The state of read-only routing. If
   * enabled, connections that have application intent set to readonly in their
   * connection string may be routed to a readonly secondary replica in the same
   * region. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {string} parameters.location Resource location.
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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 {Database} - 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 Database} 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.
   */
  beginCreateOrUpdate(resourceGroupName, serverName, databaseName, 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._beginCreateOrUpdate(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginCreateOrUpdate(resourceGroupName, serverName, databaseName, parameters, options, optionalCallback);
    }
  }

  /**
   * Deletes the database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @returns {Promise} A promise is returned
   *
   * @resolve {HttpOperationResponse<null>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginDeleteMethodWithHttpOperationResponse(resourceGroupName, serverName, databaseName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginDeleteMethod(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Deletes the database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} [options] Optional Parameters.
   *
   * @param {object} [options.customHeaders] Headers that will be added to the
   * request
   *
   * @param {function} [optionalCallback] - The optional callback.
   *
   * @returns {function|Promise} If a callback was passed as the last parameter
   * then it returns the callback else returns a Promise.
   *
   * {Promise} A promise is returned
   *
   *                      @resolve {null} - The deserialized result object.
   *
   *                      @reject {Error} - The error object.
   *
   * {function} optionalCallback(err, result, request, response)
   *
   *                      {Error}  err        - The Error object if an error occurred, null otherwise.
   *
   *                      {null} [result]   - The deserialized result object if an error did not occur.
   *
   *                      {object} [request]  - The HTTP Request object if an error did not occur.
   *
   *                      {stream} [response] - The HTTP Response stream if an error did not occur.
   */
  beginDeleteMethod(resourceGroupName, serverName, databaseName, 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._beginDeleteMethod(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginDeleteMethod(resourceGroupName, serverName, databaseName, options, optionalCallback);
    }
  }

  /**
   * Updates an existing database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} parameters The requested database resource state.
   *
   * @param {object} [parameters.sku] The name and tier of the SKU.
   *
   * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
   * typically a letter+number code
   *
   * @param {string} [parameters.sku.tier] This field is required to be
   * implemented by the Resource Provider if the service has more than one tier,
   * but is not required on a PUT.
   *
   * @param {string} [parameters.sku.size] The SKU size. When the name field is
   * the combination of tier and some other value, this would be the standalone
   * code.
   *
   * @param {string} [parameters.sku.family] If the service has different
   * generations of hardware, for the same SKU, then that can be captured here.
   *
   * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
   * then the capacity integer should be included. If scale out/in is not
   * possible for the resource this may be omitted.
   *
   * @param {string} [parameters.createMode] Specifies the mode of database
   * creation.
   *
   * Default: regular database creation.
   *
   * Copy: creates a database as a copy of an existing database. sourceDatabaseId
   * must be specified as the resource ID of the source database.
   *
   * Secondary: creates a database as a secondary replica of an existing
   * database. sourceDatabaseId must be specified as the resource ID of the
   * existing primary database.
   *
   * PointInTimeRestore: Creates a database by restoring a point in time backup
   * of an existing database. sourceDatabaseId must be specified as the resource
   * ID of the existing database, and restorePointInTime must be specified.
   *
   * Recovery: Creates a database by restoring a geo-replicated backup.
   * sourceDatabaseId must be specified as the recoverable database resource ID
   * to restore.
   *
   * Restore: Creates a database by restoring a backup of a deleted database.
   * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
   * original resource ID, then sourceDatabaseDeletionDate must be specified.
   * Otherwise sourceDatabaseId must be the restorable dropped database resource
   * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
   * specified to restore from an earlier point in time.
   *
   * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
   * term retention vault. recoveryServicesRecoveryPointResourceId must be
   * specified as the recovery point resource ID.
   *
   * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
   * DataWarehouse edition. Possible values include: 'Default', 'Copy',
   * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
   * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
   * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
   *
   * @param {string} [parameters.collation] The collation of the database.
   *
   * @param {number} [parameters.maxSizeBytes] The max size of the database
   * expressed in bytes.
   *
   * @param {string} [parameters.sampleName] The name of the sample schema to
   * apply when creating this database. Possible values include:
   * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
   *
   * @param {string} [parameters.elasticPoolId] The resource identifier of the
   * elastic pool containing this database.
   *
   * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
   * source database associated with create operation of this database.
   *
   * @param {date} [parameters.restorePointInTime] Specifies the point in time
   * (ISO8601 format) of the source database that will be restored to create the
   * new database.
   *
   * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
   * that the database was deleted.
   *
   * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
   * identifier of the recovery point associated with create operation of this
   * database.
   *
   * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
   * identifier of the long term retention backup associated with create
   * operation of this database.
   *
   * @param {string} [parameters.recoverableDatabaseId] The resource identifier
   * of the recoverable database associated with create operation of this
   * database.
   *
   * @param {string} [parameters.restorableDroppedDatabaseId] The resource
   * identifier of the restorable dropped database associated with create
   * operation of this database.
   *
   * @param {string} [parameters.catalogCollation] Collation of the metadata
   * catalog. Possible values include: 'DATABASE_DEFAULT',
   * 'SQL_Latin1_General_CP1_CI_AS'
   *
   * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
   * zone redundant, which means the replicas of this database will be spread
   * across multiple availability zones.
   *
   * @param {string} [parameters.licenseType] The license type to apply for this
   * database. Possible values include: 'LicenseIncluded', 'BasePrice'
   *
   * @param {string} [parameters.readScale] The state of read-only routing. If
   * enabled, connections that have application intent set to readonly in their
   * connection string may be routed to a readonly secondary replica in the same
   * region. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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<Database>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginUpdateWithHttpOperationResponse(resourceGroupName, serverName, databaseName, parameters, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginUpdate(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Updates an existing database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database.
   *
   * @param {object} parameters The requested database resource state.
   *
   * @param {object} [parameters.sku] The name and tier of the SKU.
   *
   * @param {string} parameters.sku.name The name of the SKU. Ex - P3. It is
   * typically a letter+number code
   *
   * @param {string} [parameters.sku.tier] This field is required to be
   * implemented by the Resource Provider if the service has more than one tier,
   * but is not required on a PUT.
   *
   * @param {string} [parameters.sku.size] The SKU size. When the name field is
   * the combination of tier and some other value, this would be the standalone
   * code.
   *
   * @param {string} [parameters.sku.family] If the service has different
   * generations of hardware, for the same SKU, then that can be captured here.
   *
   * @param {number} [parameters.sku.capacity] If the SKU supports scale out/in
   * then the capacity integer should be included. If scale out/in is not
   * possible for the resource this may be omitted.
   *
   * @param {string} [parameters.createMode] Specifies the mode of database
   * creation.
   *
   * Default: regular database creation.
   *
   * Copy: creates a database as a copy of an existing database. sourceDatabaseId
   * must be specified as the resource ID of the source database.
   *
   * Secondary: creates a database as a secondary replica of an existing
   * database. sourceDatabaseId must be specified as the resource ID of the
   * existing primary database.
   *
   * PointInTimeRestore: Creates a database by restoring a point in time backup
   * of an existing database. sourceDatabaseId must be specified as the resource
   * ID of the existing database, and restorePointInTime must be specified.
   *
   * Recovery: Creates a database by restoring a geo-replicated backup.
   * sourceDatabaseId must be specified as the recoverable database resource ID
   * to restore.
   *
   * Restore: Creates a database by restoring a backup of a deleted database.
   * sourceDatabaseId must be specified. If sourceDatabaseId is the database's
   * original resource ID, then sourceDatabaseDeletionDate must be specified.
   * Otherwise sourceDatabaseId must be the restorable dropped database resource
   * ID and sourceDatabaseDeletionDate is ignored. restorePointInTime may also be
   * specified to restore from an earlier point in time.
   *
   * RestoreLongTermRetentionBackup: Creates a database by restoring from a long
   * term retention vault. recoveryServicesRecoveryPointResourceId must be
   * specified as the recovery point resource ID.
   *
   * Copy, Secondary, and RestoreLongTermRetentionBackup are not supported for
   * DataWarehouse edition. Possible values include: 'Default', 'Copy',
   * 'Secondary', 'PointInTimeRestore', 'Restore', 'Recovery',
   * 'RestoreExternalBackup', 'RestoreExternalBackupSecondary',
   * 'RestoreLongTermRetentionBackup', 'OnlineSecondary'
   *
   * @param {string} [parameters.collation] The collation of the database.
   *
   * @param {number} [parameters.maxSizeBytes] The max size of the database
   * expressed in bytes.
   *
   * @param {string} [parameters.sampleName] The name of the sample schema to
   * apply when creating this database. Possible values include:
   * 'AdventureWorksLT', 'WideWorldImportersStd', 'WideWorldImportersFull'
   *
   * @param {string} [parameters.elasticPoolId] The resource identifier of the
   * elastic pool containing this database.
   *
   * @param {string} [parameters.sourceDatabaseId] The resource identifier of the
   * source database associated with create operation of this database.
   *
   * @param {date} [parameters.restorePointInTime] Specifies the point in time
   * (ISO8601 format) of the source database that will be restored to create the
   * new database.
   *
   * @param {date} [parameters.sourceDatabaseDeletionDate] Specifies the time
   * that the database was deleted.
   *
   * @param {string} [parameters.recoveryServicesRecoveryPointId] The resource
   * identifier of the recovery point associated with create operation of this
   * database.
   *
   * @param {string} [parameters.longTermRetentionBackupResourceId] The resource
   * identifier of the long term retention backup associated with create
   * operation of this database.
   *
   * @param {string} [parameters.recoverableDatabaseId] The resource identifier
   * of the recoverable database associated with create operation of this
   * database.
   *
   * @param {string} [parameters.restorableDroppedDatabaseId] The resource
   * identifier of the restorable dropped database associated with create
   * operation of this database.
   *
   * @param {string} [parameters.catalogCollation] Collation of the metadata
   * catalog. Possible values include: 'DATABASE_DEFAULT',
   * 'SQL_Latin1_General_CP1_CI_AS'
   *
   * @param {boolean} [parameters.zoneRedundant] Whether or not this database is
   * zone redundant, which means the replicas of this database will be spread
   * across multiple availability zones.
   *
   * @param {string} [parameters.licenseType] The license type to apply for this
   * database. Possible values include: 'LicenseIncluded', 'BasePrice'
   *
   * @param {string} [parameters.readScale] The state of read-only routing. If
   * enabled, connections that have application intent set to readonly in their
   * connection string may be routed to a readonly secondary replica in the same
   * region. Possible values include: 'Enabled', 'Disabled'
   *
   * @param {object} [parameters.tags] Resource tags.
   *
   * @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 {Database} - 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 Database} 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.
   */
  beginUpdate(resourceGroupName, serverName, databaseName, 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._beginUpdate(resourceGroupName, serverName, databaseName, parameters, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginUpdate(resourceGroupName, serverName, databaseName, parameters, options, optionalCallback);
    }
  }

  /**
   * Pauses a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be paused.
   *
   * @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<Database>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginPauseWithHttpOperationResponse(resourceGroupName, serverName, databaseName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginPause(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Pauses a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be paused.
   *
   * @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 {Database} - 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 Database} 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.
   */
  beginPause(resourceGroupName, serverName, databaseName, 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._beginPause(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginPause(resourceGroupName, serverName, databaseName, options, optionalCallback);
    }
  }

  /**
   * Resumes a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be resumed.
   *
   * @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<Database>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  beginResumeWithHttpOperationResponse(resourceGroupName, serverName, databaseName, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._beginResume(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Resumes a database.
   *
   * @param {string} resourceGroupName The name of the resource group that
   * contains the resource. You can obtain this value from the Azure Resource
   * Manager API or the portal.
   *
   * @param {string} serverName The name of the server.
   *
   * @param {string} databaseName The name of the database to be resumed.
   *
   * @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 {Database} - 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 Database} 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.
   */
  beginResume(resourceGroupName, serverName, databaseName, 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._beginResume(resourceGroupName, serverName, databaseName, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._beginResume(resourceGroupName, serverName, databaseName, options, optionalCallback);
    }
  }

  /**
   * Gets a list of databases.
   *
   * @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<DatabaseListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByServerNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByServerNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets a list of databases.
   *
   * @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 {DatabaseListResult} - 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 DatabaseListResult} 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.
   */
  listByServerNext(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._listByServerNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByServerNext(nextPageLink, options, optionalCallback);
    }
  }

  /**
   * Gets a list of databases in an elastic pool.
   *
   * @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<DatabaseListResult>} - The deserialized result object.
   *
   * @reject {Error} - The error object.
   */
  listByElasticPoolNextWithHttpOperationResponse(nextPageLink, options) {
    let client = this.client;
    let self = this;
    return new Promise((resolve, reject) => {
      self._listByElasticPoolNext(nextPageLink, options, (err, result, request, response) => {
        let httpOperationResponse = new msRest.HttpOperationResponse(request, response);
        httpOperationResponse.body = result;
        if (err) { reject(err); }
        else { resolve(httpOperationResponse); }
        return;
      });
    });
  }

  /**
   * Gets a list of databases in an elastic pool.
   *
   * @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 {DatabaseListResult} - 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 DatabaseListResult} 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.
   */
  listByElasticPoolNext(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._listByElasticPoolNext(nextPageLink, options, (err, result, request, response) => {
          if (err) { reject(err); }
          else { resolve(result); }
          return;
        });
      });
    } else {
      return self._listByElasticPoolNext(nextPageLink, options, optionalCallback);
    }
  }

}

module.exports = Databases;
