"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.WorkloadClassifiersImpl = 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 WorkloadClassifiers operations. */
class WorkloadClassifiersImpl {
    client;
    /**
     * Initialize a new instance of the class WorkloadClassifiers class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Gets the list of workload classifiers for a workload group
     * @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 workloadGroupName The name of the workload group from which to receive the classifiers from.
     * @param options The options parameters.
     */
    listByWorkloadGroup(resourceGroupName, serverName, databaseName, workloadGroupName, options) {
        const iter = this.listByWorkloadGroupPagingAll(resourceGroupName, serverName, databaseName, workloadGroupName, 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.listByWorkloadGroupPagingPage(resourceGroupName, serverName, databaseName, workloadGroupName, options, settings);
            },
        };
    }
    async *listByWorkloadGroupPagingPage(resourceGroupName, serverName, databaseName, workloadGroupName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByWorkloadGroup(resourceGroupName, serverName, databaseName, workloadGroupName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByWorkloadGroupNext(resourceGroupName, serverName, databaseName, workloadGroupName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *listByWorkloadGroupPagingAll(resourceGroupName, serverName, databaseName, workloadGroupName, options) {
        for await (const page of this.listByWorkloadGroupPagingPage(resourceGroupName, serverName, databaseName, workloadGroupName, options)) {
            yield* page;
        }
    }
    /**
     * Gets a workload classifier
     * @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 workloadGroupName The name of the workload group from which to receive the classifier from.
     * @param workloadClassifierName The name of the workload classifier.
     * @param options The options parameters.
     */
    get(resourceGroupName, serverName, databaseName, workloadGroupName, workloadClassifierName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            databaseName,
            workloadGroupName,
            workloadClassifierName,
            options,
        }, getOperationSpec);
    }
    /**
     * Creates or updates a workload classifier.
     * @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 workloadGroupName The name of the workload group from which to receive the classifier from.
     * @param workloadClassifierName The name of the workload classifier to create/update.
     * @param parameters The properties of the workload classifier.
     * @param options The options parameters.
     */
    async beginCreateOrUpdate(resourceGroupName, serverName, databaseName, workloadGroupName, workloadClassifierName, 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,
                workloadGroupName,
                workloadClassifierName,
                parameters,
                options,
            },
            spec: createOrUpdateOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Creates or updates a workload classifier.
     * @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 workloadGroupName The name of the workload group from which to receive the classifier from.
     * @param workloadClassifierName The name of the workload classifier to create/update.
     * @param parameters The properties of the workload classifier.
     * @param options The options parameters.
     */
    async beginCreateOrUpdateAndWait(resourceGroupName, serverName, databaseName, workloadGroupName, workloadClassifierName, parameters, options) {
        const poller = await this.beginCreateOrUpdate(resourceGroupName, serverName, databaseName, workloadGroupName, workloadClassifierName, parameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Deletes a workload classifier.
     * @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 workloadGroupName The name of the workload group from which to receive the classifier from.
     * @param workloadClassifierName The name of the workload classifier to delete.
     * @param options The options parameters.
     */
    async beginDelete(resourceGroupName, serverName, databaseName, workloadGroupName, workloadClassifierName, 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,
                workloadGroupName,
                workloadClassifierName,
                options,
            },
            spec: deleteOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Deletes a workload classifier.
     * @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 workloadGroupName The name of the workload group from which to receive the classifier from.
     * @param workloadClassifierName The name of the workload classifier to delete.
     * @param options The options parameters.
     */
    async beginDeleteAndWait(resourceGroupName, serverName, databaseName, workloadGroupName, workloadClassifierName, options) {
        const poller = await this.beginDelete(resourceGroupName, serverName, databaseName, workloadGroupName, workloadClassifierName, options);
        return poller.pollUntilDone();
    }
    /**
     * Gets the list of workload classifiers for a workload group
     * @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 workloadGroupName The name of the workload group from which to receive the classifiers from.
     * @param options The options parameters.
     */
    _listByWorkloadGroup(resourceGroupName, serverName, databaseName, workloadGroupName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            databaseName,
            workloadGroupName,
            options,
        }, listByWorkloadGroupOperationSpec);
    }
    /**
     * ListByWorkloadGroupNext
     * @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 workloadGroupName The name of the workload group from which to receive the classifiers from.
     * @param nextLink The nextLink from the previous successful call to the ListByWorkloadGroup method.
     * @param options The options parameters.
     */
    _listByWorkloadGroupNext(resourceGroupName, serverName, databaseName, workloadGroupName, nextLink, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            databaseName,
            workloadGroupName,
            nextLink,
            options,
        }, listByWorkloadGroupNextOperationSpec);
    }
}
exports.WorkloadClassifiersImpl = WorkloadClassifiersImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const getOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.WorkloadClassifier,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
        Parameters.workloadGroupName,
        Parameters.workloadClassifierName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const createOrUpdateOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}",
    httpMethod: "PUT",
    responses: {
        200: {
            bodyMapper: Mappers.WorkloadClassifier,
        },
        201: {
            bodyMapper: Mappers.WorkloadClassifier,
        },
        202: {
            bodyMapper: Mappers.WorkloadClassifier,
        },
        204: {
            bodyMapper: Mappers.WorkloadClassifier,
        },
        default: {},
    },
    requestBody: Parameters.parameters56,
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
        Parameters.workloadGroupName,
        Parameters.workloadClassifierName,
    ],
    headerParameters: [Parameters.contentType, Parameters.accept],
    mediaType: "json",
    serializer,
};
const deleteOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers/{workloadClassifierName}",
    httpMethod: "DELETE",
    responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: {} },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
        Parameters.workloadGroupName,
        Parameters.workloadClassifierName,
    ],
    serializer,
};
const listByWorkloadGroupOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/databases/{databaseName}/workloadGroups/{workloadGroupName}/workloadClassifiers",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.WorkloadClassifierListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
        Parameters.workloadGroupName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByWorkloadGroupNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.WorkloadClassifierListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.databaseName,
        Parameters.nextLink,
        Parameters.workloadGroupName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=workloadClassifiers.js.map