"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesImpl = 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 ManagedRestorableDroppedDatabaseBackupShortTermRetentionPolicies operations. */
class ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesImpl {
    client;
    /**
     * Initialize a new instance of the class ManagedRestorableDroppedDatabaseBackupShortTermRetentionPolicies class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Gets a dropped database's short term retention policy list.
     * @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 managedInstanceName The name of the managed instance.
     * @param restorableDroppedDatabaseId
     * @param options The options parameters.
     */
    listByRestorableDroppedDatabase(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, options) {
        const iter = this.listByRestorableDroppedDatabasePagingAll(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, 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.listByRestorableDroppedDatabasePagingPage(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, options, settings);
            },
        };
    }
    async *listByRestorableDroppedDatabasePagingPage(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByRestorableDroppedDatabase(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByRestorableDroppedDatabaseNext(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *listByRestorableDroppedDatabasePagingAll(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, options) {
        for await (const page of this.listByRestorableDroppedDatabasePagingPage(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, options)) {
            yield* page;
        }
    }
    /**
     * Gets a dropped database's short term retention policy.
     * @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 managedInstanceName The name of the managed instance.
     * @param restorableDroppedDatabaseId
     * @param policyName The policy name.
     * @param options The options parameters.
     */
    get(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, policyName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            managedInstanceName,
            restorableDroppedDatabaseId,
            policyName,
            options,
        }, getOperationSpec);
    }
    /**
     * Sets a database's short term retention policy.
     * @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 managedInstanceName The name of the managed instance.
     * @param restorableDroppedDatabaseId
     * @param policyName The policy name. Should always be "default".
     * @param parameters The short term retention policy info.
     * @param options The options parameters.
     */
    async beginCreateOrUpdate(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, policyName, 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,
                managedInstanceName,
                restorableDroppedDatabaseId,
                policyName,
                parameters,
                options,
            },
            spec: createOrUpdateOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Sets a database's short term retention policy.
     * @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 managedInstanceName The name of the managed instance.
     * @param restorableDroppedDatabaseId
     * @param policyName The policy name. Should always be "default".
     * @param parameters The short term retention policy info.
     * @param options The options parameters.
     */
    async beginCreateOrUpdateAndWait(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, policyName, parameters, options) {
        const poller = await this.beginCreateOrUpdate(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, policyName, parameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Sets a database's short term retention policy.
     * @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 managedInstanceName The name of the managed instance.
     * @param restorableDroppedDatabaseId
     * @param policyName The policy name. Should always be "default".
     * @param parameters The short term retention policy info.
     * @param options The options parameters.
     */
    async beginUpdate(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, policyName, 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,
                managedInstanceName,
                restorableDroppedDatabaseId,
                policyName,
                parameters,
                options,
            },
            spec: updateOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Sets a database's short term retention policy.
     * @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 managedInstanceName The name of the managed instance.
     * @param restorableDroppedDatabaseId
     * @param policyName The policy name. Should always be "default".
     * @param parameters The short term retention policy info.
     * @param options The options parameters.
     */
    async beginUpdateAndWait(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, policyName, parameters, options) {
        const poller = await this.beginUpdate(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, policyName, parameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Gets a dropped database's short term retention policy list.
     * @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 managedInstanceName The name of the managed instance.
     * @param restorableDroppedDatabaseId
     * @param options The options parameters.
     */
    _listByRestorableDroppedDatabase(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            managedInstanceName,
            restorableDroppedDatabaseId,
            options,
        }, listByRestorableDroppedDatabaseOperationSpec);
    }
    /**
     * ListByRestorableDroppedDatabaseNext
     * @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 managedInstanceName The name of the managed instance.
     * @param restorableDroppedDatabaseId
     * @param nextLink The nextLink from the previous successful call to the
     *                 ListByRestorableDroppedDatabase method.
     * @param options The options parameters.
     */
    _listByRestorableDroppedDatabaseNext(resourceGroupName, managedInstanceName, restorableDroppedDatabaseId, nextLink, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            managedInstanceName,
            restorableDroppedDatabaseId,
            nextLink,
            options,
        }, listByRestorableDroppedDatabaseNextOperationSpec);
    }
}
exports.ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesImpl = ManagedRestorableDroppedDatabaseBackupShortTermRetentionPoliciesImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const getOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedBackupShortTermRetentionPolicy,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.managedInstanceName,
        Parameters.policyName,
        Parameters.restorableDroppedDatabaseId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const createOrUpdateOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}",
    httpMethod: "PUT",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedBackupShortTermRetentionPolicy,
        },
        201: {
            bodyMapper: Mappers.ManagedBackupShortTermRetentionPolicy,
        },
        202: {
            bodyMapper: Mappers.ManagedBackupShortTermRetentionPolicy,
        },
        204: {
            bodyMapper: Mappers.ManagedBackupShortTermRetentionPolicy,
        },
        default: {},
    },
    requestBody: Parameters.parameters28,
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.managedInstanceName,
        Parameters.policyName,
        Parameters.restorableDroppedDatabaseId,
    ],
    headerParameters: [Parameters.contentType, Parameters.accept],
    mediaType: "json",
    serializer,
};
const updateOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies/{policyName}",
    httpMethod: "PATCH",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedBackupShortTermRetentionPolicy,
        },
        201: {
            bodyMapper: Mappers.ManagedBackupShortTermRetentionPolicy,
        },
        202: {
            bodyMapper: Mappers.ManagedBackupShortTermRetentionPolicy,
        },
        204: {
            bodyMapper: Mappers.ManagedBackupShortTermRetentionPolicy,
        },
        default: {},
    },
    requestBody: Parameters.parameters28,
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.managedInstanceName,
        Parameters.policyName,
        Parameters.restorableDroppedDatabaseId,
    ],
    headerParameters: [Parameters.contentType, Parameters.accept],
    mediaType: "json",
    serializer,
};
const listByRestorableDroppedDatabaseOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/restorableDroppedDatabases/{restorableDroppedDatabaseId}/backupShortTermRetentionPolicies",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedBackupShortTermRetentionPolicyListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.managedInstanceName,
        Parameters.restorableDroppedDatabaseId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByRestorableDroppedDatabaseNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedBackupShortTermRetentionPolicyListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.nextLink,
        Parameters.managedInstanceName,
        Parameters.restorableDroppedDatabaseId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=managedRestorableDroppedDatabaseBackupShortTermRetentionPolicies.js.map