"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.VipSwapImpl = 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 VipSwap operations. */
class VipSwapImpl {
    client;
    /**
     * Initialize a new instance of the class VipSwap class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Gets the SwapResource which identifies the slot type for the specified cloud service. The slot type
     * on a cloud service can either be Staging or Production
     * @param groupName The name of the resource group.
     * @param resourceName The name of the cloud service.
     * @param options The options parameters.
     */
    get(groupName, resourceName, options) {
        return this.client.sendOperationRequest({ groupName, resourceName, options }, getOperationSpec);
    }
    /**
     * Performs vip swap operation on swappable cloud services.
     * @param groupName The name of the resource group.
     * @param resourceName The name of the cloud service.
     * @param parameters SwapResource object where slot type should be the target slot after vip swap for
     *                   the specified cloud service.
     * @param options The options parameters.
     */
    async beginCreate(groupName, resourceName, parameters, 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: { groupName, resourceName, parameters, options },
            spec: createOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
        });
        await poller.poll();
        return poller;
    }
    /**
     * Performs vip swap operation on swappable cloud services.
     * @param groupName The name of the resource group.
     * @param resourceName The name of the cloud service.
     * @param parameters SwapResource object where slot type should be the target slot after vip swap for
     *                   the specified cloud service.
     * @param options The options parameters.
     */
    async beginCreateAndWait(groupName, resourceName, parameters, options) {
        const poller = await this.beginCreate(groupName, resourceName, parameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Gets the list of SwapResource which identifies the slot type for the specified cloud service. The
     * slot type on a cloud service can either be Staging or Production
     * @param groupName The name of the resource group.
     * @param resourceName The name of the cloud service.
     * @param options The options parameters.
     */
    list(groupName, resourceName, options) {
        return this.client.sendOperationRequest({ groupName, resourceName, options }, listOperationSpec);
    }
}
exports.VipSwapImpl = VipSwapImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const getOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Compute/cloudServices/{resourceName}/providers/Microsoft.Network/cloudServiceSlots/{singletonResource}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.SwapResource,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.groupName,
        Parameters.resourceName,
        Parameters.singletonResource,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const createOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Compute/cloudServices/{resourceName}/providers/Microsoft.Network/cloudServiceSlots/{singletonResource}",
    httpMethod: "PUT",
    responses: {
        200: {},
        201: {},
        202: {},
        204: {},
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    requestBody: Parameters.parameters11,
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.groupName,
        Parameters.resourceName,
        Parameters.singletonResource,
    ],
    headerParameters: [Parameters.accept, Parameters.contentType],
    mediaType: "json",
    serializer,
};
const listOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.Compute/cloudServices/{resourceName}/providers/Microsoft.Network/cloudServiceSlots",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.SwapResourceListResult,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.groupName,
        Parameters.resourceName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=vipSwap.js.map