"use strict";
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
Object.defineProperty(exports, "__esModule", { value: true });
exports.JobStepsImpl = 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"));
/// <reference lib="esnext.asynciterable" />
/** Class containing JobSteps operations. */
class JobStepsImpl {
    client;
    /**
     * Initialize a new instance of the class JobSteps class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Gets all job steps in the specified 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 to get.
     * @param jobVersion The version of the job to get.
     * @param options The options parameters.
     */
    listByVersion(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, options) {
        const iter = this.listByVersionPagingAll(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, 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.listByVersionPagingPage(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, options, settings);
            },
        };
    }
    async *listByVersionPagingPage(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByVersion(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByVersionNext(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
    }
    async *listByVersionPagingAll(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, options) {
        for await (const page of this.listByVersionPagingPage(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, options)) {
            yield* page;
        }
    }
    /**
     * Gets all job steps for a job's current 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 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;
            (0, pagingHelper_js_1.setContinuationToken)(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByJobNext(resourceGroupName, serverName, jobAgentName, jobName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            (0, pagingHelper_js_1.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 job steps in the specified 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 to get.
     * @param jobVersion The version of the job to get.
     * @param options The options parameters.
     */
    _listByVersion(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            jobVersion,
            options,
        }, listByVersionOperationSpec);
    }
    /**
     * Gets the specified version of a job step.
     * @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 stepName The name of the job step.
     * @param options The options parameters.
     */
    getByVersion(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, stepName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            jobVersion,
            stepName,
            options,
        }, getByVersionOperationSpec);
    }
    /**
     * Gets all job steps for a job's current 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 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 step in a job's current 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 stepName The name of the job step.
     * @param options The options parameters.
     */
    get(resourceGroupName, serverName, jobAgentName, jobName, stepName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            stepName,
            options,
        }, getOperationSpec);
    }
    /**
     * Creates or updates a job step. This will implicitly create a new 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 stepName The name of the job step.
     * @param parameters The requested state of the job step.
     * @param options The options parameters.
     */
    createOrUpdate(resourceGroupName, serverName, jobAgentName, jobName, stepName, parameters, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            stepName,
            parameters,
            options,
        }, createOrUpdateOperationSpec);
    }
    /**
     * Deletes a job step. This will implicitly create a new 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 stepName The name of the job step to delete.
     * @param options The options parameters.
     */
    delete(resourceGroupName, serverName, jobAgentName, jobName, stepName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            stepName,
            options,
        }, deleteOperationSpec);
    }
    /**
     * ListByVersionNext
     * @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 jobVersion The version of the job to get.
     * @param nextLink The nextLink from the previous successful call to the ListByVersion method.
     * @param options The options parameters.
     */
    _listByVersionNext(resourceGroupName, serverName, jobAgentName, jobName, jobVersion, nextLink, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            jobVersion,
            nextLink,
            options,
        }, listByVersionNextOperationSpec);
    }
    /**
     * 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);
    }
}
exports.JobStepsImpl = JobStepsImpl;
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByVersionOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobStepListResult,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.jobVersion,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const getByVersionOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/versions/{jobVersion}/steps/{stepName}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobStep,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.stepName,
        Parameters.jobVersion,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByJobOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobStepListResult,
        },
        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}/steps/{stepName}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobStep,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.stepName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const createOrUpdateOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}",
    httpMethod: "PUT",
    responses: {
        200: {
            bodyMapper: Mappers.JobStep,
        },
        201: {
            bodyMapper: Mappers.JobStep,
        },
        default: {},
    },
    requestBody: Parameters.parameters25,
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.stepName,
    ],
    headerParameters: [Parameters.contentType, Parameters.accept],
    mediaType: "json",
    serializer,
};
const deleteOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/steps/{stepName}",
    httpMethod: "DELETE",
    responses: { 200: {}, 204: {}, default: {} },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.stepName,
    ],
    serializer,
};
const listByVersionNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobStepListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.nextLink,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.jobVersion,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByJobNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobStepListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.nextLink,
        Parameters.jobAgentName,
        Parameters.jobName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=jobSteps.js.map