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

package com.azure.resourcemanager.kubernetesconfiguration.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.kubernetesconfiguration.fluent.ExtensionsClient;
import com.azure.resourcemanager.kubernetesconfiguration.fluent.models.ExtensionInner;
import com.azure.resourcemanager.kubernetesconfiguration.models.ExtensionsList;
import com.azure.resourcemanager.kubernetesconfiguration.models.PatchExtension;
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 ExtensionsClient. */
public final class ExtensionsClientImpl implements ExtensionsClient {
    /** The proxy service used to perform REST calls. */
    private final ExtensionsService service;

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

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

    /**
     * The interface defining all the services for SourceControlConfigurationClientExtensions to be used by the proxy
     * service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "SourceControlConfigu")
    public interface ExtensionsService {
        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/{clusterRp}/{clusterResourceName}/{clusterName}/providers/Microsoft.KubernetesConfiguration/extensions/{extensionName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> create(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("clusterRp") String clusterRp,
            @PathParam("clusterResourceName") String clusterResourceName,
            @PathParam("clusterName") String clusterName,
            @PathParam("extensionName") String extensionName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") ExtensionInner extension,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

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

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

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

    /**
     * Create a new Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param extension Properties necessary to Create an Extension.
     * @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 Extension object along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createWithResponseAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension) {
        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 (clusterRp == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterRp is required and cannot be null."));
        }
        if (clusterResourceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter clusterResourceName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (extensionName == null) {
            return Mono.error(new IllegalArgumentException("Parameter extensionName is required and cannot be null."));
        }
        if (extension == null) {
            return Mono.error(new IllegalArgumentException("Parameter extension is required and cannot be null."));
        } else {
            extension.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .create(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            clusterRp,
                            clusterResourceName,
                            clusterName,
                            extensionName,
                            this.client.getApiVersion(),
                            extension,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create a new Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param extension Properties necessary to Create an Extension.
     * @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 Extension object along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createWithResponseAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension,
        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 (clusterRp == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterRp is required and cannot be null."));
        }
        if (clusterResourceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter clusterResourceName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (extensionName == null) {
            return Mono.error(new IllegalArgumentException("Parameter extensionName is required and cannot be null."));
        }
        if (extension == null) {
            return Mono.error(new IllegalArgumentException("Parameter extension is required and cannot be null."));
        } else {
            extension.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .create(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                clusterRp,
                clusterResourceName,
                clusterName,
                extensionName,
                this.client.getApiVersion(),
                extension,
                accept,
                context);
    }

    /**
     * Create a new Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param extension Properties necessary to Create an Extension.
     * @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 the Extension object.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ExtensionInner>, ExtensionInner> beginCreateAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createWithResponseAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, extension);
        return this
            .client
            .<ExtensionInner, ExtensionInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ExtensionInner.class,
                ExtensionInner.class,
                this.client.getContext());
    }

    /**
     * Create a new Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param extension Properties necessary to Create an Extension.
     * @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 the Extension object.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ExtensionInner>, ExtensionInner> beginCreateAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createWithResponseAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, extension, context);
        return this
            .client
            .<ExtensionInner, ExtensionInner>getLroResult(
                mono, this.client.getHttpPipeline(), ExtensionInner.class, ExtensionInner.class, context);
    }

    /**
     * Create a new Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param extension Properties necessary to Create an Extension.
     * @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 the Extension object.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ExtensionInner>, ExtensionInner> beginCreate(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension) {
        return this
            .beginCreateAsync(resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, extension)
            .getSyncPoller();
    }

    /**
     * Create a new Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param extension Properties necessary to Create an Extension.
     * @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 the Extension object.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ExtensionInner>, ExtensionInner> beginCreate(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension,
        Context context) {
        return this
            .beginCreateAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, extension, context)
            .getSyncPoller();
    }

    /**
     * Create a new Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param extension Properties necessary to Create an Extension.
     * @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 Extension object on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ExtensionInner> createAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension) {
        return beginCreateAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, extension)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create a new Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param extension Properties necessary to Create an Extension.
     * @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 Extension object on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ExtensionInner> createAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension,
        Context context) {
        return beginCreateAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, extension, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create a new Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param extension Properties necessary to Create an Extension.
     * @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 Extension object.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ExtensionInner create(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension) {
        return createAsync(resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, extension)
            .block();
    }

    /**
     * Create a new Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param extension Properties necessary to Create an Extension.
     * @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 Extension object.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ExtensionInner create(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        ExtensionInner extension,
        Context context) {
        return createAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, extension, context)
            .block();
    }

    /**
     * Gets Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @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 kubernetes Cluster Extension along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ExtensionInner>> getWithResponseAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName) {
        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 (clusterRp == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterRp is required and cannot be null."));
        }
        if (clusterResourceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter clusterResourceName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (extensionName == null) {
            return Mono.error(new IllegalArgumentException("Parameter extensionName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            clusterRp,
                            clusterResourceName,
                            clusterName,
                            extensionName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @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 kubernetes Cluster Extension along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ExtensionInner>> getWithResponseAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        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 (clusterRp == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterRp is required and cannot be null."));
        }
        if (clusterResourceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter clusterResourceName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (extensionName == null) {
            return Mono.error(new IllegalArgumentException("Parameter extensionName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                clusterRp,
                clusterResourceName,
                clusterName,
                extensionName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Gets Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @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 kubernetes Cluster Extension on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ExtensionInner> getAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName) {
        return getWithResponseAsync(resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @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 kubernetes Cluster Extension along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ExtensionInner> getWithResponse(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        Context context) {
        return getWithResponseAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, context)
            .block();
    }

    /**
     * Gets Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @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 kubernetes Cluster Extension.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ExtensionInner get(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName) {
        return getWithResponse(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, Context.NONE)
            .getValue();
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param forceDelete Delete the extension resource in Azure - not the normal asynchronous delete.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        Boolean forceDelete) {
        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 (clusterRp == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterRp is required and cannot be null."));
        }
        if (clusterResourceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter clusterResourceName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (extensionName == null) {
            return Mono.error(new IllegalArgumentException("Parameter extensionName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            clusterRp,
                            clusterResourceName,
                            clusterName,
                            extensionName,
                            this.client.getApiVersion(),
                            forceDelete,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param forceDelete Delete the extension resource in Azure - not the normal asynchronous delete.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        Boolean forceDelete,
        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 (clusterRp == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterRp is required and cannot be null."));
        }
        if (clusterResourceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter clusterResourceName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (extensionName == null) {
            return Mono.error(new IllegalArgumentException("Parameter extensionName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                clusterRp,
                clusterResourceName,
                clusterName,
                extensionName,
                this.client.getApiVersion(),
                forceDelete,
                accept,
                context);
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param forceDelete Delete the extension resource in Azure - not the normal asynchronous delete.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        Boolean forceDelete) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, forceDelete);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName) {
        final Boolean forceDelete = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, forceDelete);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param forceDelete Delete the extension resource in Azure - not the normal asynchronous delete.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        Boolean forceDelete,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, forceDelete, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName) {
        final Boolean forceDelete = null;
        return this
            .beginDeleteAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, forceDelete)
            .getSyncPoller();
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param forceDelete Delete the extension resource in Azure - not the normal asynchronous delete.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        Boolean forceDelete,
        Context context) {
        return this
            .beginDeleteAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, forceDelete, context)
            .getSyncPoller();
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param forceDelete Delete the extension resource in Azure - not the normal asynchronous delete.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        Boolean forceDelete) {
        return beginDeleteAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, forceDelete)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName) {
        final Boolean forceDelete = null;
        return beginDeleteAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, forceDelete)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param forceDelete Delete the extension resource in Azure - not the normal asynchronous delete.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        Boolean forceDelete,
        Context context) {
        return beginDeleteAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, forceDelete, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName) {
        final Boolean forceDelete = null;
        deleteAsync(resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, forceDelete).block();
    }

    /**
     * Delete a Kubernetes Cluster Extension. This will cause the Agent to Uninstall the extension from the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param forceDelete Delete the extension resource in Azure - not the normal asynchronous delete.
     * @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 clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        Boolean forceDelete,
        Context context) {
        deleteAsync(resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, forceDelete, context)
            .block();
    }

    /**
     * Patch an existing Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param patchExtension Properties to Patch in an existing Extension.
     * @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 Extension object along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension) {
        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 (clusterRp == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterRp is required and cannot be null."));
        }
        if (clusterResourceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter clusterResourceName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (extensionName == null) {
            return Mono.error(new IllegalArgumentException("Parameter extensionName is required and cannot be null."));
        }
        if (patchExtension == null) {
            return Mono.error(new IllegalArgumentException("Parameter patchExtension is required and cannot be null."));
        } else {
            patchExtension.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            clusterRp,
                            clusterResourceName,
                            clusterName,
                            extensionName,
                            this.client.getApiVersion(),
                            patchExtension,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Patch an existing Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param patchExtension Properties to Patch in an existing Extension.
     * @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 Extension object along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension,
        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 (clusterRp == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterRp is required and cannot be null."));
        }
        if (clusterResourceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter clusterResourceName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (extensionName == null) {
            return Mono.error(new IllegalArgumentException("Parameter extensionName is required and cannot be null."));
        }
        if (patchExtension == null) {
            return Mono.error(new IllegalArgumentException("Parameter patchExtension is required and cannot be null."));
        } else {
            patchExtension.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                clusterRp,
                clusterResourceName,
                clusterName,
                extensionName,
                this.client.getApiVersion(),
                patchExtension,
                accept,
                context);
    }

    /**
     * Patch an existing Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param patchExtension Properties to Patch in an existing Extension.
     * @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 the Extension object.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ExtensionInner>, ExtensionInner> beginUpdateAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, patchExtension);
        return this
            .client
            .<ExtensionInner, ExtensionInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ExtensionInner.class,
                ExtensionInner.class,
                this.client.getContext());
    }

    /**
     * Patch an existing Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param patchExtension Properties to Patch in an existing Extension.
     * @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 the Extension object.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ExtensionInner>, ExtensionInner> beginUpdateAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, patchExtension, context);
        return this
            .client
            .<ExtensionInner, ExtensionInner>getLroResult(
                mono, this.client.getHttpPipeline(), ExtensionInner.class, ExtensionInner.class, context);
    }

    /**
     * Patch an existing Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param patchExtension Properties to Patch in an existing Extension.
     * @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 the Extension object.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ExtensionInner>, ExtensionInner> beginUpdate(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension) {
        return this
            .beginUpdateAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, patchExtension)
            .getSyncPoller();
    }

    /**
     * Patch an existing Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param patchExtension Properties to Patch in an existing Extension.
     * @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 the Extension object.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ExtensionInner>, ExtensionInner> beginUpdate(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension,
        Context context) {
        return this
            .beginUpdateAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, patchExtension, context)
            .getSyncPoller();
    }

    /**
     * Patch an existing Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param patchExtension Properties to Patch in an existing Extension.
     * @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 Extension object on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ExtensionInner> updateAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension) {
        return beginUpdateAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, patchExtension)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patch an existing Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param patchExtension Properties to Patch in an existing Extension.
     * @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 Extension object on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ExtensionInner> updateAsync(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension,
        Context context) {
        return beginUpdateAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, patchExtension, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patch an existing Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param patchExtension Properties to Patch in an existing Extension.
     * @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 Extension object.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ExtensionInner update(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension) {
        return updateAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, patchExtension)
            .block();
    }

    /**
     * Patch an existing Kubernetes Cluster Extension.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes cluster.
     * @param extensionName Name of the Extension.
     * @param patchExtension Properties to Patch in an existing Extension.
     * @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 Extension object.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ExtensionInner update(
        String resourceGroupName,
        String clusterRp,
        String clusterResourceName,
        String clusterName,
        String extensionName,
        PatchExtension patchExtension,
        Context context) {
        return updateAsync(
                resourceGroupName, clusterRp, clusterResourceName, clusterName, extensionName, patchExtension, context)
            .block();
    }

    /**
     * List all Extensions in the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes 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 result of the request to list Extensions along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ExtensionInner>> listSinglePageAsync(
        String resourceGroupName, String clusterRp, String clusterResourceName, 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 (clusterRp == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterRp is required and cannot be null."));
        }
        if (clusterResourceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter clusterResourceName 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
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            clusterRp,
                            clusterResourceName,
                            clusterName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<ExtensionInner>>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 all Extensions in the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes 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 result of the request to list Extensions along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ExtensionInner>> listSinglePageAsync(
        String resourceGroupName, String clusterRp, String clusterResourceName, 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 (clusterRp == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterRp is required and cannot be null."));
        }
        if (clusterResourceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter clusterResourceName 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
            .list(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                clusterRp,
                clusterResourceName,
                clusterName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List all Extensions in the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes 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 result of the request to list Extensions as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ExtensionInner> listAsync(
        String resourceGroupName, String clusterRp, String clusterResourceName, String clusterName) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, clusterRp, clusterResourceName, clusterName),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * List all Extensions in the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes 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 result of the request to list Extensions as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ExtensionInner> listAsync(
        String resourceGroupName, String clusterRp, String clusterResourceName, String clusterName, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, clusterRp, clusterResourceName, clusterName, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * List all Extensions in the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes 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 result of the request to list Extensions as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ExtensionInner> list(
        String resourceGroupName, String clusterRp, String clusterResourceName, String clusterName) {
        return new PagedIterable<>(listAsync(resourceGroupName, clusterRp, clusterResourceName, clusterName));
    }

    /**
     * List all Extensions in the cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterRp The Kubernetes cluster RP - i.e. Microsoft.ContainerService, Microsoft.Kubernetes,
     *     Microsoft.HybridContainerService.
     * @param clusterResourceName The Kubernetes cluster resource name - i.e. managedClusters, connectedClusters,
     *     provisionedClusters.
     * @param clusterName The name of the kubernetes 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 result of the request to list Extensions as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ExtensionInner> list(
        String resourceGroupName, String clusterRp, String clusterResourceName, String clusterName, Context context) {
        return new PagedIterable<>(listAsync(resourceGroupName, clusterRp, clusterResourceName, clusterName, context));
    }

    /**
     * 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 result of the request to list Extensions along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ExtensionInner>> listNextSinglePageAsync(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.listNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ExtensionInner>>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 result of the request to list Extensions along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ExtensionInner>> listNextSinglePageAsync(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
            .listNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
