"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.ExpressRouteGatewaysImpl = void 0;
const tslib_1 = require("tslib");
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");
/** Class containing ExpressRouteGateways operations. */
class ExpressRouteGatewaysImpl {
    client;
    /**
     * Initialize a new instance of the class ExpressRouteGateways class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Lists ExpressRoute gateways under a given subscription.
     * @param options The options parameters.
     */
    listBySubscription(options) {
        return this.client.sendOperationRequest({ options }, listBySubscriptionOperationSpec);
    }
    /**
     * Lists ExpressRoute gateways in a given resource group.
     * @param resourceGroupName The name of the resource group.
     * @param options The options parameters.
     */
    listByResourceGroup(resourceGroupName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, options }, listByResourceGroupOperationSpec);
    }
    /**
     * Creates or updates a ExpressRoute gateway in a specified resource group.
     * @param resourceGroupName The name of the resource group.
     * @param expressRouteGatewayName The name of the ExpressRoute gateway.
     * @param putExpressRouteGatewayParameters Parameters required in an ExpressRoute gateway PUT
     *                                         operation.
     * @param options The options parameters.
     */
    async beginCreateOrUpdate(resourceGroupName, expressRouteGatewayName, putExpressRouteGatewayParameters, 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,
                expressRouteGatewayName,
                putExpressRouteGatewayParameters,
                options,
            },
            spec: createOrUpdateOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
            resourceLocationConfig: "azure-async-operation",
        });
        await poller.poll();
        return poller;
    }
    /**
     * Creates or updates a ExpressRoute gateway in a specified resource group.
     * @param resourceGroupName The name of the resource group.
     * @param expressRouteGatewayName The name of the ExpressRoute gateway.
     * @param putExpressRouteGatewayParameters Parameters required in an ExpressRoute gateway PUT
     *                                         operation.
     * @param options The options parameters.
     */
    async beginCreateOrUpdateAndWait(resourceGroupName, expressRouteGatewayName, putExpressRouteGatewayParameters, options) {
        const poller = await this.beginCreateOrUpdate(resourceGroupName, expressRouteGatewayName, putExpressRouteGatewayParameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Updates express route gateway tags.
     * @param resourceGroupName The resource group name of the ExpressRouteGateway.
     * @param expressRouteGatewayName The name of the gateway.
     * @param expressRouteGatewayParameters Parameters supplied to update a virtual wan express route
     *                                      gateway tags.
     * @param options The options parameters.
     */
    async beginUpdateTags(resourceGroupName, expressRouteGatewayName, expressRouteGatewayParameters, 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,
                expressRouteGatewayName,
                expressRouteGatewayParameters,
                options,
            },
            spec: updateTagsOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
            resourceLocationConfig: "azure-async-operation",
        });
        await poller.poll();
        return poller;
    }
    /**
     * Updates express route gateway tags.
     * @param resourceGroupName The resource group name of the ExpressRouteGateway.
     * @param expressRouteGatewayName The name of the gateway.
     * @param expressRouteGatewayParameters Parameters supplied to update a virtual wan express route
     *                                      gateway tags.
     * @param options The options parameters.
     */
    async beginUpdateTagsAndWait(resourceGroupName, expressRouteGatewayName, expressRouteGatewayParameters, options) {
        const poller = await this.beginUpdateTags(resourceGroupName, expressRouteGatewayName, expressRouteGatewayParameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Fetches the details of a ExpressRoute gateway in a resource group.
     * @param resourceGroupName The name of the resource group.
     * @param expressRouteGatewayName The name of the ExpressRoute gateway.
     * @param options The options parameters.
     */
    get(resourceGroupName, expressRouteGatewayName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, expressRouteGatewayName, options }, getOperationSpec);
    }
    /**
     * Deletes the specified ExpressRoute gateway in a resource group. An ExpressRoute gateway resource can
     * only be deleted when there are no connection subresources.
     * @param resourceGroupName The name of the resource group.
     * @param expressRouteGatewayName The name of the ExpressRoute gateway.
     * @param options The options parameters.
     */
    async beginDelete(resourceGroupName, expressRouteGatewayName, 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, expressRouteGatewayName, options },
            spec: deleteOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
            resourceLocationConfig: "location",
        });
        await poller.poll();
        return poller;
    }
    /**
     * Deletes the specified ExpressRoute gateway in a resource group. An ExpressRoute gateway resource can
     * only be deleted when there are no connection subresources.
     * @param resourceGroupName The name of the resource group.
     * @param expressRouteGatewayName The name of the ExpressRoute gateway.
     * @param options The options parameters.
     */
    async beginDeleteAndWait(resourceGroupName, expressRouteGatewayName, options) {
        const poller = await this.beginDelete(resourceGroupName, expressRouteGatewayName, options);
        return poller.pollUntilDone();
    }
}
exports.ExpressRouteGatewaysImpl = ExpressRouteGatewaysImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listBySubscriptionOperationSpec = {
    path: "/subscriptions/{subscriptionId}/providers/Microsoft.Network/expressRouteGateways",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ExpressRouteGatewayList,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [Parameters.$host, Parameters.subscriptionId],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByResourceGroupOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ExpressRouteGatewayList,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const createOrUpdateOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}",
    httpMethod: "PUT",
    responses: {
        200: {
            bodyMapper: Mappers.ExpressRouteGateway,
        },
        201: {
            bodyMapper: Mappers.ExpressRouteGateway,
        },
        202: {
            bodyMapper: Mappers.ExpressRouteGateway,
        },
        204: {
            bodyMapper: Mappers.ExpressRouteGateway,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    requestBody: Parameters.putExpressRouteGatewayParameters,
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.expressRouteGatewayName,
    ],
    headerParameters: [Parameters.accept, Parameters.contentType],
    mediaType: "json",
    serializer,
};
const updateTagsOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}",
    httpMethod: "PATCH",
    responses: {
        200: {
            bodyMapper: Mappers.ExpressRouteGateway,
        },
        201: {
            bodyMapper: Mappers.ExpressRouteGateway,
        },
        202: {
            bodyMapper: Mappers.ExpressRouteGateway,
        },
        204: {
            bodyMapper: Mappers.ExpressRouteGateway,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    requestBody: Parameters.expressRouteGatewayParameters,
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.expressRouteGatewayName,
    ],
    headerParameters: [Parameters.accept, Parameters.contentType],
    mediaType: "json",
    serializer,
};
const getOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.ExpressRouteGateway,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.expressRouteGatewayName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const deleteOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/expressRouteGateways/{expressRouteGatewayName}",
    httpMethod: "DELETE",
    responses: {
        200: {},
        201: {},
        202: {},
        204: {},
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.expressRouteGatewayName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=expressRouteGateways.js.map