/* * Copyright (c) Microsoft Corporation. * Licensed under the MIT License. * * Code generated by Microsoft (R) AutoRest Code Generator. * Changes may cause incorrect behavior and will be lost if the code is regenerated. */ import { PagedAsyncIterableIterator, PageSettings } from "@azure/core-paging"; import { setContinuationToken } from "../pagingHelper"; import { ReservationRecommendations } from "../operationsInterfaces"; import * as coreClient from "@azure/core-client"; import * as Mappers from "../models/mappers"; import * as Parameters from "../models/parameters"; import { ConsumptionManagementClient } from "../consumptionManagementClient"; import { ReservationRecommendationUnion, ReservationRecommendationsListNextOptionalParams, ReservationRecommendationsListOptionalParams, ReservationRecommendationsListResponse, ReservationRecommendationsListNextResponse } from "../models"; /// /** Class containing ReservationRecommendations operations. */ export class ReservationRecommendationsImpl implements ReservationRecommendations { private readonly client: ConsumptionManagementClient; /** * Initialize a new instance of the class ReservationRecommendations class. * @param client Reference to the service client */ constructor(client: ConsumptionManagementClient) { this.client = client; } /** * List of recommendations for purchasing reserved instances. * @param scope The scope associated with reservation recommendations operations. This includes * '/subscriptions/{subscriptionId}/' for subscription scope, * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resource group scope, * '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for BillingAccount scope, and * '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' * for billingProfile scope * @param options The options parameters. */ public list( scope: string, options?: ReservationRecommendationsListOptionalParams ): PagedAsyncIterableIterator { const iter = this.listPagingAll(scope, options); return { next() { return iter.next(); }, [Symbol.asyncIterator]() { return this; }, byPage: (settings?: PageSettings) => { if (settings?.maxPageSize) { throw new Error("maxPageSize is not supported by this operation."); } return this.listPagingPage(scope, options, settings); } }; } private async *listPagingPage( scope: string, options?: ReservationRecommendationsListOptionalParams, settings?: PageSettings ): AsyncIterableIterator { let result: ReservationRecommendationsListResponse; let continuationToken = settings?.continuationToken; if (!continuationToken) { result = await this._list(scope, options); let page = result.value || []; continuationToken = result.nextLink; setContinuationToken(page, continuationToken); yield page; } while (continuationToken) { result = await this._listNext(scope, continuationToken, options); continuationToken = result.nextLink; let page = result.value || []; setContinuationToken(page, continuationToken); yield page; } } private async *listPagingAll( scope: string, options?: ReservationRecommendationsListOptionalParams ): AsyncIterableIterator { for await (const page of this.listPagingPage(scope, options)) { yield* page; } } /** * List of recommendations for purchasing reserved instances. * @param scope The scope associated with reservation recommendations operations. This includes * '/subscriptions/{subscriptionId}/' for subscription scope, * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resource group scope, * '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for BillingAccount scope, and * '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' * for billingProfile scope * @param options The options parameters. */ private _list( scope: string, options?: ReservationRecommendationsListOptionalParams ): Promise { return this.client.sendOperationRequest( { scope, options }, listOperationSpec ); } /** * ListNext * @param scope The scope associated with reservation recommendations operations. This includes * '/subscriptions/{subscriptionId}/' for subscription scope, * '/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resource group scope, * '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for BillingAccount scope, and * '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' * for billingProfile scope * @param nextLink The nextLink from the previous successful call to the List method. * @param options The options parameters. */ private _listNext( scope: string, nextLink: string, options?: ReservationRecommendationsListNextOptionalParams ): Promise { return this.client.sendOperationRequest( { scope, nextLink, options }, listNextOperationSpec ); } } // Operation Specifications const serializer = coreClient.createSerializer(Mappers, /* isXml */ false); const listOperationSpec: coreClient.OperationSpec = { path: "/{scope}/providers/Microsoft.Consumption/reservationRecommendations", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ReservationRecommendationsListResult }, 204: {}, default: { bodyMapper: Mappers.ErrorResponse } }, queryParameters: [Parameters.filter, Parameters.apiVersion], urlParameters: [Parameters.$host, Parameters.scope], headerParameters: [Parameters.accept], serializer }; const listNextOperationSpec: coreClient.OperationSpec = { path: "{nextLink}", httpMethod: "GET", responses: { 200: { bodyMapper: Mappers.ReservationRecommendationsListResult }, 204: {}, default: { bodyMapper: Mappers.ErrorResponse } }, urlParameters: [Parameters.$host, Parameters.scope, Parameters.nextLink], headerParameters: [Parameters.accept], serializer };