// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { setContinuationToken } from "../pagingHelper.js";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers.js";
import * as Parameters from "../models/parameters.js";
/// <reference lib="esnext.asynciterable" />
/** Class containing ElasticPoolOperations operations. */
export class ElasticPoolOperationsImpl {
    client;
    /**
     * Initialize a new instance of the class ElasticPoolOperations class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Gets a list of operations performed on the 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
     * @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;
            setContinuationToken(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByElasticPoolNext(resourceGroupName, serverName, elasticPoolName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            setContinuationToken(page, continuationToken);
            yield page;
        }
    }
    async *listByElasticPoolPagingAll(resourceGroupName, serverName, elasticPoolName, options) {
        for await (const page of this.listByElasticPoolPagingPage(resourceGroupName, serverName, elasticPoolName, options)) {
            yield* page;
        }
    }
    /**
     * Cancels the asynchronous operation on the 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
     * @param operationId The operation identifier.
     * @param options The options parameters.
     */
    cancel(resourceGroupName, serverName, elasticPoolName, operationId, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, elasticPoolName, operationId, options }, cancelOperationSpec);
    }
    /**
     * Gets a list of operations performed on the 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
     * @param options The options parameters.
     */
    _listByElasticPool(resourceGroupName, serverName, elasticPoolName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, elasticPoolName, options }, listByElasticPoolOperationSpec);
    }
    /**
     * 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
     * @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);
    }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const cancelOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations/{operationId}/cancel",
    httpMethod: "POST",
    responses: { 200: {}, default: {} },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.elasticPoolName,
        Parameters.operationId,
    ],
    serializer,
};
const listByElasticPoolOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/elasticPools/{elasticPoolName}/operations",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ElasticPoolOperationListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.elasticPoolName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByElasticPoolNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ElasticPoolOperationListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.elasticPoolName,
        Parameters.nextLink,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=elasticPoolOperations.js.map