"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.FirewallPolicyDeploymentsImpl = 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 FirewallPolicyDeployments operations. */
class FirewallPolicyDeploymentsImpl {
    client;
    /**
     * Initialize a new instance of the class FirewallPolicyDeployments class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Deploys the firewall policy draft and child rule collection group drafts.
     * @param resourceGroupName The name of the resource group.
     * @param firewallPolicyName The name of the Firewall Policy.
     * @param options The options parameters.
     */
    async beginDeploy(resourceGroupName, firewallPolicyName, 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, firewallPolicyName, options },
            spec: deployOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
            resourceLocationConfig: "azure-async-operation",
        });
        await poller.poll();
        return poller;
    }
    /**
     * Deploys the firewall policy draft and child rule collection group drafts.
     * @param resourceGroupName The name of the resource group.
     * @param firewallPolicyName The name of the Firewall Policy.
     * @param options The options parameters.
     */
    async beginDeployAndWait(resourceGroupName, firewallPolicyName, options) {
        const poller = await this.beginDeploy(resourceGroupName, firewallPolicyName, options);
        return poller.pollUntilDone();
    }
}
exports.FirewallPolicyDeploymentsImpl = FirewallPolicyDeploymentsImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const deployOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/firewallPolicies/{firewallPolicyName}/deploy",
    httpMethod: "POST",
    responses: {
        200: {
            headersMapper: Mappers.FirewallPolicyDeploymentsDeployHeaders,
        },
        201: {
            headersMapper: Mappers.FirewallPolicyDeploymentsDeployHeaders,
        },
        202: {
            headersMapper: Mappers.FirewallPolicyDeploymentsDeployHeaders,
        },
        204: {
            headersMapper: Mappers.FirewallPolicyDeploymentsDeployHeaders,
        },
        default: {
            bodyMapper: Mappers.CloudError,
        },
    },
    queryParameters: [Parameters.apiVersion],
    urlParameters: [
        Parameters.$host,
        Parameters.resourceGroupName,
        Parameters.subscriptionId,
        Parameters.firewallPolicyName1,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=firewallPolicyDeployments.js.map