/*
* 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 { LotsOperations } 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 {
LotSummary,
LotsListByBillingProfileNextOptionalParams,
LotsListByBillingProfileOptionalParams,
LotsListByBillingProfileResponse,
LotsListByBillingAccountNextOptionalParams,
LotsListByBillingAccountOptionalParams,
LotsListByBillingAccountResponse,
LotsListByBillingProfileNextResponse,
LotsListByBillingAccountNextResponse
} from "../models";
///
/** Class containing LotsOperations operations. */
export class LotsOperationsImpl implements LotsOperations {
private readonly client: ConsumptionManagementClient;
/**
* Initialize a new instance of the class LotsOperations class.
* @param client Reference to the service client
*/
constructor(client: ConsumptionManagementClient) {
this.client = client;
}
/**
* Lists all Azure credits and Microsoft Azure consumption commitments for a billing account or a
* billing profile. Microsoft Azure consumption commitments are only supported for the billing account
* scope.
* @param billingAccountId BillingAccount ID
* @param billingProfileId Azure Billing Profile ID.
* @param options The options parameters.
*/
public listByBillingProfile(
billingAccountId: string,
billingProfileId: string,
options?: LotsListByBillingProfileOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listByBillingProfilePagingAll(
billingAccountId,
billingProfileId,
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.listByBillingProfilePagingPage(
billingAccountId,
billingProfileId,
options,
settings
);
}
};
}
private async *listByBillingProfilePagingPage(
billingAccountId: string,
billingProfileId: string,
options?: LotsListByBillingProfileOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: LotsListByBillingProfileResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listByBillingProfile(
billingAccountId,
billingProfileId,
options
);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listByBillingProfileNext(
billingAccountId,
billingProfileId,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listByBillingProfilePagingAll(
billingAccountId: string,
billingProfileId: string,
options?: LotsListByBillingProfileOptionalParams
): AsyncIterableIterator {
for await (const page of this.listByBillingProfilePagingPage(
billingAccountId,
billingProfileId,
options
)) {
yield* page;
}
}
/**
* Lists all Azure credits and Microsoft Azure consumption commitments for a billing account or a
* billing profile. Microsoft Azure consumption commitments are only supported for the billing account
* scope.
* @param billingAccountId BillingAccount ID
* @param options The options parameters.
*/
public listByBillingAccount(
billingAccountId: string,
options?: LotsListByBillingAccountOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listByBillingAccountPagingAll(billingAccountId, 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.listByBillingAccountPagingPage(
billingAccountId,
options,
settings
);
}
};
}
private async *listByBillingAccountPagingPage(
billingAccountId: string,
options?: LotsListByBillingAccountOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: LotsListByBillingAccountResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listByBillingAccount(billingAccountId, options);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listByBillingAccountNext(
billingAccountId,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listByBillingAccountPagingAll(
billingAccountId: string,
options?: LotsListByBillingAccountOptionalParams
): AsyncIterableIterator {
for await (const page of this.listByBillingAccountPagingPage(
billingAccountId,
options
)) {
yield* page;
}
}
/**
* Lists all Azure credits and Microsoft Azure consumption commitments for a billing account or a
* billing profile. Microsoft Azure consumption commitments are only supported for the billing account
* scope.
* @param billingAccountId BillingAccount ID
* @param billingProfileId Azure Billing Profile ID.
* @param options The options parameters.
*/
private _listByBillingProfile(
billingAccountId: string,
billingProfileId: string,
options?: LotsListByBillingProfileOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ billingAccountId, billingProfileId, options },
listByBillingProfileOperationSpec
);
}
/**
* Lists all Azure credits and Microsoft Azure consumption commitments for a billing account or a
* billing profile. Microsoft Azure consumption commitments are only supported for the billing account
* scope.
* @param billingAccountId BillingAccount ID
* @param options The options parameters.
*/
private _listByBillingAccount(
billingAccountId: string,
options?: LotsListByBillingAccountOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ billingAccountId, options },
listByBillingAccountOperationSpec
);
}
/**
* ListByBillingProfileNext
* @param billingAccountId BillingAccount ID
* @param billingProfileId Azure Billing Profile ID.
* @param nextLink The nextLink from the previous successful call to the ListByBillingProfile method.
* @param options The options parameters.
*/
private _listByBillingProfileNext(
billingAccountId: string,
billingProfileId: string,
nextLink: string,
options?: LotsListByBillingProfileNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ billingAccountId, billingProfileId, nextLink, options },
listByBillingProfileNextOperationSpec
);
}
/**
* ListByBillingAccountNext
* @param billingAccountId BillingAccount ID
* @param nextLink The nextLink from the previous successful call to the ListByBillingAccount method.
* @param options The options parameters.
*/
private _listByBillingAccountNext(
billingAccountId: string,
nextLink: string,
options?: LotsListByBillingAccountNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ billingAccountId, nextLink, options },
listByBillingAccountNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByBillingProfileOperationSpec: coreClient.OperationSpec = {
path:
"/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}/providers/Microsoft.Consumption/lots",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.Lots
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.billingAccountId,
Parameters.billingProfileId
],
headerParameters: [Parameters.accept],
serializer
};
const listByBillingAccountOperationSpec: coreClient.OperationSpec = {
path:
"/providers/Microsoft.Billing/billingAccounts/{billingAccountId}/providers/Microsoft.Consumption/lots",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.Lots
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
queryParameters: [Parameters.filter, Parameters.apiVersion],
urlParameters: [Parameters.$host, Parameters.billingAccountId],
headerParameters: [Parameters.accept],
serializer
};
const listByBillingProfileNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.Lots
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Parameters.billingAccountId,
Parameters.billingProfileId
],
headerParameters: [Parameters.accept],
serializer
};
const listByBillingAccountNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.Lots
},
default: {
bodyMapper: Mappers.ErrorResponse
}
},
urlParameters: [
Parameters.$host,
Parameters.nextLink,
Parameters.billingAccountId
],
headerParameters: [Parameters.accept],
serializer
};