// 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 JobTargetExecutions operations. */
export class JobTargetExecutionsImpl {
    client;
    /**
     * Initialize a new instance of the class JobTargetExecutions class.
     * @param client Reference to the service client
     */
    constructor(client) {
        this.client = client;
    }
    /**
     * Lists target executions for all steps of a job execution.
     * @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 jobExecutionId The id of the job execution
     * @param options The options parameters.
     */
    listByJobExecution(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, options) {
        const iter = this.listByJobExecutionPagingAll(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, 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.listByJobExecutionPagingPage(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, options, settings);
            },
        };
    }
    async *listByJobExecutionPagingPage(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByJobExecution(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            setContinuationToken(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByJobExecutionNext(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            setContinuationToken(page, continuationToken);
            yield page;
        }
    }
    async *listByJobExecutionPagingAll(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, options) {
        for await (const page of this.listByJobExecutionPagingPage(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, options)) {
            yield* page;
        }
    }
    /**
     * Lists the target executions of a job step execution.
     * @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 jobExecutionId The id of the job execution
     * @param stepName The name of the step.
     * @param options The options parameters.
     */
    listByStep(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, stepName, options) {
        const iter = this.listByStepPagingAll(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, stepName, 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.listByStepPagingPage(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, stepName, options, settings);
            },
        };
    }
    async *listByStepPagingPage(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, stepName, options, settings) {
        let result;
        let continuationToken = settings?.continuationToken;
        if (!continuationToken) {
            result = await this._listByStep(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, stepName, options);
            let page = result.value || [];
            continuationToken = result.nextLink;
            setContinuationToken(page, continuationToken);
            yield page;
        }
        while (continuationToken) {
            result = await this._listByStepNext(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, stepName, continuationToken, options);
            continuationToken = result.nextLink;
            let page = result.value || [];
            setContinuationToken(page, continuationToken);
            yield page;
        }
    }
    async *listByStepPagingAll(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, stepName, options) {
        for await (const page of this.listByStepPagingPage(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, stepName, options)) {
            yield* page;
        }
    }
    /**
     * Lists target executions for all steps of a job execution.
     * @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 jobExecutionId The id of the job execution
     * @param options The options parameters.
     */
    _listByJobExecution(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            jobExecutionId,
            options,
        }, listByJobExecutionOperationSpec);
    }
    /**
     * Lists the target executions of a job step execution.
     * @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 jobExecutionId The id of the job execution
     * @param stepName The name of the step.
     * @param options The options parameters.
     */
    _listByStep(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, stepName, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            jobExecutionId,
            stepName,
            options,
        }, listByStepOperationSpec);
    }
    /**
     * Gets a target execution.
     * @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 jobExecutionId The unique id of the job execution
     * @param stepName The name of the step.
     * @param targetId The target id.
     * @param options The options parameters.
     */
    get(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, stepName, targetId, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            jobExecutionId,
            stepName,
            targetId,
            options,
        }, getOperationSpec);
    }
    /**
     * ListByJobExecutionNext
     * @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 jobExecutionId The id of the job execution
     * @param nextLink The nextLink from the previous successful call to the ListByJobExecution method.
     * @param options The options parameters.
     */
    _listByJobExecutionNext(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, nextLink, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            jobExecutionId,
            nextLink,
            options,
        }, listByJobExecutionNextOperationSpec);
    }
    /**
     * ListByStepNext
     * @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 jobExecutionId The id of the job execution
     * @param stepName The name of the step.
     * @param nextLink The nextLink from the previous successful call to the ListByStep method.
     * @param options The options parameters.
     */
    _listByStepNext(resourceGroupName, serverName, jobAgentName, jobName, jobExecutionId, stepName, nextLink, options) {
        return this.client.sendOperationRequest({
            resourceGroupName,
            serverName,
            jobAgentName,
            jobName,
            jobExecutionId,
            stepName,
            nextLink,
            options,
        }, listByStepNextOperationSpec);
    }
}
// Operation Specifications
const serializer = coreClient.createSerializer(Mappers, /* isXml */ false);
const listByJobExecutionOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/targets",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobExecutionListResult,
        },
        default: {},
    },
    queryParameters: [
        Parameters.skip,
        Parameters.apiVersion3,
        Parameters.createTimeMin,
        Parameters.createTimeMax,
        Parameters.endTimeMin,
        Parameters.endTimeMax,
        Parameters.isActive,
        Parameters.top,
    ],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.jobExecutionId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByStepOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobExecutionListResult,
        },
        default: {},
    },
    queryParameters: [
        Parameters.skip,
        Parameters.apiVersion3,
        Parameters.createTimeMin,
        Parameters.createTimeMax,
        Parameters.endTimeMin,
        Parameters.endTimeMax,
        Parameters.isActive,
        Parameters.top,
    ],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.jobExecutionId,
        Parameters.stepName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const getOperationSpec = {
    path: "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Sql/servers/{serverName}/jobAgents/{jobAgentName}/jobs/{jobName}/executions/{jobExecutionId}/steps/{stepName}/targets/{targetId}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobExecution,
        },
        default: {},
    },
    queryParameters: [Parameters.apiVersion3],
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.jobExecutionId,
        Parameters.stepName,
        Parameters.targetId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByJobExecutionNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobExecutionListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.nextLink,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.jobExecutionId,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
const listByStepNextOperationSpec = {
    path: "{nextLink}",
    httpMethod: "GET",
    responses: {
        200: {
            bodyMapper: Mappers.JobExecutionListResult,
        },
        default: {},
    },
    urlParameters: [
        Parameters.$host,
        Parameters.subscriptionId,
        Parameters.resourceGroupName,
        Parameters.serverName,
        Parameters.nextLink,
        Parameters.jobAgentName,
        Parameters.jobName,
        Parameters.jobExecutionId,
        Parameters.stepName,
    ],
    headerParameters: [Parameters.accept],
    serializer,
};
//# sourceMappingURL=jobTargetExecutions.js.map