"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.ManagedLedgerDigestUploadsOperationsImpl = 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 ManagedLedgerDigestUploadsOperations operations. */
class ManagedLedgerDigestUploadsOperationsImpl {
    client;
    /**
     * Initialize a new instance of the class ManagedLedgerDigestUploadsOperations class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Gets all ledger digest upload settings on 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 managedInstanceName The name of the managed instance.
     * @param databaseName The name of the database.
     * @param options The options parameters.
     */
    listByDatabase(resourceGroupName, managedInstanceName, databaseName, options) {
        const iter = this.listByDatabasePagingAll(resourceGroupName, managedInstanceName, 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.listByDatabasePagingPage(resourceGroupName, managedInstanceName, databaseName, options, settings);
            },
        };
    }
    async *listByDatabasePagingPage(resourceGroupName, managedInstanceName, databaseName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByDatabase(resourceGroupName, managedInstanceName, databaseName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByDatabaseNext(resourceGroupName, managedInstanceName, databaseName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *listByDatabasePagingAll(resourceGroupName, managedInstanceName, databaseName, options) {
        for await (const page of this.listByDatabasePagingPage(resourceGroupName, managedInstanceName, databaseName, options)) {
            yield* page;
        }
    }
    /**
     * Gets all ledger digest upload settings on 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 managedInstanceName The name of the managed instance.
     * @param databaseName The name of the database.
     * @param options The options parameters.
     */
    _listByDatabase(resourceGroupName, managedInstanceName, databaseName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, managedInstanceName, databaseName, options }, listByDatabaseOperationSpec);
    }
    /**
     * Gets the current ledger digest upload configuration for 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 managedInstanceName The name of the managed instance.
     * @param databaseName The name of the database.
     * @param ledgerDigestUploads
     * @param options The options parameters.
     */
    get(resourceGroupName, managedInstanceName, databaseName, ledgerDigestUploads, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            managedInstanceName,
            databaseName,
            ledgerDigestUploads,
            options,
        }, getOperationSpec);
    }
    /**
     * Enables upload ledger digests to an Azure Storage account or an Azure Confidential Ledger instance.
     * @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 databaseName The name of the database.
     * @param ledgerDigestUploads The name of the Ledger Digest Upload Configurations.
     * @param parameters The Ledger Digest Storage Endpoint.
     * @param options The options parameters.
     */
    async beginCreateOrUpdate(resourceGroupName, managedInstanceName, databaseName, ledgerDigestUploads, 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,
                databaseName,
                ledgerDigestUploads,
                parameters,
                options,
            },
            spec: createOrUpdateOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Enables upload ledger digests to an Azure Storage account or an Azure Confidential Ledger instance.
     * @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 databaseName The name of the database.
     * @param ledgerDigestUploads The name of the Ledger Digest Upload Configurations.
     * @param parameters The Ledger Digest Storage Endpoint.
     * @param options The options parameters.
     */
    async beginCreateOrUpdateAndWait(resourceGroupName, managedInstanceName, databaseName, ledgerDigestUploads, parameters, options) {
        const poller = await this.beginCreateOrUpdate(resourceGroupName, managedInstanceName, databaseName, ledgerDigestUploads, parameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Disables uploading ledger digests to an Azure Storage account or an Azure Confidential Ledger
     * instance.
     * @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 databaseName The name of the database.
     * @param ledgerDigestUploads
     * @param options The options parameters.
     */
    async beginDisable(resourceGroupName, managedInstanceName, databaseName, ledgerDigestUploads, 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,
                databaseName,
                ledgerDigestUploads,
                options,
            },
            spec: disableOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Disables uploading ledger digests to an Azure Storage account or an Azure Confidential Ledger
     * instance.
     * @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 databaseName The name of the database.
     * @param ledgerDigestUploads
     * @param options The options parameters.
     */
    async beginDisableAndWait(resourceGroupName, managedInstanceName, databaseName, ledgerDigestUploads, options) {
        const poller = await this.beginDisable(resourceGroupName, managedInstanceName, databaseName, ledgerDigestUploads, options);
        return poller.pollUntilDone();
    }
    /**
     * ListByDatabaseNext
     * @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 databaseName The name of the database.
     * @param nextLink The nextLink from the previous successful call to the ListByDatabase method.
     * @param options The options parameters.
     */
    _listByDatabaseNext(resourceGroupName, managedInstanceName, databaseName, nextLink, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            managedInstanceName,
            databaseName,
            nextLink,
            options,
        }, listByDatabaseNextOperationSpec);
    }
}
exports.ManagedLedgerDigestUploadsOperationsImpl = ManagedLedgerDigestUploadsOperationsImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByDatabaseOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/ledgerDigestUploads",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedLedgerDigestUploadsListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion2],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.databaseName,
        Parameters.managedInstanceName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const getOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedLedgerDigestUploads,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion2],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.databaseName,
        Parameters.managedInstanceName,
        Parameters.ledgerDigestUploads1,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const createOrUpdateOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}",
    httpMethod: "PUT",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedLedgerDigestUploads,
        },
        201: {
            bodyMapper: Mappers.ManagedLedgerDigestUploads,
        },
        202: {
            bodyMapper: Mappers.ManagedLedgerDigestUploads,
        },
        204: {
            bodyMapper: Mappers.ManagedLedgerDigestUploads,
        },
        default: {},
    },
    requestBody: Parameters.parameters85,
    queryParameters: [Parameters.apiVersion2],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.databaseName,
        Parameters.managedInstanceName,
        Parameters.ledgerDigestUploads1,
    ],
    headerParameters: [Parameters.contentType, Parameters.accept],
    mediaType: "json",
    serializer,
};
const disableOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/managedInstances/{managedInstanceName}/databases/{databaseName}/ledgerDigestUploads/{ledgerDigestUploads}/disable",
    httpMethod: "POST",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedLedgerDigestUploads,
        },
        201: {
            bodyMapper: Mappers.ManagedLedgerDigestUploads,
        },
        202: {
            bodyMapper: Mappers.ManagedLedgerDigestUploads,
        },
        204: {
            bodyMapper: Mappers.ManagedLedgerDigestUploads,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion2],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.databaseName,
        Parameters.managedInstanceName,
        Parameters.ledgerDigestUploads1,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByDatabaseNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ManagedLedgerDigestUploadsListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.databaseName,
        Parameters.nextLink,
        Parameters.managedInstanceName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=managedLedgerDigestUploadsOperations.js.map