"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.JobPrivateEndpointsImpl = 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 JobPrivateEndpoints operations. */
class JobPrivateEndpointsImpl {
    client;
    /**
     * Initialize a new instance of the class JobPrivateEndpoints class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Gets a list of job agent private endpoints.
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param serverName The name of the server.
     * @param jobAgentName The name of the job agent.
     * @param options The options parameters.
     */
    listByAgent(resourceGroupName, serverName, jobAgentName, options) {
        const iter = this.listByAgentPagingAll(resourceGroupName, serverName, jobAgentName, 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.listByAgentPagingPage(resourceGroupName, serverName, jobAgentName, options, settings);
            },
        };
    }
    async *listByAgentPagingPage(resourceGroupName, serverName, jobAgentName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByAgent(resourceGroupName, serverName, jobAgentName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByAgentNext(resourceGroupName, serverName, jobAgentName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *listByAgentPagingAll(resourceGroupName, serverName, jobAgentName, options) {
        for await (const page of this.listByAgentPagingPage(resourceGroupName, serverName, jobAgentName, options)) {
            yield* page;
        }
    }
    /**
     * Gets a list of job agent private endpoints.
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param serverName The name of the server.
     * @param jobAgentName The name of the job agent.
     * @param options The options parameters.
     */
    _listByAgent(resourceGroupName, serverName, jobAgentName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, jobAgentName, options }, listByAgentOperationSpec);
    }
    /**
     * Gets a private endpoint.
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param serverName The name of the server.
     * @param jobAgentName The name of the job agent.
     * @param privateEndpointName The name of the private endpoint to get.
     * @param options The options parameters.
     */
    get(resourceGroupName, serverName, jobAgentName, privateEndpointName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            privateEndpointName,
            options,
        }, getOperationSpec);
    }
    /**
     * Creates or updates a private endpoint.
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param serverName The name of the server.
     * @param jobAgentName The name of the job agent.
     * @param privateEndpointName The name of the private endpoint.
     * @param parameters The requested private endpoint state.
     * @param options The options parameters.
     */
    async beginCreateOrUpdate(resourceGroupName, serverName, jobAgentName, privateEndpointName, 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: {
                resourceGroupName,
                serverName,
                jobAgentName,
                privateEndpointName,
                parameters,
                options,
            },
            spec: createOrUpdateOperationSpec,
        });
        const poller = await (0, core_lro_1.createHttpPoller)(lro, {
            restoreFrom: options?.resumeFrom,
            intervalInMs: options?.updateIntervalInMs,
            resourceLocationConfig: "location",
        });
        await poller.poll();
        return poller;
    }
    /**
     * Creates or updates a private endpoint.
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param serverName The name of the server.
     * @param jobAgentName The name of the job agent.
     * @param privateEndpointName The name of the private endpoint.
     * @param parameters The requested private endpoint state.
     * @param options The options parameters.
     */
    async beginCreateOrUpdateAndWait(resourceGroupName, serverName, jobAgentName, privateEndpointName, parameters, options) {
        const poller = await this.beginCreateOrUpdate(resourceGroupName, serverName, jobAgentName, privateEndpointName, parameters, options);
        return poller.pollUntilDone();
    }
    /**
     * Deletes a private endpoint.
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param serverName The name of the server.
     * @param jobAgentName The name of the job agent.
     * @param privateEndpointName The name of the private endpoint to delete.
     * @param options The options parameters.
     */
    async beginDelete(resourceGroupName, serverName, jobAgentName, privateEndpointName, 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,
                serverName,
                jobAgentName,
                privateEndpointName,
                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 a private endpoint.
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param serverName The name of the server.
     * @param jobAgentName The name of the job agent.
     * @param privateEndpointName The name of the private endpoint to delete.
     * @param options The options parameters.
     */
    async beginDeleteAndWait(resourceGroupName, serverName, jobAgentName, privateEndpointName, options) {
        const poller = await this.beginDelete(resourceGroupName, serverName, jobAgentName, privateEndpointName, options);
        return poller.pollUntilDone();
    }
    /**
     * ListByAgentNext
     * @param resourceGroupName The name of the resource group that contains the resource. You can obtain
     *                          this value from the Azure Resource Manager API or the portal.
     * @param serverName The name of the server.
     * @param jobAgentName The name of the job agent.
     * @param nextLink The nextLink from the previous successful call to the ListByAgent method.
     * @param options The options parameters.
     */
    _listByAgentNext(resourceGroupName, serverName, jobAgentName, nextLink, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, jobAgentName, nextLink, options }, listByAgentNextOperationSpec);
    }
}
exports.JobPrivateEndpointsImpl = JobPrivateEndpointsImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByAgentOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/privateEndpoints",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobPrivateEndpointListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion4],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const getOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/privateEndpoints/{privateEndpointName}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobPrivateEndpoint,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion4],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.privateEndpointName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const createOrUpdateOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/privateEndpoints/{privateEndpointName}",
    httpMethod: "PUT",
    responses: {
        200: {
            bodyMapper: Mappers.JobPrivateEndpoint,
        },
        201: {
            bodyMapper: Mappers.JobPrivateEndpoint,
        },
        202: {
            bodyMapper: Mappers.JobPrivateEndpoint,
        },
        204: {
            bodyMapper: Mappers.JobPrivateEndpoint,
        },
        default: {},
    },
    requestBody: Parameters.parameters23,
    queryParameters: [Parameters.apiVersion4],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.privateEndpointName,
    ],
    headerParameters: [Parameters.contentType, Parameters.accept],
    mediaType: "json",
    serializer,
};
const deleteOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/privateEndpoints/{privateEndpointName}",
    httpMethod: "DELETE",
    responses: { 200: {}, 201: {}, 202: {}, 204: {}, default: {} },
    queryParameters: [Parameters.apiVersion4],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.privateEndpointName,
    ],
    serializer,
};
const listByAgentNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobPrivateEndpointListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.nextLink,
        Parameters.jobAgentName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=jobPrivateEndpoints.js.map