"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.TimeZonesImpl = void 0;
const tslib_1 = require("tslib");
const pagingHelper_js_1 = require("../pagingHelper.js");
const coreClient = tslib_1.__importStar(require("@azure/core-client"));
const Mappers = tslib_1.__importStar(require("../models/mappers.js"));
const Parameters = tslib_1.__importStar(require("../models/parameters.js"));
/// <reference lib="esnext.asynciterable" />
/** Class containing TimeZones operations. */
class TimeZonesImpl {
    client;
    /**
     * Initialize a new instance of the class TimeZones class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Gets a list of managed instance time zones by location.
     * @param locationName
     * @param options The options parameters.
     */
    listByLocation(locationName, options) {
        const iter = this.listByLocationPagingAll(locationName, options);
        return {
            next() {
                return iter.next();
            },
            [Symbol.asyncIterator]() {
                return this;
            },
            byPage: (settings) => {
                if (settings?.maxPageSize) {
                    throw new Error("maxPageSize is not supported by this operation.");
                }
                return this.listByLocationPagingPage(locationName, options, settings);
            },
        };
    }
    async *listByLocationPagingPage(locationName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByLocation(locationName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByLocationNext(locationName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *listByLocationPagingAll(locationName, options) {
        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.
     */
    _listByLocation(locationName, options) {
        return this.client.sendOperationRequest({ locationName, options }, listByLocationOperationSpec);
    }
    /**
     * Gets a managed instance time zone.
     * @param locationName
     * @param timeZoneId
     * @param options The options parameters.
     */
    get(locationName, timeZoneId, options) {
        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.
     */
    _listByLocationNext(locationName, nextLink, options) {
        return this.client.sendOperationRequest({ locationName, nextLink, options }, listByLocationNextOperationSpec);
    }
}
exports.TimeZonesImpl = TimeZonesImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByLocationOperationSpec = {
    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 = {
    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 = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.TimeZoneListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.nextLink,
        Parameters.locationName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=timeZones.js.map