// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
import { setContinuationToken } from "../pagingHelper.js";
import * as coreClient from "@azure/core-client";
import * as Mappers from "../models/mappers.js";
import * as Parameters from "../models/parameters.js";
/// <reference lib="esnext.asynciterable" />
/** Class containing JobVersions operations. */
export class JobVersionsImpl {
    client;
    /**
     * Initialize a new instance of the class JobVersions class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Gets all versions of a job.
     * @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 jobName The name of the job to get.
     * @param options The options parameters.
     */
    listByJob(resourceGroupName, serverName, jobAgentName, jobName, options) {
        const iter = this.listByJobPagingAll(resourceGroupName, serverName, jobAgentName, jobName, 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.listByJobPagingPage(resourceGroupName, serverName, jobAgentName, jobName, options, settings);
            },
        };
    }
    async *listByJobPagingPage(resourceGroupName, serverName, jobAgentName, jobName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByJob(resourceGroupName, serverName, jobAgentName, jobName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            setContinuationToken(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByJobNext(resourceGroupName, serverName, jobAgentName, jobName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            setContinuationToken(page, continuationToken);
            yield page;
        }
    }
    async *listByJobPagingAll(resourceGroupName, serverName, jobAgentName, jobName, options) {
        for await (const page of this.listByJobPagingPage(resourceGroupName, serverName, jobAgentName, jobName, options)) {
            yield* page;
        }
    }
    /**
     * Gets all versions of a job.
     * @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 jobName The name of the job to get.
     * @param options The options parameters.
     */
    _listByJob(resourceGroupName, serverName, jobAgentName, jobName, options) {
        return this.client.sendOperationRequest({ resourceGroupName, serverName, jobAgentName, jobName, options }, listByJobOperationSpec);
    }
    /**
     * Gets a job version.
     * @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 jobName The name of the job.
     * @param jobVersion The version of the job to get.
     * @param options The options parameters.
     */
    get(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            jobVersion,
            options,
        }, getOperationSpec);
    }
    /**
     * ListByJobNext
     * @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 jobName The name of the job to get.
     * @param nextLink The nextLink from the previous successful call to the ListByJob method.
     * @param options The options parameters.
     */
    _listByJobNext(resourceGroupName, serverName, jobAgentName, jobName, nextLink, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            nextLink,
            options,
        }, listByJobNextOperationSpec);
    }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByJobOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobVersionListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.jobName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const getOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobVersion,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.jobVersion,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByJobNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobVersionListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.nextLink,
        Parameters.jobAgentName,
        Parameters.jobName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=jobVersions.js.map