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

package com.azure.resourcemanager.networkcloud.implementation;

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.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
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.management.exception.ManagementException;
import com.azure.core.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.networkcloud.fluent.BmcKeySetsClient;
import com.azure.resourcemanager.networkcloud.fluent.models.BmcKeySetInner;
import com.azure.resourcemanager.networkcloud.models.BmcKeySetList;
import com.azure.resourcemanager.networkcloud.models.BmcKeySetPatchParameters;
import java.nio.ByteBuffer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for NetworkCloudBmcKeySets to be used by the proxy service to perform
     * REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "NetworkCloudBmcKeySe")
    public interface BmcKeySetsService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/clusters/{clusterName}/bmcKeySets")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<BmcKeySetList>> listByCluster(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("clusterName") String clusterName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/clusters/{clusterName}/bmcKeySets/{bmcKeySetName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<BmcKeySetInner>> get(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("clusterName") String clusterName,
            @PathParam("bmcKeySetName") String bmcKeySetName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/clusters/{clusterName}/bmcKeySets/{bmcKeySetName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("clusterName") String clusterName,
            @PathParam("bmcKeySetName") String bmcKeySetName,
            @BodyParam("application/json") BmcKeySetInner bmcKeySetParameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/clusters/{clusterName}/bmcKeySets/{bmcKeySetName}")
        @ExpectedResponses({200, 202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> delete(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("clusterName") String clusterName,
            @PathParam("bmcKeySetName") String bmcKeySetName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/clusters/{clusterName}/bmcKeySets/{bmcKeySetName}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> update(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("clusterName") String clusterName,
            @PathParam("bmcKeySetName") String bmcKeySetName,
            @BodyParam("application/json") BmcKeySetPatchParameters bmcKeySetUpdateParameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("{nextLink}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<BmcKeySetList>> listByClusterNext(
            @PathParam(value = "nextLink", encoded = true) String nextLink,
            @HostParam("$host") String endpoint,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * List baseboard management controller key sets of the cluster.
     *
     * <p>Get a list of baseboard management controller key sets for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 baseboard management controller key sets for the provided cluster along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BmcKeySetInner>> listByClusterSinglePageAsync(
        String resourceGroupName, String clusterName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByCluster(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            clusterName,
                            accept,
                            context))
            .<PagedResponse<BmcKeySetInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List baseboard management controller key sets of the cluster.
     *
     * <p>Get a list of baseboard management controller key sets for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 baseboard management controller key sets for the provided cluster along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BmcKeySetInner>> listByClusterSinglePageAsync(
        String resourceGroupName, String clusterName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByCluster(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                clusterName,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List baseboard management controller key sets of the cluster.
     *
     * <p>Get a list of baseboard management controller key sets for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 baseboard management controller key sets for the provided cluster as paginated response with
     *     {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<BmcKeySetInner> listByClusterAsync(String resourceGroupName, String clusterName) {
        return new PagedFlux<>(
            () -> listByClusterSinglePageAsync(resourceGroupName, clusterName),
            nextLink -> listByClusterNextSinglePageAsync(nextLink));
    }

    /**
     * List baseboard management controller key sets of the cluster.
     *
     * <p>Get a list of baseboard management controller key sets for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 baseboard management controller key sets for the provided cluster as paginated response with
     *     {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<BmcKeySetInner> listByClusterAsync(
        String resourceGroupName, String clusterName, Context context) {
        return new PagedFlux<>(
            () -> listByClusterSinglePageAsync(resourceGroupName, clusterName, context),
            nextLink -> listByClusterNextSinglePageAsync(nextLink, context));
    }

    /**
     * List baseboard management controller key sets of the cluster.
     *
     * <p>Get a list of baseboard management controller key sets for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 baseboard management controller key sets for the provided cluster as paginated response with
     *     {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<BmcKeySetInner> listByCluster(String resourceGroupName, String clusterName) {
        return new PagedIterable<>(listByClusterAsync(resourceGroupName, clusterName));
    }

    /**
     * List baseboard management controller key sets of the cluster.
     *
     * <p>Get a list of baseboard management controller key sets for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 baseboard management controller key sets for the provided cluster as paginated response with
     *     {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<BmcKeySetInner> listByCluster(String resourceGroupName, String clusterName, Context context) {
        return new PagedIterable<>(listByClusterAsync(resourceGroupName, clusterName, context));
    }

    /**
     * Retrieve the baseboard management controller key set of the cluster.
     *
     * <p>Get baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return baseboard management controller key set of the provided cluster along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<BmcKeySetInner>> getWithResponseAsync(
        String resourceGroupName, String clusterName, String bmcKeySetName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (bmcKeySetName == null) {
            return Mono.error(new IllegalArgumentException("Parameter bmcKeySetName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            clusterName,
                            bmcKeySetName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Retrieve the baseboard management controller key set of the cluster.
     *
     * <p>Get baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return baseboard management controller key set of the provided cluster along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<BmcKeySetInner>> getWithResponseAsync(
        String resourceGroupName, String clusterName, String bmcKeySetName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (bmcKeySetName == null) {
            return Mono.error(new IllegalArgumentException("Parameter bmcKeySetName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                clusterName,
                bmcKeySetName,
                accept,
                context);
    }

    /**
     * Retrieve the baseboard management controller key set of the cluster.
     *
     * <p>Get baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return baseboard management controller key set of the provided cluster on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BmcKeySetInner> getAsync(String resourceGroupName, String clusterName, String bmcKeySetName) {
        return getWithResponseAsync(resourceGroupName, clusterName, bmcKeySetName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Retrieve the baseboard management controller key set of the cluster.
     *
     * <p>Get baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return baseboard management controller key set of the provided cluster along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<BmcKeySetInner> getWithResponse(
        String resourceGroupName, String clusterName, String bmcKeySetName, Context context) {
        return getWithResponseAsync(resourceGroupName, clusterName, bmcKeySetName, context).block();
    }

    /**
     * Retrieve the baseboard management controller key set of the cluster.
     *
     * <p>Get baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return baseboard management controller key set of the provided cluster.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public BmcKeySetInner get(String resourceGroupName, String clusterName, String bmcKeySetName) {
        return getWithResponse(resourceGroupName, clusterName, bmcKeySetName, Context.NONE).getValue();
    }

    /**
     * Create or update the baseboard management controller key set of the cluster.
     *
     * <p>Create a new baseboard management controller key set or update the existing one for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String clusterName, String bmcKeySetName, BmcKeySetInner bmcKeySetParameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (bmcKeySetName == null) {
            return Mono.error(new IllegalArgumentException("Parameter bmcKeySetName is required and cannot be null."));
        }
        if (bmcKeySetParameters == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bmcKeySetParameters is required and cannot be null."));
        } else {
            bmcKeySetParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            clusterName,
                            bmcKeySetName,
                            bmcKeySetParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create or update the baseboard management controller key set of the cluster.
     *
     * <p>Create a new baseboard management controller key set or update the existing one for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetInner bmcKeySetParameters,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (bmcKeySetName == null) {
            return Mono.error(new IllegalArgumentException("Parameter bmcKeySetName is required and cannot be null."));
        }
        if (bmcKeySetParameters == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bmcKeySetParameters is required and cannot be null."));
        } else {
            bmcKeySetParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                clusterName,
                bmcKeySetName,
                bmcKeySetParameters,
                accept,
                context);
    }

    /**
     * Create or update the baseboard management controller key set of the cluster.
     *
     * <p>Create a new baseboard management controller key set or update the existing one for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 PollerFlux} for polling of bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<BmcKeySetInner>, BmcKeySetInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String clusterName, String bmcKeySetName, BmcKeySetInner bmcKeySetParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetParameters);
        return this
            .client
            .<BmcKeySetInner, BmcKeySetInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                BmcKeySetInner.class,
                BmcKeySetInner.class,
                this.client.getContext());
    }

    /**
     * Create or update the baseboard management controller key set of the cluster.
     *
     * <p>Create a new baseboard management controller key set or update the existing one for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 PollerFlux} for polling of bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<BmcKeySetInner>, BmcKeySetInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetInner bmcKeySetParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, clusterName, bmcKeySetName, bmcKeySetParameters, context);
        return this
            .client
            .<BmcKeySetInner, BmcKeySetInner>getLroResult(
                mono, this.client.getHttpPipeline(), BmcKeySetInner.class, BmcKeySetInner.class, context);
    }

    /**
     * Create or update the baseboard management controller key set of the cluster.
     *
     * <p>Create a new baseboard management controller key set or update the existing one for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 SyncPoller} for polling of bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<BmcKeySetInner>, BmcKeySetInner> beginCreateOrUpdate(
        String resourceGroupName, String clusterName, String bmcKeySetName, BmcKeySetInner bmcKeySetParameters) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetParameters)
            .getSyncPoller();
    }

    /**
     * Create or update the baseboard management controller key set of the cluster.
     *
     * <p>Create a new baseboard management controller key set or update the existing one for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 SyncPoller} for polling of bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<BmcKeySetInner>, BmcKeySetInner> beginCreateOrUpdate(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetInner bmcKeySetParameters,
        Context context) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetParameters, context)
            .getSyncPoller();
    }

    /**
     * Create or update the baseboard management controller key set of the cluster.
     *
     * <p>Create a new baseboard management controller key set or update the existing one for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BmcKeySetInner> createOrUpdateAsync(
        String resourceGroupName, String clusterName, String bmcKeySetName, BmcKeySetInner bmcKeySetParameters) {
        return beginCreateOrUpdateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update the baseboard management controller key set of the cluster.
     *
     * <p>Create a new baseboard management controller key set or update the existing one for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BmcKeySetInner> createOrUpdateAsync(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetInner bmcKeySetParameters,
        Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update the baseboard management controller key set of the cluster.
     *
     * <p>Create a new baseboard management controller key set or update the existing one for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public BmcKeySetInner createOrUpdate(
        String resourceGroupName, String clusterName, String bmcKeySetName, BmcKeySetInner bmcKeySetParameters) {
        return createOrUpdateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetParameters).block();
    }

    /**
     * Create or update the baseboard management controller key set of the cluster.
     *
     * <p>Create a new baseboard management controller key set or update the existing one for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public BmcKeySetInner createOrUpdate(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetInner bmcKeySetParameters,
        Context context) {
        return createOrUpdateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetParameters, context).block();
    }

    /**
     * Delete the baseboard management controller key set of the cluster.
     *
     * <p>Delete the baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String clusterName, String bmcKeySetName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (bmcKeySetName == null) {
            return Mono.error(new IllegalArgumentException("Parameter bmcKeySetName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            clusterName,
                            bmcKeySetName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete the baseboard management controller key set of the cluster.
     *
     * <p>Delete the baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String clusterName, String bmcKeySetName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (bmcKeySetName == null) {
            return Mono.error(new IllegalArgumentException("Parameter bmcKeySetName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                clusterName,
                bmcKeySetName,
                accept,
                context);
    }

    /**
     * Delete the baseboard management controller key set of the cluster.
     *
     * <p>Delete the baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String clusterName, String bmcKeySetName) {
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(resourceGroupName, clusterName, bmcKeySetName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Delete the baseboard management controller key set of the cluster.
     *
     * <p>Delete the baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String clusterName, String bmcKeySetName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, clusterName, bmcKeySetName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Delete the baseboard management controller key set of the cluster.
     *
     * <p>Delete the baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String clusterName, String bmcKeySetName) {
        return this.beginDeleteAsync(resourceGroupName, clusterName, bmcKeySetName).getSyncPoller();
    }

    /**
     * Delete the baseboard management controller key set of the cluster.
     *
     * <p>Delete the baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String clusterName, String bmcKeySetName, Context context) {
        return this.beginDeleteAsync(resourceGroupName, clusterName, bmcKeySetName, context).getSyncPoller();
    }

    /**
     * Delete the baseboard management controller key set of the cluster.
     *
     * <p>Delete the baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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)
    private Mono<Void> deleteAsync(String resourceGroupName, String clusterName, String bmcKeySetName) {
        return beginDeleteAsync(resourceGroupName, clusterName, bmcKeySetName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete the baseboard management controller key set of the cluster.
     *
     * <p>Delete the baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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)
    private Mono<Void> deleteAsync(
        String resourceGroupName, String clusterName, String bmcKeySetName, Context context) {
        return beginDeleteAsync(resourceGroupName, clusterName, bmcKeySetName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete the baseboard management controller key set of the cluster.
     *
     * <p>Delete the baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 delete(String resourceGroupName, String clusterName, String bmcKeySetName) {
        deleteAsync(resourceGroupName, clusterName, bmcKeySetName).block();
    }

    /**
     * Delete the baseboard management controller key set of the cluster.
     *
     * <p>Delete the baseboard management controller key set of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 delete(String resourceGroupName, String clusterName, String bmcKeySetName, Context context) {
        deleteAsync(resourceGroupName, clusterName, bmcKeySetName, context).block();
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetUpdateParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetPatchParameters bmcKeySetUpdateParameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (bmcKeySetName == null) {
            return Mono.error(new IllegalArgumentException("Parameter bmcKeySetName is required and cannot be null."));
        }
        if (bmcKeySetUpdateParameters != null) {
            bmcKeySetUpdateParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            clusterName,
                            bmcKeySetName,
                            bmcKeySetUpdateParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetUpdateParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetPatchParameters bmcKeySetUpdateParameters,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (bmcKeySetName == null) {
            return Mono.error(new IllegalArgumentException("Parameter bmcKeySetName is required and cannot be null."));
        }
        if (bmcKeySetUpdateParameters != null) {
            bmcKeySetUpdateParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                clusterName,
                bmcKeySetName,
                bmcKeySetUpdateParameters,
                accept,
                context);
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetUpdateParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 PollerFlux} for polling of bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<BmcKeySetInner>, BmcKeySetInner> beginUpdateAsync(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetPatchParameters bmcKeySetUpdateParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetUpdateParameters);
        return this
            .client
            .<BmcKeySetInner, BmcKeySetInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                BmcKeySetInner.class,
                BmcKeySetInner.class,
                this.client.getContext());
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 PollerFlux} for polling of bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<BmcKeySetInner>, BmcKeySetInner> beginUpdateAsync(
        String resourceGroupName, String clusterName, String bmcKeySetName) {
        final BmcKeySetPatchParameters bmcKeySetUpdateParameters = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetUpdateParameters);
        return this
            .client
            .<BmcKeySetInner, BmcKeySetInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                BmcKeySetInner.class,
                BmcKeySetInner.class,
                this.client.getContext());
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetUpdateParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 PollerFlux} for polling of bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<BmcKeySetInner>, BmcKeySetInner> beginUpdateAsync(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetPatchParameters bmcKeySetUpdateParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetUpdateParameters, context);
        return this
            .client
            .<BmcKeySetInner, BmcKeySetInner>getLroResult(
                mono, this.client.getHttpPipeline(), BmcKeySetInner.class, BmcKeySetInner.class, context);
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 SyncPoller} for polling of bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<BmcKeySetInner>, BmcKeySetInner> beginUpdate(
        String resourceGroupName, String clusterName, String bmcKeySetName) {
        final BmcKeySetPatchParameters bmcKeySetUpdateParameters = null;
        return this
            .beginUpdateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetUpdateParameters)
            .getSyncPoller();
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetUpdateParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException 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 SyncPoller} for polling of bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<BmcKeySetInner>, BmcKeySetInner> beginUpdate(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetPatchParameters bmcKeySetUpdateParameters,
        Context context) {
        return this
            .beginUpdateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetUpdateParameters, context)
            .getSyncPoller();
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetUpdateParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BmcKeySetInner> updateAsync(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetPatchParameters bmcKeySetUpdateParameters) {
        return beginUpdateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetUpdateParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BmcKeySetInner> updateAsync(String resourceGroupName, String clusterName, String bmcKeySetName) {
        final BmcKeySetPatchParameters bmcKeySetUpdateParameters = null;
        return beginUpdateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetUpdateParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetUpdateParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BmcKeySetInner> updateAsync(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetPatchParameters bmcKeySetUpdateParameters,
        Context context) {
        return beginUpdateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetUpdateParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public BmcKeySetInner update(String resourceGroupName, String clusterName, String bmcKeySetName) {
        final BmcKeySetPatchParameters bmcKeySetUpdateParameters = null;
        return updateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetUpdateParameters).block();
    }

    /**
     * Patch baseboard management controller key set of the cluster.
     *
     * <p>Patch properties of baseboard management controller key set for the provided cluster, or update the tags
     * associated with it. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param bmcKeySetName The name of the baseboard management controller key set.
     * @param bmcKeySetUpdateParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySet represents the baseboard management controller key set.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public BmcKeySetInner update(
        String resourceGroupName,
        String clusterName,
        String bmcKeySetName,
        BmcKeySetPatchParameters bmcKeySetUpdateParameters,
        Context context) {
        return updateAsync(resourceGroupName, clusterName, bmcKeySetName, bmcKeySetUpdateParameters, context).block();
    }

    /**
     * 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 ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySetList represents a list of baseboard management controller key sets along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BmcKeySetInner>> listByClusterNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listByClusterNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<BmcKeySetInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * 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 ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return bmcKeySetList represents a list of baseboard management controller key sets along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BmcKeySetInner>> listByClusterNextSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByClusterNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
