// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// Code generated by Microsoft (R) AutoRest Code Generator.

package com.azure.analytics.synapse.artifacts;

import com.azure.analytics.synapse.artifacts.implementation.PipelineRunsImpl;
import com.azure.analytics.synapse.artifacts.models.ActivityRunsQueryResponse;
import com.azure.analytics.synapse.artifacts.models.CloudErrorException;
import com.azure.analytics.synapse.artifacts.models.PipelineRun;
import com.azure.analytics.synapse.artifacts.models.PipelineRunsQueryResponse;
import com.azure.analytics.synapse.artifacts.models.RunFilterParameters;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.rest.Response;
import com.azure.core.util.Context;

/** Initializes a new instance of the synchronous ArtifactsClient type. */
@ServiceClient(builder = ArtifactsClientBuilder.class)
public final class PipelineRunClient {
    @Generated private final PipelineRunsImpl serviceClient;

    /**
     * Initializes an instance of PipelineRunClient class.
     *
     * @param serviceClient the service client implementation.
     */
    @Generated
    PipelineRunClient(PipelineRunsImpl serviceClient) {
        this.serviceClient = serviceClient;
    }

    /**
     * Query pipeline runs in the workspace based on input filter conditions.
     *
     * @param filterParameters Parameters to filter the pipeline run.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list pipeline runs along with {@link Response}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<PipelineRunsQueryResponse> queryPipelineRunsByWorkspaceWithResponse(
            RunFilterParameters filterParameters, Context context) {
        return this.serviceClient.queryPipelineRunsByWorkspaceWithResponse(filterParameters, context);
    }

    /**
     * Query pipeline runs in the workspace based on input filter conditions.
     *
     * @param filterParameters Parameters to filter the pipeline run.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list pipeline runs.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PipelineRunsQueryResponse queryPipelineRunsByWorkspace(RunFilterParameters filterParameters) {
        return this.serviceClient.queryPipelineRunsByWorkspace(filterParameters);
    }

    /**
     * Get a pipeline run by its run ID.
     *
     * @param runId The pipeline run identifier.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a pipeline run by its run ID along with {@link Response}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<PipelineRun> getPipelineRunWithResponse(String runId, Context context) {
        return this.serviceClient.getPipelineRunWithResponse(runId, context);
    }

    /**
     * Get a pipeline run by its run ID.
     *
     * @param runId The pipeline run identifier.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a pipeline run by its run ID.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PipelineRun getPipelineRun(String runId) {
        return this.serviceClient.getPipelineRun(runId);
    }

    /**
     * Query activity runs based on input filter conditions.
     *
     * @param pipelineName The pipeline name.
     * @param runId The pipeline run identifier.
     * @param filterParameters Parameters to filter the activity runs.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list activity runs along with {@link Response}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ActivityRunsQueryResponse> queryActivityRunsWithResponse(
            String pipelineName, String runId, RunFilterParameters filterParameters, Context context) {
        return this.serviceClient.queryActivityRunsWithResponse(pipelineName, runId, filterParameters, context);
    }

    /**
     * Query activity runs based on input filter conditions.
     *
     * @param pipelineName The pipeline name.
     * @param runId The pipeline run identifier.
     * @param filterParameters Parameters to filter the activity runs.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list activity runs.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ActivityRunsQueryResponse queryActivityRuns(
            String pipelineName, String runId, RunFilterParameters filterParameters) {
        return this.serviceClient.queryActivityRuns(pipelineName, runId, filterParameters);
    }

    /**
     * Cancel a pipeline run by its run ID.
     *
     * @param runId The pipeline run identifier.
     * @param isRecursive If true, cancel all the Child pipelines that are triggered by the current pipeline.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> cancelPipelineRunWithResponse(String runId, Boolean isRecursive, Context context) {
        return this.serviceClient.cancelPipelineRunWithResponse(runId, isRecursive, context);
    }

    /**
     * Cancel a pipeline run by its run ID.
     *
     * @param runId The pipeline run identifier.
     * @param isRecursive If true, cancel all the Child pipelines that are triggered by the current pipeline.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void cancelPipelineRun(String runId, Boolean isRecursive) {
        this.serviceClient.cancelPipelineRun(runId, isRecursive);
    }

    /**
     * Cancel a pipeline run by its run ID.
     *
     * @param runId The pipeline run identifier.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void cancelPipelineRun(String runId) {
        this.serviceClient.cancelPipelineRun(runId);
    }
}
