"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.DatabasesImpl = void 0;
const tslib_1 = require("tslib");
const pagingHelper_js_1 = require("../pagingHelper.js");
const coreClient = tslib_1.__importStar(require("@azure/core-client"));
const Mappers = tslib_1.__importStar(require("../models/mappers.js"));
const Parameters = tslib_1.__importStar(require("../models/parameters.js"));
const core_lro_1 = require("@azure/core-lro");
const lroImpl_js_1 = require("../lroImpl.js");
/// <reference lib="esnext.asynciterable" />
/** Class containing Databases operations. */
class DatabasesImpl {
    client;
    /**
     * Initialize a new instance of the class Databases class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Returns database metrics.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param filter An OData filter expression that describes a subset of metrics to return.
     * @param options The options parameters.
     */
    listMetrics(resourceGroupName, serverName, databaseName, filter, options) {
        const iter = this.listMetricsPagingAll(resourceGroupName, serverName, databaseName, filter, options);
        return {
            next() {
                return iter.next();
            },
            [Symbol.asyncIterator]() {
                return this;
            },
            byPage: (settings) => {
                if (settings?.maxPageSize) {
                    throw new Error("maxPageSize is not supported by this operation.");
                }
                return this.listMetricsPagingPage(resourceGroupName, serverName, databaseName, filter, options, settings);
            },
        };
    }
    async *listMetricsPagingPage(resourceGroupName, serverName, databaseName, filter, options, _settings) {
        let result;
        result = await this._listMetrics(resourceGroupName, serverName, databaseName, filter, options);
        yield result.value || [];
    }
    async *listMetricsPagingAll(resourceGroupName, serverName, databaseName, filter, options) {
        for await (const page of this.listMetricsPagingPage(resourceGroupName, serverName, databaseName, filter, options)) {
            yield* page;
        }
    }
    /**
     * Returns database metric definitions.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param options The options parameters.
     */
    listMetricDefinitions(resourceGroupName, serverName, databaseName, options) {
        const iter = this.listMetricDefinitionsPagingAll(resourceGroupName, serverName, databaseName, options);
        return {
            next() {
                return iter.next();
            },
            [Symbol.asyncIterator]() {
                return this;
            },
            byPage: (settings) => {
                if (settings?.maxPageSize) {
                    throw new Error("maxPageSize is not supported by this operation.");
                }
                return this.listMetricDefinitionsPagingPage(resourceGroupName, serverName, databaseName, options, settings);
            },
        };
    }
    async *listMetricDefinitionsPagingPage(resourceGroupName, serverName, databaseName, options, _settings) {
        let result;
        result = await this._listMetricDefinitions(resourceGroupName, serverName, databaseName, options);
        yield result.value || [];
    }
    async *listMetricDefinitionsPagingAll(resourceGroupName, serverName, databaseName, options) {
        for await (const page of this.listMetricDefinitionsPagingPage(resourceGroupName, serverName, databaseName, options)) {
            yield* page;
        }
    }
    /**
     * Gets a list of databases.
     * @param 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 serverName The name of the server.
     * @param options The options parameters.
     */
    listByServer(resourceGroupName, serverName, options) {
        const iter = this.listByServerPagingAll(resourceGroupName, serverName, options);
        return {
            next() {
                return iter.next();
            },
            [Symbol.asyncIterator]() {
                return this;
            },
            byPage: (settings) => {
                if (settings?.maxPageSize) {
                    throw new Error("maxPageSize is not supported by this operation.");
                }
                return this.listByServerPagingPage(resourceGroupName, serverName, options, settings);
            },
        };
    }
    async *listByServerPagingPage(resourceGroupName, serverName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByServer(resourceGroupName, serverName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByServerNext(resourceGroupName, serverName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *listByServerPagingAll(resourceGroupName, serverName, options) {
        for await (const page of this.listByServerPagingPage(resourceGroupName, serverName, options)) {
            yield* page;
        }
    }
    /**
     * Gets a list of databases in an elastic pool.
     * @param 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 serverName The name of the server.
     * @param elasticPoolName The name of the elastic pool.
     * @param options The options parameters.
     */
    listByElasticPool(resourceGroupName, serverName, elasticPoolName, options) {
        const iter = this.listByElasticPoolPagingAll(resourceGroupName, serverName, elasticPoolName, options);
        return {
            next() {
                return iter.next();
            },
            [Symbol.asyncIterator]() {
                return this;
            },
            byPage: (settings) => {
                if (settings?.maxPageSize) {
                    throw new Error("maxPageSize is not supported by this operation.");
                }
                return this.listByElasticPoolPagingPage(resourceGroupName, serverName, elasticPoolName, options, settings);
            },
        };
    }
    async *listByElasticPoolPagingPage(resourceGroupName, serverName, elasticPoolName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByElasticPool(resourceGroupName, serverName, elasticPoolName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByElasticPoolNext(resourceGroupName, serverName, elasticPoolName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *listByElasticPoolPagingAll(resourceGroupName, serverName, elasticPoolName, options) {
        for await (const page of this.listByElasticPoolPagingPage(resourceGroupName, serverName, elasticPoolName, options)) {
            yield* page;
        }
    }
    /**
     * Gets a list of inaccessible databases in a logical server
     * @param 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 serverName The name of the server.
     * @param options The options parameters.
     */
    listInaccessibleByServer(resourceGroupName, serverName, options) {
        const iter = this.listInaccessibleByServerPagingAll(resourceGroupName, serverName, options);
        return {
            next() {
                return iter.next();
            },
            [Symbol.asyncIterator]() {
                return this;
            },
            byPage: (settings) => {
                if (settings?.maxPageSize) {
                    throw new Error("maxPageSize is not supported by this operation.");
                }
                return this.listInaccessibleByServerPagingPage(resourceGroupName, serverName, options, settings);
            },
        };
    }
    async *listInaccessibleByServerPagingPage(resourceGroupName, serverName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listInaccessibleByServer(resourceGroupName, serverName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listInaccessibleByServerNext(resourceGroupName, serverName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *listInaccessibleByServerPagingAll(resourceGroupName, serverName, options) {
        for await (const page of this.listInaccessibleByServerPagingPage(resourceGroupName, serverName, options)) {
            yield* page;
        }
    }
    /**
     * Returns database metrics.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param filter An OData filter expression that describes a subset of metrics to return.
     * @param options The options parameters.
     */
    _listMetrics(resourceGroupName, serverName, databaseName, filter, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, databaseName, filter, options }, listMetricsOperationSpec);
    }
    /**
     * Returns database metric definitions.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param options The options parameters.
     */
    _listMetricDefinitions(resourceGroupName, serverName, databaseName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, databaseName, options }, listMetricDefinitionsOperationSpec);
    }
    /**
     * Gets a list of databases.
     * @param 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 serverName The name of the server.
     * @param options The options parameters.
     */
    _listByServer(resourceGroupName, serverName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, options }, listByServerOperationSpec);
    }
    /**
     * Gets a database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param options The options parameters.
     */
    get(resourceGroupName, serverName, databaseName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, databaseName, options }, getOperationSpec);
    }
    /**
     * Creates a new database or updates an existing database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param parameters The requested database resource state.
     * @param options The options parameters.
     */
    async beginCreateOrUpdate(resourceGroupName, serverName, databaseName, parameters, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: {
                resourceGroupName,
                serverName,
                databaseName,
                parameters,
                options,
            },
            spec: createOrUpdateOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
            resourceLocationConfig: "azure-async-operation",
        });
        await poller.poll();
        return poller;
    }
    /**
     * Creates a new database or updates an existing database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param parameters The requested database resource state.
     * @param options The options parameters.
     */
    async beginCreateOrUpdateAndWait(resourceGroupName, serverName, databaseName, parameters, options) {
        const poller = await this.beginCreateOrUpdate(resourceGroupName, serverName, databaseName, parameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Deletes the database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param options The options parameters.
     */
    async beginDelete(resourceGroupName, serverName, databaseName, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: { resourceGroupName, serverName, databaseName, options },
            spec: deleteOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
            resourceLocationConfig: "location",
        });
        await poller.poll();
        return poller;
    }
    /**
     * Deletes the database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param options The options parameters.
     */
    async beginDeleteAndWait(resourceGroupName, serverName, databaseName, options) {
        const poller = await this.beginDelete(resourceGroupName, serverName, databaseName, options);
        return poller.pollUntilDone();
    }
    /**
     * Updates an existing database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param parameters The requested database resource state.
     * @param options The options parameters.
     */
    async beginUpdate(resourceGroupName, serverName, databaseName, parameters, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: {
                resourceGroupName,
                serverName,
                databaseName,
                parameters,
                options,
            },
            spec: updateOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
            resourceLocationConfig: "location",
        });
        await poller.poll();
        return poller;
    }
    /**
     * Updates an existing database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param parameters The requested database resource state.
     * @param options The options parameters.
     */
    async beginUpdateAndWait(resourceGroupName, serverName, databaseName, parameters, options) {
        const poller = await this.beginUpdate(resourceGroupName, serverName, databaseName, parameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Exports a database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param parameters The database export request parameters.
     * @param options The options parameters.
     */
    async beginExport(resourceGroupName, serverName, databaseName, parameters, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: {
                resourceGroupName,
                serverName,
                databaseName,
                parameters,
                options,
            },
            spec: exportOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Exports a database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param parameters The database export request parameters.
     * @param options The options parameters.
     */
    async beginExportAndWait(resourceGroupName, serverName, databaseName, parameters, options) {
        const poller = await this.beginExport(resourceGroupName, serverName, databaseName, parameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Failovers a database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database to failover.
     * @param options The options parameters.
     */
    async beginFailover(resourceGroupName, serverName, databaseName, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: { resourceGroupName, serverName, databaseName, options },
            spec: failoverOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Failovers a database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database to failover.
     * @param options The options parameters.
     */
    async beginFailoverAndWait(resourceGroupName, serverName, databaseName, options) {
        const poller = await this.beginFailover(resourceGroupName, serverName, databaseName, options);
        return poller.pollUntilDone();
    }
    /**
     * Imports a bacpac into a new database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param parameters The database import request parameters.
     * @param options The options parameters.
     */
    async beginImport(resourceGroupName, serverName, databaseName, parameters, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: {
                resourceGroupName,
                serverName,
                databaseName,
                parameters,
                options,
            },
            spec: importOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Imports a bacpac into a new database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database.
     * @param parameters The database import request parameters.
     * @param options The options parameters.
     */
    async beginImportAndWait(resourceGroupName, serverName, databaseName, parameters, options) {
        const poller = await this.beginImport(resourceGroupName, serverName, databaseName, parameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Renames a database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database to rename.
     * @param parameters The resource move definition for renaming this database.
     * @param options The options parameters.
     */
    rename(resourceGroupName, serverName, databaseName, parameters, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, databaseName, parameters, options }, renameOperationSpec);
    }
    /**
     * Pauses a database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database to be paused.
     * @param options The options parameters.
     */
    async beginPause(resourceGroupName, serverName, databaseName, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: { resourceGroupName, serverName, databaseName, options },
            spec: pauseOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Pauses a database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database to be paused.
     * @param options The options parameters.
     */
    async beginPauseAndWait(resourceGroupName, serverName, databaseName, options) {
        const poller = await this.beginPause(resourceGroupName, serverName, databaseName, options);
        return poller.pollUntilDone();
    }
    /**
     * Resumes a database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database to be resumed.
     * @param options The options parameters.
     */
    async beginResume(resourceGroupName, serverName, databaseName, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: { resourceGroupName, serverName, databaseName, options },
            spec: resumeOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Resumes a database.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database to be resumed.
     * @param options The options parameters.
     */
    async beginResumeAndWait(resourceGroupName, serverName, databaseName, options) {
        const poller = await this.beginResume(resourceGroupName, serverName, databaseName, options);
        return poller.pollUntilDone();
    }
    /**
     * Upgrades a data warehouse.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database to be upgraded.
     * @param options The options parameters.
     */
    async beginUpgradeDataWarehouse(resourceGroupName, serverName, databaseName, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: { resourceGroupName, serverName, databaseName, options },
            spec: upgradeDataWarehouseOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Upgrades a data warehouse.
     * @param 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 serverName The name of the server.
     * @param databaseName The name of the database to be upgraded.
     * @param options The options parameters.
     */
    async beginUpgradeDataWarehouseAndWait(resourceGroupName, serverName, databaseName, options) {
        const poller = await this.beginUpgradeDataWarehouse(resourceGroupName, serverName, databaseName, options);
        return poller.pollUntilDone();
    }
    /**
     * Gets a list of databases in an elastic pool.
     * @param 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 serverName The name of the server.
     * @param elasticPoolName The name of the elastic pool.
     * @param options The options parameters.
     */
    _listByElasticPool(resourceGroupName, serverName, elasticPoolName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, elasticPoolName, options }, listByElasticPoolOperationSpec);
    }
    /**
     * Gets a list of inaccessible databases in a logical server
     * @param 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 serverName The name of the server.
     * @param options The options parameters.
     */
    _listInaccessibleByServer(resourceGroupName, serverName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, options }, listInaccessibleByServerOperationSpec);
    }
    /**
     * ListByServerNext
     * @param 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 serverName The name of the server.
     * @param nextLink The nextLink from the previous successful call to the ListByServer method.
     * @param options The options parameters.
     */
    _listByServerNext(resourceGroupName, serverName, nextLink, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, nextLink, options }, listByServerNextOperationSpec);
    }
    /**
     * ListByElasticPoolNext
     * @param 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 serverName The name of the server.
     * @param elasticPoolName The name of the elastic pool.
     * @param nextLink The nextLink from the previous successful call to the ListByElasticPool method.
     * @param options The options parameters.
     */
    _listByElasticPoolNext(resourceGroupName, serverName, elasticPoolName, nextLink, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, elasticPoolName, nextLink, options }, listByElasticPoolNextOperationSpec);
    }
    /**
     * ListInaccessibleByServerNext
     * @param 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 serverName The name of the server.
     * @param nextLink The nextLink from the previous successful call to the ListInaccessibleByServer
     *                 method.
     * @param options The options parameters.
     */
    _listInaccessibleByServerNext(resourceGroupName, serverName, nextLink, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, nextLink, options }, listInaccessibleByServerNextOperationSpec);
    }
}
exports.DatabasesImpl = DatabasesImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listMetricsOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metrics",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.MetricListResult,
        },
    },
    queryParameters: [Parameters.apiVersion, Parameters.filter],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listMetricDefinitionsOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/metricDefinitions",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.MetricDefinitionListResult,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByServerOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.DatabaseListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.skipToken, Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const getOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.Database,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion1, Parameters.expand, Parameters.filter1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const createOrUpdateOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}",
    httpMethod: "PUT",
    responses: {
        200: {
            bodyMapper: Mappers.Database,
        },
        201: {
            bodyMapper: Mappers.Database,
        },
        202: {
            bodyMapper: Mappers.Database,
        },
        204: {
            bodyMapper: Mappers.Database,
        },
        default: {},
    },
    requestBody: Parameters.parameters3,
    queryParameters: [Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    headerParameters: [Parameters.contentType, Parameters.accept],
    mediaType: "json",
    serializer,
};
const deleteOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}",
    httpMethod: "DELETE",
    responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: {} },
    queryParameters: [Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    serializer,
};
const updateOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}",
    httpMethod: "PATCH",
    responses: {
        200: {
            bodyMapper: Mappers.Database,
        },
        201: {
            bodyMapper: Mappers.Database,
        },
        202: {
            bodyMapper: Mappers.Database,
        },
        204: {
            bodyMapper: Mappers.Database,
        },
        default: {},
    },
    requestBody: Parameters.parameters4,
    queryParameters: [Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    headerParameters: [Parameters.contentType, Parameters.accept],
    mediaType: "json",
    serializer,
};
const exportOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/export",
    httpMethod: "POST",
    responses: {
        200: {
            bodyMapper: Mappers.ImportExportOperationResult,
        },
        201: {
            bodyMapper: Mappers.ImportExportOperationResult,
        },
        202: {
            bodyMapper: Mappers.ImportExportOperationResult,
        },
        204: {
            bodyMapper: Mappers.ImportExportOperationResult,
        },
        default: {},
    },
    requestBody: Parameters.parameters5,
    queryParameters: [Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    headerParameters: [Parameters.contentType, Parameters.accept],
    mediaType: "json",
    serializer,
};
const failoverOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/failover",
    httpMethod: "POST",
    responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: {} },
    queryParameters: [Parameters.apiVersion1, Parameters.replicaType],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    serializer,
};
const importOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/import",
    httpMethod: "POST",
    responses: {
        200: {
            bodyMapper: Mappers.ImportExportOperationResult,
        },
        201: {
            bodyMapper: Mappers.ImportExportOperationResult,
        },
        202: {
            bodyMapper: Mappers.ImportExportOperationResult,
        },
        204: {
            bodyMapper: Mappers.ImportExportOperationResult,
        },
        default: {},
    },
    requestBody: Parameters.parameters6,
    queryParameters: [Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    headerParameters: [Parameters.contentType, Parameters.accept],
    mediaType: "json",
    serializer,
};
const renameOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/move",
    httpMethod: "POST",
    responses: { 200: {}, default: {} },
    requestBody: Parameters.parameters7,
    queryParameters: [Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    headerParameters: [Parameters.contentType],
    mediaType: "json",
    serializer,
};
const pauseOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/pause",
    httpMethod: "POST",
    responses: {
        200: {
            bodyMapper: Mappers.Database,
        },
        201: {
            bodyMapper: Mappers.Database,
        },
        202: {
            bodyMapper: Mappers.Database,
        },
        204: {
            bodyMapper: Mappers.Database,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const resumeOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/resume",
    httpMethod: "POST",
    responses: {
        200: {
            bodyMapper: Mappers.Database,
        },
        201: {
            bodyMapper: Mappers.Database,
        },
        202: {
            bodyMapper: Mappers.Database,
        },
        204: {
            bodyMapper: Mappers.Database,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const upgradeDataWarehouseOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/upgradeDataWarehouse",
    httpMethod: "POST",
    responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: {} },
    queryParameters: [Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
    ],
    serializer,
};
const listByElasticPoolOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/databases",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.DatabaseListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.elasticPoolName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listInaccessibleByServerOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/inaccessibleDatabases",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.DatabaseListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion1],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByServerNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.DatabaseListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.nextLink,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByElasticPoolNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.DatabaseListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.elasticPoolName,
        Parameters.nextLink,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listInaccessibleByServerNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.DatabaseListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.nextLink,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=databases.js.map