KqlScriptsOperationsImpl.java

// 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.implementation;

import com.azure.analytics.synapse.artifacts.models.ArtifactRenameRequest;
import com.azure.analytics.synapse.artifacts.models.ErrorContractException;
import com.azure.analytics.synapse.artifacts.models.KqlScriptResource;
import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Post;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import reactor.core.publisher.Mono;

/** An instance of this class provides access to all the operations defined in KqlScriptsOperations. */
public final class KqlScriptsOperationsImpl {
    /** The proxy service used to perform REST calls. */
    private final KqlScriptsService service;

    /** The service client containing this operation class. */
    private final ArtifactsClientImpl client;

    /**
     * Initializes an instance of KqlScriptsOperationsImpl.
     *
     * @param client the instance of the service client containing this operation class.
     */
    KqlScriptsOperationsImpl(ArtifactsClientImpl client) {
        this.service =
                RestProxy.create(KqlScriptsService.class, client.getHttpPipeline(), client.getSerializerAdapter());
        this.client = client;
    }

    /**
     * The interface defining all the services for ArtifactsClientKqlScriptsOperations to be used by the proxy service
     * to perform REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "ArtifactsClientKqlSc")
    private interface KqlScriptsService {
        @Put("/kqlScripts/{kqlScriptName}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<KqlScriptResource>> createOrUpdate(
                @HostParam("endpoint") String endpoint,
                @PathParam("kqlScriptName") String kqlScriptName,
                @QueryParam("api-version") String apiVersion,
                @BodyParam("application/json") KqlScriptResource kqlScript,
                @HeaderParam("Accept") String accept,
                Context context);

        @Get("/kqlScripts/{kqlScriptName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<KqlScriptResource>> getByName(
                @HostParam("endpoint") String endpoint,
                @PathParam("kqlScriptName") String kqlScriptName,
                @QueryParam("api-version") String apiVersion,
                @HeaderParam("Accept") String accept,
                Context context);

        @Delete("/kqlScripts/{kqlScriptName}")
        @ExpectedResponses({200, 202, 204})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<Void>> deleteByName(
                @HostParam("endpoint") String endpoint,
                @PathParam("kqlScriptName") String kqlScriptName,
                @QueryParam("api-version") String apiVersion,
                @HeaderParam("Accept") String accept,
                Context context);

        @Post("/kqlScripts/{kqlScriptName}/rename")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<Void>> rename(
                @HostParam("endpoint") String endpoint,
                @PathParam("kqlScriptName") String kqlScriptName,
                @QueryParam("api-version") String apiVersion,
                @BodyParam("application/json") ArtifactRenameRequest renameRequest,
                @HeaderParam("Accept") String accept,
                Context context);
    }

    /**
     * Creates or updates a KQL Script.
     *
     * @param kqlScriptName KQL script name.
     * @param kqlScript KQL script.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<KqlScriptResource>> createOrUpdateWithResponseAsync(
            String kqlScriptName, KqlScriptResource kqlScript) {
        final String apiVersion = "2021-11-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.createOrUpdate(
                                this.client.getEndpoint(), kqlScriptName, apiVersion, kqlScript, accept, context));
    }

    /**
     * Creates or updates a KQL Script.
     *
     * @param kqlScriptName KQL script name.
     * @param kqlScript KQL script.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<KqlScriptResource>> createOrUpdateWithResponseAsync(
            String kqlScriptName, KqlScriptResource kqlScript, Context context) {
        final String apiVersion = "2021-11-01-preview";
        final String accept = "application/json";
        return service.createOrUpdate(this.client.getEndpoint(), kqlScriptName, apiVersion, kqlScript, accept, context);
    }

    /**
     * Creates or updates a KQL Script.
     *
     * @param kqlScriptName KQL script name.
     * @param kqlScript KQL script.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<KqlScriptResource> createOrUpdateAsync(String kqlScriptName, KqlScriptResource kqlScript) {
        return createOrUpdateWithResponseAsync(kqlScriptName, kqlScript)
                .flatMap(
                        (Response<KqlScriptResource> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Creates or updates a KQL Script.
     *
     * @param kqlScriptName KQL script name.
     * @param kqlScript KQL script.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<KqlScriptResource> createOrUpdateAsync(
            String kqlScriptName, KqlScriptResource kqlScript, Context context) {
        return createOrUpdateWithResponseAsync(kqlScriptName, kqlScript, context)
                .flatMap(
                        (Response<KqlScriptResource> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Creates or updates a KQL Script.
     *
     * @param kqlScriptName KQL script name.
     * @param kqlScript KQL script.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public KqlScriptResource createOrUpdate(String kqlScriptName, KqlScriptResource kqlScript) {
        return createOrUpdateAsync(kqlScriptName, kqlScript).block();
    }

    /**
     * Creates or updates a KQL Script.
     *
     * @param kqlScriptName KQL script name.
     * @param kqlScript KQL script.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<KqlScriptResource> createOrUpdateWithResponse(
            String kqlScriptName, KqlScriptResource kqlScript, Context context) {
        return createOrUpdateWithResponseAsync(kqlScriptName, kqlScript, context).block();
    }

    /**
     * Get KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return kQL script by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<KqlScriptResource>> getByNameWithResponseAsync(String kqlScriptName) {
        final String apiVersion = "2021-11-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.getByName(this.client.getEndpoint(), kqlScriptName, apiVersion, accept, context));
    }

    /**
     * Get KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return kQL script by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<KqlScriptResource>> getByNameWithResponseAsync(String kqlScriptName, Context context) {
        final String apiVersion = "2021-11-01-preview";
        final String accept = "application/json";
        return service.getByName(this.client.getEndpoint(), kqlScriptName, apiVersion, accept, context);
    }

    /**
     * Get KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return kQL script by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<KqlScriptResource> getByNameAsync(String kqlScriptName) {
        return getByNameWithResponseAsync(kqlScriptName)
                .flatMap(
                        (Response<KqlScriptResource> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Get KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return kQL script by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<KqlScriptResource> getByNameAsync(String kqlScriptName, Context context) {
        return getByNameWithResponseAsync(kqlScriptName, context)
                .flatMap(
                        (Response<KqlScriptResource> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Get KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return kQL script by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public KqlScriptResource getByName(String kqlScriptName) {
        return getByNameAsync(kqlScriptName).block();
    }

    /**
     * Get KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return kQL script by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<KqlScriptResource> getByNameWithResponse(String kqlScriptName, Context context) {
        return getByNameWithResponseAsync(kqlScriptName, context).block();
    }

    /**
     * Delete KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> deleteByNameWithResponseAsync(String kqlScriptName) {
        final String apiVersion = "2021-11-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.deleteByName(this.client.getEndpoint(), kqlScriptName, apiVersion, accept, context));
    }

    /**
     * Delete KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> deleteByNameWithResponseAsync(String kqlScriptName, Context context) {
        final String apiVersion = "2021-11-01-preview";
        final String accept = "application/json";
        return service.deleteByName(this.client.getEndpoint(), kqlScriptName, apiVersion, accept, context);
    }

    /**
     * Delete KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> deleteByNameAsync(String kqlScriptName) {
        return deleteByNameWithResponseAsync(kqlScriptName).flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Delete KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> deleteByNameAsync(String kqlScriptName, Context context) {
        return deleteByNameWithResponseAsync(kqlScriptName, context).flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Delete KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void deleteByName(String kqlScriptName) {
        deleteByNameAsync(kqlScriptName).block();
    }

    /**
     * Delete KQL script by name.
     *
     * @param kqlScriptName KQL script name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteByNameWithResponse(String kqlScriptName, Context context) {
        return deleteByNameWithResponseAsync(kqlScriptName, context).block();
    }

    /**
     * Rename KQL script.
     *
     * @param kqlScriptName KQL script name.
     * @param renameRequest Rename request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> renameWithResponseAsync(String kqlScriptName, ArtifactRenameRequest renameRequest) {
        final String apiVersion = "2021-11-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.rename(
                                this.client.getEndpoint(), kqlScriptName, apiVersion, renameRequest, accept, context));
    }

    /**
     * Rename KQL script.
     *
     * @param kqlScriptName KQL script name.
     * @param renameRequest Rename request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> renameWithResponseAsync(
            String kqlScriptName, ArtifactRenameRequest renameRequest, Context context) {
        final String apiVersion = "2021-11-01-preview";
        final String accept = "application/json";
        return service.rename(this.client.getEndpoint(), kqlScriptName, apiVersion, renameRequest, accept, context);
    }

    /**
     * Rename KQL script.
     *
     * @param kqlScriptName KQL script name.
     * @param renameRequest Rename request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> renameAsync(String kqlScriptName, ArtifactRenameRequest renameRequest) {
        return renameWithResponseAsync(kqlScriptName, renameRequest).flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Rename KQL script.
     *
     * @param kqlScriptName KQL script name.
     * @param renameRequest Rename request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> renameAsync(String kqlScriptName, ArtifactRenameRequest renameRequest, Context context) {
        return renameWithResponseAsync(kqlScriptName, renameRequest, context)
                .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Rename KQL script.
     *
     * @param kqlScriptName KQL script name.
     * @param renameRequest Rename request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void rename(String kqlScriptName, ArtifactRenameRequest renameRequest) {
        renameAsync(kqlScriptName, renameRequest).block();
    }

    /**
     * Rename KQL script.
     *
     * @param kqlScriptName KQL script name.
     * @param renameRequest Rename request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> renameWithResponse(
            String kqlScriptName, ArtifactRenameRequest renameRequest, Context context) {
        return renameWithResponseAsync(kqlScriptName, renameRequest, context).block();
    }
}