// 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.CloudErrorException;
import com.azure.analytics.synapse.artifacts.models.SparkConfigurationListResponse;
import com.azure.analytics.synapse.artifacts.models.SparkConfigurationResource;
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.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
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 SparkConfigurations. */
public final class SparkConfigurationsImpl {
    /** The proxy service used to perform REST calls. */
    private final SparkConfigurationsService service;

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

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

    /**
     * The interface defining all the services for ArtifactsClientSparkConfigurations to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "ArtifactsClientSpark")
    public interface SparkConfigurationsService {
        @Get("/sparkconfigurations")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(CloudErrorException.class)
        Mono<Response<SparkConfigurationListResponse>> getSparkConfigurationsByWorkspace(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @HeaderParam("Accept") String accept,
                Context context);

        @Put("/sparkconfigurations/{sparkConfigurationName}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(CloudErrorException.class)
        Mono<Response<SparkConfigurationResource>> createOrUpdateSparkConfiguration(
                @HostParam("endpoint") String endpoint,
                @PathParam("sparkConfigurationName") String sparkConfigurationName,
                @QueryParam("api-version") String apiVersion,
                @HeaderParam("If-Match") String ifMatch,
                @BodyParam("application/json") SparkConfigurationResource sparkConfiguration,
                @HeaderParam("Accept") String accept,
                Context context);

        @Get("/sparkconfigurations/{sparkConfigurationName}")
        @ExpectedResponses({200, 304})
        @UnexpectedResponseExceptionType(CloudErrorException.class)
        Mono<Response<SparkConfigurationResource>> getSparkConfiguration(
                @HostParam("endpoint") String endpoint,
                @PathParam("sparkConfigurationName") String sparkConfigurationName,
                @QueryParam("api-version") String apiVersion,
                @HeaderParam("If-None-Match") String ifNoneMatch,
                @HeaderParam("Accept") String accept,
                Context context);

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

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

        @Get("{nextLink}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(CloudErrorException.class)
        Mono<Response<SparkConfigurationListResponse>> getSparkConfigurationsByWorkspaceNext(
                @PathParam(value = "nextLink", encoded = true) String nextLink,
                @HostParam("endpoint") String endpoint,
                @HeaderParam("Accept") String accept,
                Context context);
    }

    /**
     * Lists sparkconfigurations.
     *
     * @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 of sparkconfiguration resources along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<SparkConfigurationResource>> getSparkConfigurationsByWorkspaceSinglePageAsync() {
        final String apiVersion = "2021-06-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                        context ->
                                service.getSparkConfigurationsByWorkspace(
                                        this.client.getEndpoint(), apiVersion, accept, context))
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }

    /**
     * Lists sparkconfigurations.
     *
     * @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 of sparkconfiguration resources along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<SparkConfigurationResource>> getSparkConfigurationsByWorkspaceSinglePageAsync(
            Context context) {
        final String apiVersion = "2021-06-01-preview";
        final String accept = "application/json";
        return service.getSparkConfigurationsByWorkspace(this.client.getEndpoint(), apiVersion, accept, context)
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }

    /**
     * Lists sparkconfigurations.
     *
     * @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 of sparkconfiguration resources as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<SparkConfigurationResource> getSparkConfigurationsByWorkspaceAsync() {
        return new PagedFlux<>(
                () -> getSparkConfigurationsByWorkspaceSinglePageAsync(),
                nextLink -> getSparkConfigurationsByWorkspaceNextSinglePageAsync(nextLink));
    }

    /**
     * Lists sparkconfigurations.
     *
     * @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 of sparkconfiguration resources as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<SparkConfigurationResource> getSparkConfigurationsByWorkspaceAsync(Context context) {
        return new PagedFlux<>(
                () -> getSparkConfigurationsByWorkspaceSinglePageAsync(context),
                nextLink -> getSparkConfigurationsByWorkspaceNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists sparkconfigurations.
     *
     * @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 of sparkconfiguration resources along with {@link PagedResponse}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PagedResponse<SparkConfigurationResource> getSparkConfigurationsByWorkspaceSinglePage() {
        return getSparkConfigurationsByWorkspaceSinglePageAsync().block();
    }

    /**
     * Lists sparkconfigurations.
     *
     * @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 of sparkconfiguration resources along with {@link PagedResponse}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PagedResponse<SparkConfigurationResource> getSparkConfigurationsByWorkspaceSinglePage(Context context) {
        return getSparkConfigurationsByWorkspaceSinglePageAsync(context).block();
    }

    /**
     * Lists sparkconfigurations.
     *
     * @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 of sparkconfiguration resources as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SparkConfigurationResource> getSparkConfigurationsByWorkspace() {
        return new PagedIterable<>(getSparkConfigurationsByWorkspaceAsync());
    }

    /**
     * Lists sparkconfigurations.
     *
     * @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 of sparkconfiguration resources as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SparkConfigurationResource> getSparkConfigurationsByWorkspace(Context context) {
        return new PagedIterable<>(getSparkConfigurationsByWorkspaceAsync(context));
    }

    /**
     * Creates or updates a sparkconfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param sparkConfiguration SparkConfiguration resource definition.
     * @param ifMatch ETag of the sparkConfiguration entity. Should only be specified for update, for which it should
     *     match existing entity or can be * for unconditional update.
     * @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 spark Configuration resource type along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<SparkConfigurationResource>> createOrUpdateSparkConfigurationWithResponseAsync(
            String sparkConfigurationName, SparkConfigurationResource sparkConfiguration, String ifMatch) {
        final String apiVersion = "2021-06-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.createOrUpdateSparkConfiguration(
                                this.client.getEndpoint(),
                                sparkConfigurationName,
                                apiVersion,
                                ifMatch,
                                sparkConfiguration,
                                accept,
                                context));
    }

    /**
     * Creates or updates a sparkconfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param sparkConfiguration SparkConfiguration resource definition.
     * @param ifMatch ETag of the sparkConfiguration entity. Should only be specified for update, for which it should
     *     match existing entity or can be * for unconditional update.
     * @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 spark Configuration resource type along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<SparkConfigurationResource>> createOrUpdateSparkConfigurationWithResponseAsync(
            String sparkConfigurationName,
            SparkConfigurationResource sparkConfiguration,
            String ifMatch,
            Context context) {
        final String apiVersion = "2021-06-01-preview";
        final String accept = "application/json";
        return service.createOrUpdateSparkConfiguration(
                this.client.getEndpoint(),
                sparkConfigurationName,
                apiVersion,
                ifMatch,
                sparkConfiguration,
                accept,
                context);
    }

    /**
     * Creates or updates a sparkconfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param sparkConfiguration SparkConfiguration resource definition.
     * @param ifMatch ETag of the sparkConfiguration entity. Should only be specified for update, for which it should
     *     match existing entity or can be * for unconditional update.
     * @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 spark Configuration resource type on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<SparkConfigurationResource> createOrUpdateSparkConfigurationAsync(
            String sparkConfigurationName, SparkConfigurationResource sparkConfiguration, String ifMatch) {
        return createOrUpdateSparkConfigurationWithResponseAsync(sparkConfigurationName, sparkConfiguration, ifMatch)
                .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates or updates a sparkconfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param sparkConfiguration SparkConfiguration resource definition.
     * @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 spark Configuration resource type on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<SparkConfigurationResource> createOrUpdateSparkConfigurationAsync(
            String sparkConfigurationName, SparkConfigurationResource sparkConfiguration) {
        final String ifMatch = null;
        return createOrUpdateSparkConfigurationWithResponseAsync(sparkConfigurationName, sparkConfiguration, ifMatch)
                .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates or updates a sparkconfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param sparkConfiguration SparkConfiguration resource definition.
     * @param ifMatch ETag of the sparkConfiguration entity. Should only be specified for update, for which it should
     *     match existing entity or can be * for unconditional update.
     * @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 spark Configuration resource type on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<SparkConfigurationResource> createOrUpdateSparkConfigurationAsync(
            String sparkConfigurationName,
            SparkConfigurationResource sparkConfiguration,
            String ifMatch,
            Context context) {
        return createOrUpdateSparkConfigurationWithResponseAsync(
                        sparkConfigurationName, sparkConfiguration, ifMatch, context)
                .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates or updates a sparkconfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param sparkConfiguration SparkConfiguration resource definition.
     * @param ifMatch ETag of the sparkConfiguration entity. Should only be specified for update, for which it should
     *     match existing entity or can be * for unconditional update.
     * @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 spark Configuration resource type along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SparkConfigurationResource> createOrUpdateSparkConfigurationWithResponse(
            String sparkConfigurationName,
            SparkConfigurationResource sparkConfiguration,
            String ifMatch,
            Context context) {
        return createOrUpdateSparkConfigurationWithResponseAsync(
                        sparkConfigurationName, sparkConfiguration, ifMatch, context)
                .block();
    }

    /**
     * Creates or updates a sparkconfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param sparkConfiguration SparkConfiguration resource definition.
     * @param ifMatch ETag of the sparkConfiguration entity. Should only be specified for update, for which it should
     *     match existing entity or can be * for unconditional update.
     * @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 spark Configuration resource type.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SparkConfigurationResource createOrUpdateSparkConfiguration(
            String sparkConfigurationName, SparkConfigurationResource sparkConfiguration, String ifMatch) {
        return createOrUpdateSparkConfigurationWithResponse(
                        sparkConfigurationName, sparkConfiguration, ifMatch, Context.NONE)
                .getValue();
    }

    /**
     * Creates or updates a sparkconfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param sparkConfiguration SparkConfiguration resource definition.
     * @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 spark Configuration resource type.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SparkConfigurationResource createOrUpdateSparkConfiguration(
            String sparkConfigurationName, SparkConfigurationResource sparkConfiguration) {
        final String ifMatch = null;
        return createOrUpdateSparkConfigurationWithResponse(
                        sparkConfigurationName, sparkConfiguration, ifMatch, Context.NONE)
                .getValue();
    }

    /**
     * Gets a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param ifNoneMatch ETag of the sparkConfiguration entity. Should only be specified for get. If the ETag matches
     *     the existing entity tag, or if * was provided, then no content will be returned.
     * @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 sparkConfiguration along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<SparkConfigurationResource>> getSparkConfigurationWithResponseAsync(
            String sparkConfigurationName, String ifNoneMatch) {
        final String apiVersion = "2021-06-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.getSparkConfiguration(
                                this.client.getEndpoint(),
                                sparkConfigurationName,
                                apiVersion,
                                ifNoneMatch,
                                accept,
                                context));
    }

    /**
     * Gets a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param ifNoneMatch ETag of the sparkConfiguration entity. Should only be specified for get. If the ETag matches
     *     the existing entity tag, or if * was provided, then no content will be returned.
     * @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 sparkConfiguration along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<SparkConfigurationResource>> getSparkConfigurationWithResponseAsync(
            String sparkConfigurationName, String ifNoneMatch, Context context) {
        final String apiVersion = "2021-06-01-preview";
        final String accept = "application/json";
        return service.getSparkConfiguration(
                this.client.getEndpoint(), sparkConfigurationName, apiVersion, ifNoneMatch, accept, context);
    }

    /**
     * Gets a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param ifNoneMatch ETag of the sparkConfiguration entity. Should only be specified for get. If the ETag matches
     *     the existing entity tag, or if * was provided, then no content will be returned.
     * @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 sparkConfiguration on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<SparkConfigurationResource> getSparkConfigurationAsync(
            String sparkConfigurationName, String ifNoneMatch) {
        return getSparkConfigurationWithResponseAsync(sparkConfigurationName, ifNoneMatch)
                .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @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 sparkConfiguration on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<SparkConfigurationResource> getSparkConfigurationAsync(String sparkConfigurationName) {
        final String ifNoneMatch = null;
        return getSparkConfigurationWithResponseAsync(sparkConfigurationName, ifNoneMatch)
                .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param ifNoneMatch ETag of the sparkConfiguration entity. Should only be specified for get. If the ETag matches
     *     the existing entity tag, or if * was provided, then no content will be returned.
     * @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 sparkConfiguration on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<SparkConfigurationResource> getSparkConfigurationAsync(
            String sparkConfigurationName, String ifNoneMatch, Context context) {
        return getSparkConfigurationWithResponseAsync(sparkConfigurationName, ifNoneMatch, context)
                .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param ifNoneMatch ETag of the sparkConfiguration entity. Should only be specified for get. If the ETag matches
     *     the existing entity tag, or if * was provided, then no content will be returned.
     * @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 sparkConfiguration along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SparkConfigurationResource> getSparkConfigurationWithResponse(
            String sparkConfigurationName, String ifNoneMatch, Context context) {
        return getSparkConfigurationWithResponseAsync(sparkConfigurationName, ifNoneMatch, context).block();
    }

    /**
     * Gets a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param ifNoneMatch ETag of the sparkConfiguration entity. Should only be specified for get. If the ETag matches
     *     the existing entity tag, or if * was provided, then no content will be returned.
     * @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 sparkConfiguration.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SparkConfigurationResource getSparkConfiguration(String sparkConfigurationName, String ifNoneMatch) {
        return getSparkConfigurationWithResponse(sparkConfigurationName, ifNoneMatch, Context.NONE).getValue();
    }

    /**
     * Gets a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @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 sparkConfiguration.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SparkConfigurationResource getSparkConfiguration(String sparkConfigurationName) {
        final String ifNoneMatch = null;
        return getSparkConfigurationWithResponse(sparkConfigurationName, ifNoneMatch, Context.NONE).getValue();
    }

    /**
     * Deletes a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @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} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> deleteSparkConfigurationWithResponseAsync(String sparkConfigurationName) {
        final String apiVersion = "2021-06-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.deleteSparkConfiguration(
                                this.client.getEndpoint(), sparkConfigurationName, apiVersion, accept, context));
    }

    /**
     * Deletes a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @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} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> deleteSparkConfigurationWithResponseAsync(
            String sparkConfigurationName, Context context) {
        final String apiVersion = "2021-06-01-preview";
        final String accept = "application/json";
        return service.deleteSparkConfiguration(
                this.client.getEndpoint(), sparkConfigurationName, apiVersion, accept, context);
    }

    /**
     * Deletes a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @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 {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> deleteSparkConfigurationAsync(String sparkConfigurationName) {
        return deleteSparkConfigurationWithResponseAsync(sparkConfigurationName).flatMap(ignored -> Mono.empty());
    }

    /**
     * Deletes a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @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 {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> deleteSparkConfigurationAsync(String sparkConfigurationName, Context context) {
        return deleteSparkConfigurationWithResponseAsync(sparkConfigurationName, context)
                .flatMap(ignored -> Mono.empty());
    }

    /**
     * Deletes a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @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}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteSparkConfigurationWithResponse(String sparkConfigurationName, Context context) {
        return deleteSparkConfigurationWithResponseAsync(sparkConfigurationName, context).block();
    }

    /**
     * Deletes a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void deleteSparkConfiguration(String sparkConfigurationName) {
        deleteSparkConfigurationWithResponse(sparkConfigurationName, Context.NONE);
    }

    /**
     * Renames a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param request proposed new name.
     * @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} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> renameSparkConfigurationWithResponseAsync(
            String sparkConfigurationName, ArtifactRenameRequest request) {
        final String apiVersion = "2021-06-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.renameSparkConfiguration(
                                this.client.getEndpoint(),
                                sparkConfigurationName,
                                apiVersion,
                                request,
                                accept,
                                context));
    }

    /**
     * Renames a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param request proposed new name.
     * @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} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> renameSparkConfigurationWithResponseAsync(
            String sparkConfigurationName, ArtifactRenameRequest request, Context context) {
        final String apiVersion = "2021-06-01-preview";
        final String accept = "application/json";
        return service.renameSparkConfiguration(
                this.client.getEndpoint(), sparkConfigurationName, apiVersion, request, accept, context);
    }

    /**
     * Renames a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param request proposed new name.
     * @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 {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> renameSparkConfigurationAsync(String sparkConfigurationName, ArtifactRenameRequest request) {
        return renameSparkConfigurationWithResponseAsync(sparkConfigurationName, request)
                .flatMap(ignored -> Mono.empty());
    }

    /**
     * Renames a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param request proposed new name.
     * @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 {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> renameSparkConfigurationAsync(
            String sparkConfigurationName, ArtifactRenameRequest request, Context context) {
        return renameSparkConfigurationWithResponseAsync(sparkConfigurationName, request, context)
                .flatMap(ignored -> Mono.empty());
    }

    /**
     * Renames a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param request proposed new name.
     * @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}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> renameSparkConfigurationWithResponse(
            String sparkConfigurationName, ArtifactRenameRequest request, Context context) {
        return renameSparkConfigurationWithResponseAsync(sparkConfigurationName, request, context).block();
    }

    /**
     * Renames a sparkConfiguration.
     *
     * @param sparkConfigurationName The spark Configuration name.
     * @param request proposed new name.
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void renameSparkConfiguration(String sparkConfigurationName, ArtifactRenameRequest request) {
        renameSparkConfigurationWithResponse(sparkConfigurationName, request, Context.NONE);
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @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 of sparkconfiguration resources along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<SparkConfigurationResource>> getSparkConfigurationsByWorkspaceNextSinglePageAsync(
            String nextLink) {
        final String accept = "application/json";
        return FluxUtil.withContext(
                        context ->
                                service.getSparkConfigurationsByWorkspaceNext(
                                        nextLink, this.client.getEndpoint(), accept, context))
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @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 of sparkconfiguration resources along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<SparkConfigurationResource>> getSparkConfigurationsByWorkspaceNextSinglePageAsync(
            String nextLink, Context context) {
        final String accept = "application/json";
        return service.getSparkConfigurationsByWorkspaceNext(nextLink, this.client.getEndpoint(), accept, context)
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @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 of sparkconfiguration resources along with {@link PagedResponse}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PagedResponse<SparkConfigurationResource> getSparkConfigurationsByWorkspaceNextSinglePage(String nextLink) {
        return getSparkConfigurationsByWorkspaceNextSinglePageAsync(nextLink).block();
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @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 of sparkconfiguration resources along with {@link PagedResponse}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PagedResponse<SparkConfigurationResource> getSparkConfigurationsByWorkspaceNextSinglePage(
            String nextLink, Context context) {
        return getSparkConfigurationsByWorkspaceNextSinglePageAsync(nextLink, context).block();
    }
}
