/*
 * 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 { setContinuationToken } from "../pagingHelper.js";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers.js";
import * as Parameters from "../models/parameters.js";
/// <reference lib="esnext.asynciterable" />
/** Class containing ManagementGroupNetworkManagerConnections operations. */
export class ManagementGroupNetworkManagerConnectionsImpl {
    client;
    /**
     * Initialize a new instance of the class ManagementGroupNetworkManagerConnections class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * List all network manager connections created by this management group.
     * @param managementGroupId The management group Id which uniquely identify the Microsoft Azure
     *                          management group.
     * @param options The options parameters.
     */
    list(managementGroupId, options) {
        const iter = this.listPagingAll(managementGroupId, 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.listPagingPage(managementGroupId, options, settings);
            },
        };
    }
    async *listPagingPage(managementGroupId, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._list(managementGroupId, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            setContinuationToken(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listNext(managementGroupId, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            setContinuationToken(page, continuationToken);
            yield page;
        }
    }
    async *listPagingAll(managementGroupId, options) {
        for await (const page of this.listPagingPage(managementGroupId, options)) {
            yield* page;
        }
    }
    /**
     * Create a network manager connection on this management group.
     * @param managementGroupId The management group Id which uniquely identify the Microsoft Azure
     *                          management group.
     * @param networkManagerConnectionName Name for the network manager connection.
     * @param parameters Network manager connection to be created/updated.
     * @param options The options parameters.
     */
    createOrUpdate(managementGroupId, networkManagerConnectionName, parameters, options) {
        return this.client.sendOperationRequest({ managementGroupId, networkManagerConnectionName, parameters, options }, createOrUpdateOperationSpec);
    }
    /**
     * Get a specified connection created by this management group.
     * @param managementGroupId The management group Id which uniquely identify the Microsoft Azure
     *                          management group.
     * @param networkManagerConnectionName Name for the network manager connection.
     * @param options The options parameters.
     */
    get(managementGroupId, networkManagerConnectionName, options) {
        return this.client.sendOperationRequest({ managementGroupId, networkManagerConnectionName, options }, getOperationSpec);
    }
    /**
     * Delete specified pending connection created by this management group.
     * @param managementGroupId The management group Id which uniquely identify the Microsoft Azure
     *                          management group.
     * @param networkManagerConnectionName Name for the network manager connection.
     * @param options The options parameters.
     */
    delete(managementGroupId, networkManagerConnectionName, options) {
        return this.client.sendOperationRequest({ managementGroupId, networkManagerConnectionName, options }, deleteOperationSpec);
    }
    /**
     * List all network manager connections created by this management group.
     * @param managementGroupId The management group Id which uniquely identify the Microsoft Azure
     *                          management group.
     * @param options The options parameters.
     */
    _list(managementGroupId, options) {
        return this.client.sendOperationRequest({ managementGroupId, options }, listOperationSpec);
    }
    /**
     * ListNext
     * @param managementGroupId The management group Id which uniquely identify the Microsoft Azure
     *                          management group.
     * @param nextLink The nextLink from the previous successful call to the List method.
     * @param options The options parameters.
     */
    _listNext(managementGroupId, nextLink, options) {
        return this.client.sendOperationRequest({ managementGroupId, nextLink, options }, listNextOperationSpec);
    }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const createOrUpdateOperationSpec = {
    path: "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Network/networkManagerConnections/{networkManagerConnectionName}",
    httpMethod: "PUT",
    responses: {
        200: {
            bodyMapper: Mappers.NetworkManagerConnection,
        },
        201: {
            bodyMapper: Mappers.NetworkManagerConnection,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    requestBody: Parameters.parameters38,
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.networkManagerConnectionName,
        Parameters.managementGroupId,
    ],
    headerParameters: [Parameters.accept, Parameters.contentType],
    mediaType: "json",
    serializer,
};
const getOperationSpec = {
    path: "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Network/networkManagerConnections/{networkManagerConnectionName}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.NetworkManagerConnection,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.networkManagerConnectionName,
        Parameters.managementGroupId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const deleteOperationSpec = {
    path: "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Network/networkManagerConnections/{networkManagerConnectionName}",
    httpMethod: "DELETE",
    responses: {
        200: {},
        204: {},
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.networkManagerConnectionName,
        Parameters.managementGroupId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listOperationSpec = {
    path: "/providers/Microsoft.Management/managementGroups/{managementGroupId}/providers/Microsoft.Network/networkManagerConnections",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.NetworkManagerConnectionListResult,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [
        Parameters.apiVersion,
        Parameters.top,
        Parameters.skipToken1,
    ],
    urlParameters: [Parameters.$host, Parameters.managementGroupId],
    headerParameters: [Parameters.accept],
    serializer,
};
const listNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.NetworkManagerConnectionListResult,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    urlParameters: [
        Parameters.$host,
        Parameters.nextLink,
        Parameters.managementGroupId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=managementGroupNetworkManagerConnections.js.map