/*
* 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 { ReservationsSummaries } 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 {
ReservationSummary,
ReservationsSummariesListByReservationOrderNextOptionalParams,
Datagrain,
ReservationsSummariesListByReservationOrderOptionalParams,
ReservationsSummariesListByReservationOrderResponse,
ReservationsSummariesListByReservationOrderAndReservationNextOptionalParams,
ReservationsSummariesListByReservationOrderAndReservationOptionalParams,
ReservationsSummariesListByReservationOrderAndReservationResponse,
ReservationsSummariesListNextOptionalParams,
ReservationsSummariesListOptionalParams,
ReservationsSummariesListResponse,
ReservationsSummariesListByReservationOrderNextResponse,
ReservationsSummariesListByReservationOrderAndReservationNextResponse,
ReservationsSummariesListNextResponse
} from "../models";
///
/** Class containing ReservationsSummaries operations. */
export class ReservationsSummariesImpl implements ReservationsSummaries {
private readonly client: ConsumptionManagementClient;
/**
* Initialize a new instance of the class ReservationsSummaries class.
* @param client Reference to the service client
*/
constructor(client: ConsumptionManagementClient) {
this.client = client;
}
/**
* Lists the reservations summaries for daily or monthly grain.
* @param reservationOrderId Order Id of the reservation
* @param grain Can be daily or monthly
* @param options The options parameters.
*/
public listByReservationOrder(
reservationOrderId: string,
grain: Datagrain,
options?: ReservationsSummariesListByReservationOrderOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listByReservationOrderPagingAll(
reservationOrderId,
grain,
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.listByReservationOrderPagingPage(
reservationOrderId,
grain,
options,
settings
);
}
};
}
private async *listByReservationOrderPagingPage(
reservationOrderId: string,
grain: Datagrain,
options?: ReservationsSummariesListByReservationOrderOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: ReservationsSummariesListByReservationOrderResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listByReservationOrder(
reservationOrderId,
grain,
options
);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listByReservationOrderNext(
reservationOrderId,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listByReservationOrderPagingAll(
reservationOrderId: string,
grain: Datagrain,
options?: ReservationsSummariesListByReservationOrderOptionalParams
): AsyncIterableIterator {
for await (const page of this.listByReservationOrderPagingPage(
reservationOrderId,
grain,
options
)) {
yield* page;
}
}
/**
* Lists the reservations summaries for daily or monthly grain.
* @param reservationOrderId Order Id of the reservation
* @param reservationId Id of the reservation
* @param grain Can be daily or monthly
* @param options The options parameters.
*/
public listByReservationOrderAndReservation(
reservationOrderId: string,
reservationId: string,
grain: Datagrain,
options?: ReservationsSummariesListByReservationOrderAndReservationOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listByReservationOrderAndReservationPagingAll(
reservationOrderId,
reservationId,
grain,
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.listByReservationOrderAndReservationPagingPage(
reservationOrderId,
reservationId,
grain,
options,
settings
);
}
};
}
private async *listByReservationOrderAndReservationPagingPage(
reservationOrderId: string,
reservationId: string,
grain: Datagrain,
options?: ReservationsSummariesListByReservationOrderAndReservationOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: ReservationsSummariesListByReservationOrderAndReservationResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listByReservationOrderAndReservation(
reservationOrderId,
reservationId,
grain,
options
);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listByReservationOrderAndReservationNext(
reservationOrderId,
reservationId,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listByReservationOrderAndReservationPagingAll(
reservationOrderId: string,
reservationId: string,
grain: Datagrain,
options?: ReservationsSummariesListByReservationOrderAndReservationOptionalParams
): AsyncIterableIterator {
for await (const page of this.listByReservationOrderAndReservationPagingPage(
reservationOrderId,
reservationId,
grain,
options
)) {
yield* page;
}
}
/**
* Lists the reservations summaries for the defined scope daily or monthly grain.
* @param scope The scope associated with reservations summaries operations. This includes
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for BillingAccount scope (legacy),
* and
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}'
* for BillingProfile scope (modern).
* @param grain Can be daily or monthly
* @param options The options parameters.
*/
public list(
scope: string,
grain: Datagrain,
options?: ReservationsSummariesListOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listPagingAll(scope, grain, 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, grain, options, settings);
}
};
}
private async *listPagingPage(
scope: string,
grain: Datagrain,
options?: ReservationsSummariesListOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: ReservationsSummariesListResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._list(scope, grain, 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,
grain: Datagrain,
options?: ReservationsSummariesListOptionalParams
): AsyncIterableIterator {
for await (const page of this.listPagingPage(scope, grain, options)) {
yield* page;
}
}
/**
* Lists the reservations summaries for daily or monthly grain.
* @param reservationOrderId Order Id of the reservation
* @param grain Can be daily or monthly
* @param options The options parameters.
*/
private _listByReservationOrder(
reservationOrderId: string,
grain: Datagrain,
options?: ReservationsSummariesListByReservationOrderOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ reservationOrderId, grain, options },
listByReservationOrderOperationSpec
);
}
/**
* Lists the reservations summaries for daily or monthly grain.
* @param reservationOrderId Order Id of the reservation
* @param reservationId Id of the reservation
* @param grain Can be daily or monthly
* @param options The options parameters.
*/
private _listByReservationOrderAndReservation(
reservationOrderId: string,
reservationId: string,
grain: Datagrain,
options?: ReservationsSummariesListByReservationOrderAndReservationOptionalParams
): Promise<
ReservationsSummariesListByReservationOrderAndReservationResponse
> {
return this.client.sendOperationRequest(
{ reservationOrderId, reservationId, grain, options },
listByReservationOrderAndReservationOperationSpec
);
}
/**
* Lists the reservations summaries for the defined scope daily or monthly grain.
* @param scope The scope associated with reservations summaries operations. This includes
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for BillingAccount scope (legacy),
* and
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}'
* for BillingProfile scope (modern).
* @param grain Can be daily or monthly
* @param options The options parameters.
*/
private _list(
scope: string,
grain: Datagrain,
options?: ReservationsSummariesListOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ scope, grain, options },
listOperationSpec
);
}
/**
* ListByReservationOrderNext
* @param reservationOrderId Order Id of the reservation
* @param nextLink The nextLink from the previous successful call to the ListByReservationOrder method.
* @param options The options parameters.
*/
private _listByReservationOrderNext(
reservationOrderId: string,
nextLink: string,
options?: ReservationsSummariesListByReservationOrderNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ reservationOrderId, nextLink, options },
listByReservationOrderNextOperationSpec
);
}
/**
* ListByReservationOrderAndReservationNext
* @param reservationOrderId Order Id of the reservation
* @param reservationId Id of the reservation
* @param nextLink The nextLink from the previous successful call to the
* ListByReservationOrderAndReservation method.
* @param options The options parameters.
*/
private _listByReservationOrderAndReservationNext(
reservationOrderId: string,
reservationId: string,
nextLink: string,
options?: ReservationsSummariesListByReservationOrderAndReservationNextOptionalParams
): Promise<
ReservationsSummariesListByReservationOrderAndReservationNextResponse
> {
return this.client.sendOperationRequest(
{ reservationOrderId, reservationId, nextLink, options },
listByReservationOrderAndReservationNextOperationSpec
);
}
/**
* ListNext
* @param scope The scope associated with reservations summaries operations. This includes
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for BillingAccount scope (legacy),
* and
* '/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}'
* for BillingProfile scope (modern).
* @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?: ReservationsSummariesListNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ scope, nextLink, options },
listNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByReservationOrderOperationSpec: coreClient.OperationSpec = {
path:
"/providers/Microsoft.Capacity/reservationorders/{reservationOrderId}/providers/Microsoft.Consumption/reservationSummaries",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ReservationSummariesListResult
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.filter, Parameters.apiVersion, Parameters.grain],
urlParameters: [Parameters.$host, Parameters.reservationOrderId],
headerParameters: [Parameters.accept],
serializer
};
const listByReservationOrderAndReservationOperationSpec: coreClient.OperationSpec = {
path:
"/providers/Microsoft.Capacity/reservationorders/{reservationOrderId}/reservations/{reservationId}/providers/Microsoft.Consumption/reservationSummaries",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ReservationSummariesListResult
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.filter, Parameters.apiVersion, Parameters.grain],
urlParameters: [
Parameters.$host,
Parameters.reservationOrderId,
Parameters.reservationId
],
headerParameters: [Parameters.accept],
serializer
};
const listOperationSpec: coreClient.OperationSpec = {
path: "/{scope}/providers/Microsoft.Consumption/reservationSummaries",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ReservationSummariesListResult
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [
Parameters.filter,
Parameters.apiVersion,
Parameters.startDate,
Parameters.endDate,
Parameters.grain,
Parameters.reservationId1,
Parameters.reservationOrderId1
],
urlParameters: [Parameters.$host, Parameters.scope],
headerParameters: [Parameters.accept],
serializer
};
const listByReservationOrderNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ReservationSummariesListResult
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Parameters.reservationOrderId
],
headerParameters: [Parameters.accept],
serializer
};
const listByReservationOrderAndReservationNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ReservationSummariesListResult
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Parameters.reservationOrderId,
Parameters.reservationId
],
headerParameters: [Parameters.accept],
serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.ReservationSummariesListResult
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
urlParameters: [Parameters.$host, Parameters.scope, Parameters.nextLink],
headerParameters: [Parameters.accept],
serializer
};