"use strict";
/*
 * 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.
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.VpnLinkConnectionsImpl = 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"));
const core_lro_1 = require("@azure/core-lro");
const lroImpl_js_1 = require("../lroImpl.js");
/// <reference lib="esnext.asynciterable" />
/** Class containing VpnLinkConnections operations. */
class VpnLinkConnectionsImpl {
    client;
    /**
     * Initialize a new instance of the class VpnLinkConnections class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Lists all shared keys of VpnLink connection specified.
     * @param resourceGroupName The name of the resource group.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param linkConnectionName The name of the vpn link connection.
     * @param options The options parameters.
     */
    listAllSharedKeys(resourceGroupName, gatewayName, connectionName, linkConnectionName, options) {
        const iter = this.getAllSharedKeysPagingAll(resourceGroupName, gatewayName, connectionName, linkConnectionName, 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.getAllSharedKeysPagingPage(resourceGroupName, gatewayName, connectionName, linkConnectionName, options, settings);
            },
        };
    }
    async *getAllSharedKeysPagingPage(resourceGroupName, gatewayName, connectionName, linkConnectionName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._getAllSharedKeys(resourceGroupName, gatewayName, connectionName, linkConnectionName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._getAllSharedKeysNext(resourceGroupName, gatewayName, connectionName, linkConnectionName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *getAllSharedKeysPagingAll(resourceGroupName, gatewayName, connectionName, linkConnectionName, options) {
        for await (const page of this.getAllSharedKeysPagingPage(resourceGroupName, gatewayName, connectionName, linkConnectionName, options)) {
            yield* page;
        }
    }
    /**
     * Retrieves all vpn site link connections for a particular virtual wan vpn gateway vpn connection.
     * @param resourceGroupName The resource group name of the vpn gateway.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param options The options parameters.
     */
    listByVpnConnection(resourceGroupName, gatewayName, connectionName, options) {
        const iter = this.listByVpnConnectionPagingAll(resourceGroupName, gatewayName, connectionName, 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.listByVpnConnectionPagingPage(resourceGroupName, gatewayName, connectionName, options, settings);
            },
        };
    }
    async *listByVpnConnectionPagingPage(resourceGroupName, gatewayName, connectionName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByVpnConnection(resourceGroupName, gatewayName, connectionName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByVpnConnectionNext(resourceGroupName, gatewayName, connectionName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *listByVpnConnectionPagingAll(resourceGroupName, gatewayName, connectionName, options) {
        for await (const page of this.listByVpnConnectionPagingPage(resourceGroupName, gatewayName, connectionName, options)) {
            yield* page;
        }
    }
    /**
     * Resets the VpnLink connection specified.
     * @param resourceGroupName The name of the resource group.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param linkConnectionName The name of the vpn link connection.
     * @param options The options parameters.
     */
    async beginResetConnection(resourceGroupName, gatewayName, connectionName, linkConnectionName, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: {
                resourceGroupName,
                gatewayName,
                connectionName,
                linkConnectionName,
                options,
            },
            spec: resetConnectionOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
            resourceLocationConfig: "location",
        });
        await poller.poll();
        return poller;
    }
    /**
     * Resets the VpnLink connection specified.
     * @param resourceGroupName The name of the resource group.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param linkConnectionName The name of the vpn link connection.
     * @param options The options parameters.
     */
    async beginResetConnectionAndWait(resourceGroupName, gatewayName, connectionName, linkConnectionName, options) {
        const poller = await this.beginResetConnection(resourceGroupName, gatewayName, connectionName, linkConnectionName, options);
        return poller.pollUntilDone();
    }
    /**
     * Lists all shared keys of VpnLink connection specified.
     * @param resourceGroupName The name of the resource group.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param linkConnectionName The name of the vpn link connection.
     * @param options The options parameters.
     */
    _getAllSharedKeys(resourceGroupName, gatewayName, connectionName, linkConnectionName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            gatewayName,
            connectionName,
            linkConnectionName,
            options,
        }, getAllSharedKeysOperationSpec);
    }
    /**
     * Gets the shared key of VpnLink connection specified.
     * @param resourceGroupName The name of the resource group.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param linkConnectionName The name of the vpn link connection.
     * @param options The options parameters.
     */
    getDefaultSharedKey(resourceGroupName, gatewayName, connectionName, linkConnectionName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            gatewayName,
            connectionName,
            linkConnectionName,
            options,
        }, getDefaultSharedKeyOperationSpec);
    }
    /**
     * Sets or auto generates the shared key based on the user input. If users give a shared key value, it
     * does the set operation. If key length is given, the operation creates a random key of the
     * pre-defined length.
     * @param resourceGroupName The resource group name of the VpnGateway.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the connection.
     * @param linkConnectionName The name of the vpn link connection.
     * @param connectionSharedKeyParameters Parameters supplied to set or auto generate the shared key for
     *                                      the vpn link connection.
     * @param options The options parameters.
     */
    async beginSetOrInitDefaultSharedKey(resourceGroupName, gatewayName, connectionName, linkConnectionName, connectionSharedKeyParameters, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: {
                resourceGroupName,
                gatewayName,
                connectionName,
                linkConnectionName,
                connectionSharedKeyParameters,
                options,
            },
            spec: setOrInitDefaultSharedKeyOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
            resourceLocationConfig: "azure-async-operation",
        });
        await poller.poll();
        return poller;
    }
    /**
     * Sets or auto generates the shared key based on the user input. If users give a shared key value, it
     * does the set operation. If key length is given, the operation creates a random key of the
     * pre-defined length.
     * @param resourceGroupName The resource group name of the VpnGateway.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the connection.
     * @param linkConnectionName The name of the vpn link connection.
     * @param connectionSharedKeyParameters Parameters supplied to set or auto generate the shared key for
     *                                      the vpn link connection.
     * @param options The options parameters.
     */
    async beginSetOrInitDefaultSharedKeyAndWait(resourceGroupName, gatewayName, connectionName, linkConnectionName, connectionSharedKeyParameters, options) {
        const poller = await this.beginSetOrInitDefaultSharedKey(resourceGroupName, gatewayName, connectionName, linkConnectionName, connectionSharedKeyParameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Gets the value of the shared key of VpnLink connection specified.
     * @param resourceGroupName The name of the resource group.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param linkConnectionName The name of the vpn link connection.
     * @param options The options parameters.
     */
    listDefaultSharedKey(resourceGroupName, gatewayName, connectionName, linkConnectionName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            gatewayName,
            connectionName,
            linkConnectionName,
            options,
        }, listDefaultSharedKeyOperationSpec);
    }
    /**
     * Lists IKE Security Associations for Vpn Site Link Connection in the specified resource group.
     * @param resourceGroupName The name of the resource group.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param linkConnectionName The name of the vpn link connection.
     * @param options The options parameters.
     */
    async beginGetIkeSas(resourceGroupName, gatewayName, connectionName, linkConnectionName, options) {
        const directSendOperation = async (args, spec) => {
            return this.client.sendOperationRequest(args, spec);
        };
        const sendOperationFn = async (args, spec) => {
            let currentRawResponse = undefined;
            const providedCallback = args.options?.onResponse;
            const callback = (rawResponse, flatResponse) => {
                currentRawResponse = rawResponse;
                providedCallback?.(rawResponse, flatResponse);
            };
            const updatedArgs = {
                ...args,
                options: {
                    ...args.options,
                    onResponse: callback,
                },
            };
            const flatResponse = await directSendOperation(updatedArgs, spec);
            return {
                flatResponse,
                rawResponse: {
                    statusCode: currentRawResponse.status,
                    body: currentRawResponse.parsedBody,
                    headers: currentRawResponse.headers.toJSON(),
                },
            };
        };
        const lro = (0, lroImpl_js_1.createLroSpec)({
            sendOperationFn,
            args: {
                resourceGroupName,
                gatewayName,
                connectionName,
                linkConnectionName,
                options,
            },
            spec: getIkeSasOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
            resourceLocationConfig: "location",
        });
        await poller.poll();
        return poller;
    }
    /**
     * Lists IKE Security Associations for Vpn Site Link Connection in the specified resource group.
     * @param resourceGroupName The name of the resource group.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param linkConnectionName The name of the vpn link connection.
     * @param options The options parameters.
     */
    async beginGetIkeSasAndWait(resourceGroupName, gatewayName, connectionName, linkConnectionName, options) {
        const poller = await this.beginGetIkeSas(resourceGroupName, gatewayName, connectionName, linkConnectionName, options);
        return poller.pollUntilDone();
    }
    /**
     * Retrieves all vpn site link connections for a particular virtual wan vpn gateway vpn connection.
     * @param resourceGroupName The resource group name of the vpn gateway.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param options The options parameters.
     */
    _listByVpnConnection(resourceGroupName, gatewayName, connectionName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, gatewayName, connectionName, options }, listByVpnConnectionOperationSpec);
    }
    /**
     * GetAllSharedKeysNext
     * @param resourceGroupName The name of the resource group.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param linkConnectionName The name of the vpn link connection.
     * @param nextLink The nextLink from the previous successful call to the GetAllSharedKeys method.
     * @param options The options parameters.
     */
    _getAllSharedKeysNext(resourceGroupName, gatewayName, connectionName, linkConnectionName, nextLink, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            gatewayName,
            connectionName,
            linkConnectionName,
            nextLink,
            options,
        }, getAllSharedKeysNextOperationSpec);
    }
    /**
     * ListByVpnConnectionNext
     * @param resourceGroupName The resource group name of the vpn gateway.
     * @param gatewayName The name of the gateway.
     * @param connectionName The name of the vpn connection.
     * @param nextLink The nextLink from the previous successful call to the ListByVpnConnection method.
     * @param options The options parameters.
     */
    _listByVpnConnectionNext(resourceGroupName, gatewayName, connectionName, nextLink, options) {
        return this.client.sendOperationRequest({ resourceGroupName, gatewayName, connectionName, nextLink, options }, listByVpnConnectionNextOperationSpec);
    }
}
exports.VpnLinkConnectionsImpl = VpnLinkConnectionsImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const resetConnectionOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections/{linkConnectionName}/resetconnection",
    httpMethod: "POST",
    responses: {
        200: {},
        201: {},
        202: {},
        204: {},
        default: {
            bodyMapper: Mappers.ErrorResponse,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.connectionName,
        Parameters.gatewayName,
        Parameters.linkConnectionName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const getAllSharedKeysOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections/{linkConnectionName}/sharedKeys",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ConnectionSharedKeyResultList,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.connectionName,
        Parameters.gatewayName,
        Parameters.linkConnectionName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const getDefaultSharedKeyOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections/{linkConnectionName}/sharedKeys/default",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ConnectionSharedKeyResult,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.connectionName,
        Parameters.gatewayName,
        Parameters.linkConnectionName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const setOrInitDefaultSharedKeyOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections/{linkConnectionName}/sharedKeys/default",
    httpMethod: "PUT",
    responses: {
        200: {
            bodyMapper: Mappers.ConnectionSharedKeyResult,
        },
        201: {
            bodyMapper: Mappers.ConnectionSharedKeyResult,
        },
        202: {
            bodyMapper: Mappers.ConnectionSharedKeyResult,
        },
        204: {
            bodyMapper: Mappers.ConnectionSharedKeyResult,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    requestBody: Parameters.connectionSharedKeyParameters,
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.connectionName,
        Parameters.gatewayName,
        Parameters.linkConnectionName,
    ],
    headerParameters: [Parameters.accept, Parameters.contentType],
    mediaType: "json",
    serializer,
};
const listDefaultSharedKeyOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections/{linkConnectionName}/sharedKeys/default/listSharedKey",
    httpMethod: "POST",
    responses: {
        200: {
            bodyMapper: Mappers.ConnectionSharedKeyResult,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.connectionName,
        Parameters.gatewayName,
        Parameters.linkConnectionName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const getIkeSasOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections/{linkConnectionName}/getikesas",
    httpMethod: "POST",
    responses: {
        200: {
            bodyMapper: { type: { name: "String" } },
        },
        201: {
            bodyMapper: { type: { name: "String" } },
        },
        202: {
            bodyMapper: { type: { name: "String" } },
        },
        204: {
            bodyMapper: { type: { name: "String" } },
        },
        default: {
            bodyMapper: Mappers.ErrorResponse,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.connectionName,
        Parameters.gatewayName,
        Parameters.linkConnectionName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByVpnConnectionOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/vpnGateways/{gatewayName}/vpnConnections/{connectionName}/vpnLinkConnections",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ListVpnSiteLinkConnectionsResult,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.connectionName,
        Parameters.gatewayName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const getAllSharedKeysNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ConnectionSharedKeyResultList,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.nextLink,
        Parameters.connectionName,
        Parameters.gatewayName,
        Parameters.linkConnectionName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByVpnConnectionNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ListVpnSiteLinkConnectionsResult,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.nextLink,
        Parameters.connectionName,
        Parameters.gatewayName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=vpnLinkConnections.js.map