/*
* 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 { TimeZones } from "../operationsInterfaces";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers";
import * as Parameters from "../models/parameters";
import { SqlManagementClient } from "../sqlManagementClient";
import {
TimeZone,
TimeZonesListByLocationNextOptionalParams,
TimeZonesListByLocationOptionalParams,
TimeZonesListByLocationResponse,
TimeZonesGetOptionalParams,
TimeZonesGetResponse,
TimeZonesListByLocationNextResponse
} from "../models";
///
/** Class containing TimeZones operations. */
export class TimeZonesImpl implements TimeZones {
private readonly client: SqlManagementClient;
/**
* Initialize a new instance of the class TimeZones class.
* @param client Reference to the service client
*/
constructor(client: SqlManagementClient) {
this.client = client;
}
/**
* Gets a list of managed instance time zones by location.
* @param locationName
* @param options The options parameters.
*/
public listByLocation(
locationName: string,
options?: TimeZonesListByLocationOptionalParams
): PagedAsyncIterableIterator {
const iter = this.listByLocationPagingAll(locationName, 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.listByLocationPagingPage(locationName, options, settings);
}
};
}
private async *listByLocationPagingPage(
locationName: string,
options?: TimeZonesListByLocationOptionalParams,
settings?: PageSettings
): AsyncIterableIterator {
let result: TimeZonesListByLocationResponse;
let continuationToken = settings?.continuationToken;
if (!continuationToken) {
result = await this._listByLocation(locationName, options);
let page = result.value || [];
continuationToken = result.nextLink;
setContinuationToken(page, continuationToken);
yield page;
}
while (continuationToken) {
result = await this._listByLocationNext(
locationName,
continuationToken,
options
);
continuationToken = result.nextLink;
let page = result.value || [];
setContinuationToken(page, continuationToken);
yield page;
}
}
private async *listByLocationPagingAll(
locationName: string,
options?: TimeZonesListByLocationOptionalParams
): AsyncIterableIterator {
for await (const page of this.listByLocationPagingPage(
locationName,
options
)) {
yield* page;
}
}
/**
* Gets a list of managed instance time zones by location.
* @param locationName
* @param options The options parameters.
*/
private _listByLocation(
locationName: string,
options?: TimeZonesListByLocationOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ locationName, options },
listByLocationOperationSpec
);
}
/**
* Gets a managed instance time zone.
* @param locationName
* @param timeZoneId
* @param options The options parameters.
*/
get(
locationName: string,
timeZoneId: string,
options?: TimeZonesGetOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ locationName, timeZoneId, options },
getOperationSpec
);
}
/**
* ListByLocationNext
* @param locationName
* @param nextLink The nextLink from the previous successful call to the ListByLocation method.
* @param options The options parameters.
*/
private _listByLocationNext(
locationName: string,
nextLink: string,
options?: TimeZonesListByLocationNextOptionalParams
): Promise {
return this.client.sendOperationRequest(
{ locationName, nextLink, options },
listByLocationNextOperationSpec
);
}
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByLocationOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.TimeZoneListResult
},
default: {}
},
queryParameters: [Parameters.apiVersion3],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.locationName
],
headerParameters: [Parameters.accept],
serializer
};
const getOperationSpec: coreClient.OperationSpec = {
path:
"/subscriptions/{subscriptionId}/providers/Microsoft.Sql/locations/{locationName}/timeZones/{timeZoneId}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.TimeZone
},
default: {}
},
queryParameters: [Parameters.apiVersion3],
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.locationName,
Parameters.timeZoneId
],
headerParameters: [Parameters.accept],
serializer
};
const listByLocationNextOperationSpec: coreClient.OperationSpec = {
path: "{nextLink}",
httpMethod: "GET",
responses: {
200: {
bodyMapper: Mappers.TimeZoneListResult
},
default: {}
},
urlParameters: [
Parameters.$host,
Parameters.subscriptionId,
Parameters.nextLink,
Parameters.locationName
],
headerParameters: [Parameters.accept],
serializer
};