/*
* 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 { Labs } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { EducationManagementClient } from "../educationManagementClient";
import {
LabDetails,
LabsListAllNextOptionalParams,
LabsListAllOptionalParams,
LabsListAllResponse,
LabsListNextOptionalParams,
LabsListOptionalParams,
LabsListResponse,
LabsGetOptionalParams,
LabsGetResponse,
LabsDeleteOptionalParams,
LabsCreateOrUpdateOptionalParams,
LabsCreateOrUpdateResponse,
InviteCodeGenerateRequest,
LabsGenerateInviteCodeOptionalParams,
LabsGenerateInviteCodeResponse,
LabsListAllNextResponse,
LabsListNextResponse
} from "../models";
///
/** Class containing Labs operations. */
export class LabsImpl implements Labs {
private readonly client: EducationManagementClient;
/**
* Initialize a new instance of the class Labs class.
* @param client Reference to the service client
*/
constructor(client: EducationManagementClient) {
this.client = client;
}
/**
* Get a list of labs associated with the provided billing account name and billing profile name.
* @param billingAccountName Billing account name.
* @param billingProfileName Billing profile name.
* @param options The options parameters.
*/
public listAll(
billingAccountName: string,
billingProfileName: string,
options?: LabsListAllOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listAllPagingAll(
billingAccountName,
billingProfileName,
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.listAllPagingPage(
billingAccountName,
billingProfileName,
options,
settings
);
}
};
}
private async *listAllPagingPage(
billingAccountName: string,
billingProfileName: string,
options?: LabsListAllOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: LabsListAllResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listAll(
billingAccountName,
billingProfileName,
options
);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listAllNext(
billingAccountName,
billingProfileName,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listAllPagingAll(
billingAccountName: string,
billingProfileName: string,
options?: LabsListAllOptionalParams
): AsyncIterableIterator {
for await (const page of this.listAllPagingPage(
billingAccountName,
billingProfileName,
options
)) {
yield* page;
}
}
/**
* Get the details for a specific lab associated with the provided billing account name, billing
* profile name, and invoice section name.
* @param billingAccountName Billing account name.
* @param billingProfileName Billing profile name.
* @param invoiceSectionName Invoice section name.
* @param options The options parameters.
*/
public list(
billingAccountName: string,
billingProfileName: string,
invoiceSectionName: string,
options?: LabsListOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listPagingAll(
billingAccountName,
billingProfileName,
invoiceSectionName,
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(
billingAccountName,
billingProfileName,
invoiceSectionName,
options,
settings
);
}
};
}
private async *listPagingPage(
billingAccountName: string,
billingProfileName: string,
invoiceSectionName: string,
options?: LabsListOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: LabsListResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._list(
billingAccountName,
billingProfileName,
invoiceSectionName,
options
);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listNext(
billingAccountName,
billingProfileName,
invoiceSectionName,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listPagingAll(
billingAccountName: string,
billingProfileName: string,
invoiceSectionName: string,
options?: LabsListOptionalParams
): AsyncIterableIterator {
for await (const page of this.listPagingPage(
billingAccountName,
billingProfileName,
invoiceSectionName,
options
)) {
yield* page;
}
}
/**
* Get a list of labs associated with the provided billing account name and billing profile name.
* @param billingAccountName Billing account name.
* @param billingProfileName Billing profile name.
* @param options The options parameters.
*/
private _listAll(
billingAccountName: string,
billingProfileName: string,
options?: LabsListAllOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ billingAccountName, billingProfileName, options },
listAllOperationSpec
);
}
/**
* Get the details for a specific lab associated with the provided billing account name, billing
* profile name, and invoice section name.
* @param billingAccountName Billing account name.
* @param billingProfileName Billing profile name.
* @param invoiceSectionName Invoice section name.
* @param options The options parameters.
*/
private _list(
billingAccountName: string,
billingProfileName: string,
invoiceSectionName: string,
options?: LabsListOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ billingAccountName, billingProfileName, invoiceSectionName, options },
listOperationSpec
);
}
/**
* Get the details for a specific lab associated with the provided billing account name, billing
* profile name, and invoice section name.
* @param billingAccountName Billing account name.
* @param billingProfileName Billing profile name.
* @param invoiceSectionName Invoice section name.
* @param options The options parameters.
*/
get(
billingAccountName: string,
billingProfileName: string,
invoiceSectionName: string,
options?: LabsGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ billingAccountName, billingProfileName, invoiceSectionName, options },
getOperationSpec
);
}
/**
* Delete a specific lab associated with the provided billing account name, billing profile name, and
* invoice section name. Note all students must be removed from the lab in order to delete the lab.
* @param billingAccountName Billing account name.
* @param billingProfileName Billing profile name.
* @param invoiceSectionName Invoice section name.
* @param options The options parameters.
*/
delete(
billingAccountName: string,
billingProfileName: string,
invoiceSectionName: string,
options?: LabsDeleteOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ billingAccountName, billingProfileName, invoiceSectionName, options },
deleteOperationSpec
);
}
/**
* Create a new lab or update a previously created lab.
* @param billingAccountName Billing account name.
* @param billingProfileName Billing profile name.
* @param invoiceSectionName Invoice section name.
* @param parameters Request parameters that are provided to create lab resource.
* @param options The options parameters.
*/
createOrUpdate(
billingAccountName: string,
billingProfileName: string,
invoiceSectionName: string,
parameters: LabDetails,
options?: LabsCreateOrUpdateOptionalParams
): Promise {
return this.client.sendOperationRequest(
{
billingAccountName,
billingProfileName,
invoiceSectionName,
parameters,
options
},
createOrUpdateOperationSpec
);
}
/**
* Generate invite code for a lab
* @param billingAccountName Billing account name.
* @param billingProfileName Billing profile name.
* @param invoiceSectionName Invoice section name.
* @param parameters Request parameters that are provided to generate invite code.
* @param options The options parameters.
*/
generateInviteCode(
billingAccountName: string,
billingProfileName: string,
invoiceSectionName: string,
parameters: InviteCodeGenerateRequest,
options?: LabsGenerateInviteCodeOptionalParams
): Promise {
return this.client.sendOperationRequest(
{
billingAccountName,
billingProfileName,
invoiceSectionName,
parameters,
options
},
generateInviteCodeOperationSpec
);
}
/**
* ListAllNext
* @param billingAccountName Billing account name.
* @param billingProfileName Billing profile name.
* @param nextLink The nextLink from the previous successful call to the ListAll method.
* @param options The options parameters.
*/
private _listAllNext(
billingAccountName: string,
billingProfileName: string,
nextLink: string,
options?: LabsListAllNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ billingAccountName, billingProfileName, nextLink, options },
listAllNextOperationSpec
);
}
/**
* ListNext
* @param billingAccountName Billing account name.
* @param billingProfileName Billing profile name.
* @param invoiceSectionName Invoice section name.
* @param nextLink The nextLink from the previous successful call to the List method.
* @param options The options parameters.
*/
private _listNext(
billingAccountName: string,
billingProfileName: string,
invoiceSectionName: string,
nextLink: string,
options?: LabsListNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{
billingAccountName,
billingProfileName,
invoiceSectionName,
nextLink,
options
},
listNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listAllOperationSpec: coreClient.OperationSpec = {
path:
"/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/providers/Microsoft.Education/labs",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.LabListResult
},
default: {
bodyMapper: Mappers.ErrorResponseBody
}
},
queryParameters: [
Parameters.apiVersion,
Parameters.includeBudget,
Parameters.includeDeleted
],
urlParameters: [
Parameters.$host,
Parameters.billingAccountName,
Parameters.billingProfileName
],
headerParameters: [Parameters.accept],
serializer
};
const listOperationSpec: coreClient.OperationSpec = {
path:
"/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName}/providers/Microsoft.Education/labs",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.LabListResult
},
default: {
bodyMapper: Mappers.ErrorResponseBody
}
},
queryParameters: [Parameters.apiVersion, Parameters.includeBudget],
urlParameters: [
Parameters.$host,
Parameters.billingAccountName,
Parameters.billingProfileName,
Parameters.invoiceSectionName
],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path:
"/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName}/providers/Microsoft.Education/labs/default",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.LabDetails
},
default: {
bodyMapper: Mappers.ErrorResponseBody
}
},
queryParameters: [Parameters.apiVersion, Parameters.includeBudget],
urlParameters: [
Parameters.$host,
Parameters.billingAccountName,
Parameters.billingProfileName,
Parameters.invoiceSectionName
],
headerParameters: [Parameters.accept],
serializer
};
const deleteOperationSpec: coreClient.OperationSpec = {
path:
"/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName}/providers/Microsoft.Education/labs/default",
httpMethod: "DELETE",
responses: {
200: {},
204: {},
default: {
bodyMapper: Mappers.ErrorResponseBody
}
},
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.billingAccountName,
Parameters.billingProfileName,
Parameters.invoiceSectionName
],
headerParameters: [Parameters.accept],
serializer
};
const createOrUpdateOperationSpec: coreClient.OperationSpec = {
path:
"/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName}/providers/Microsoft.Education/labs/default",
httpMethod: "PUT",
responses: {
200: {
bodyMapper: Mappers.LabDetails
},
201: {
bodyMapper: Mappers.LabDetails
},
default: {
bodyMapper: Mappers.ErrorResponseBody
}
},
requestBody: Parameters.parameters,
queryParameters: [Parameters.apiVersion],
urlParameters: [
Parameters.$host,
Parameters.billingAccountName,
Parameters.billingProfileName,
Parameters.invoiceSectionName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const generateInviteCodeOperationSpec: coreClient.OperationSpec = {
path:
"/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}/invoiceSections/{invoiceSectionName}/providers/Microsoft.Education/labs/default/generateInviteCode",
httpMethod: "POST",
responses: {
200: {
bodyMapper: Mappers.LabDetails
},
default: {
bodyMapper: Mappers.ErrorResponseBody
}
},
requestBody: Parameters.parameters1,
queryParameters: [
Parameters.apiVersion,
Parameters.onlyUpdateStudentCountParameter
],
urlParameters: [
Parameters.$host,
Parameters.billingAccountName,
Parameters.billingProfileName,
Parameters.invoiceSectionName
],
headerParameters: [Parameters.accept, Parameters.contentType],
mediaType: "json",
serializer
};
const listAllNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.LabListResult
},
default: {
bodyMapper: Mappers.ErrorResponseBody
}
},
urlParameters: [
Parameters.$host,
Parameters.billingAccountName,
Parameters.billingProfileName,
Parameters.nextLink
],
headerParameters: [Parameters.accept],
serializer
};
const listNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.LabListResult
},
default: {
bodyMapper: Mappers.ErrorResponseBody
}
},
urlParameters: [
Parameters.$host,
Parameters.billingAccountName,
Parameters.billingProfileName,
Parameters.nextLink,
Parameters.invoiceSectionName
],
headerParameters: [Parameters.accept],
serializer
};