"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.UsagesImpl = 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"));
/// <reference lib="esnext.asynciterable" />
/** Class containing Usages operations. */
class UsagesImpl {
    client;
    /**
     * Initialize a new instance of the class Usages class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Gets all instance pool usage 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 instancePoolName The name of the instance pool to be retrieved.
     * @param options The options parameters.
     */
    listByInstancePool(resourceGroupName, instancePoolName, options) {
        const iter = this.listByInstancePoolPagingAll(resourceGroupName, instancePoolName, 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.listByInstancePoolPagingPage(resourceGroupName, instancePoolName, options, settings);
            },
        };
    }
    async *listByInstancePoolPagingPage(resourceGroupName, instancePoolName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByInstancePool(resourceGroupName, instancePoolName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByInstancePoolNext(resourceGroupName, instancePoolName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *listByInstancePoolPagingAll(resourceGroupName, instancePoolName, options) {
        for await (const page of this.listByInstancePoolPagingPage(resourceGroupName, instancePoolName, options)) {
            yield* page;
        }
    }
    /**
     * Gets all instance pool usage 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 instancePoolName The name of the instance pool to be retrieved.
     * @param options The options parameters.
     */
    _listByInstancePool(resourceGroupName, instancePoolName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, instancePoolName, options }, listByInstancePoolOperationSpec);
    }
    /**
     * ListByInstancePoolNext
     * @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 instancePoolName The name of the instance pool to be retrieved.
     * @param nextLink The nextLink from the previous successful call to the ListByInstancePool method.
     * @param options The options parameters.
     */
    _listByInstancePoolNext(resourceGroupName, instancePoolName, nextLink, options) {
        return this.client.sendOperationRequest({ resourceGroupName, instancePoolName, nextLink, options }, listByInstancePoolNextOperationSpec);
    }
}
exports.UsagesImpl = UsagesImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByInstancePoolOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/instancePools/{instancePoolName}/usages",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.UsageListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion6, Parameters.expandChildren],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.instancePoolName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByInstancePoolNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.UsageListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.nextLink,
        Parameters.instancePoolName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=usages.js.map