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

package com.azure.resourcemanager.networkcloud.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.networkcloud.fluent.MetricsConfigurationsClient;
import com.azure.resourcemanager.networkcloud.fluent.models.ClusterMetricsConfigurationInner;
import com.azure.resourcemanager.networkcloud.models.ClusterMetricsConfigurationList;
import com.azure.resourcemanager.networkcloud.models.ClusterMetricsConfigurationPatchParameters;
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 MetricsConfigurationsClient. */
public final class MetricsConfigurationsClientImpl implements MetricsConfigurationsClient {
    /** The proxy service used to perform REST calls. */
    private final MetricsConfigurationsService service;

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

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

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

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

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

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

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

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

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

    /**
     * List metrics configurations of the cluster.
     *
     * <p>Get a list of metrics configurations for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of metrics configurations for the provided cluster as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ClusterMetricsConfigurationInner> listByClusterAsync(
        String resourceGroupName, String clusterName) {
        return new PagedFlux<>(
            () -> listByClusterSinglePageAsync(resourceGroupName, clusterName),
            nextLink -> listByClusterNextSinglePageAsync(nextLink));
    }

    /**
     * List metrics configurations of the cluster.
     *
     * <p>Get a list of metrics configurations for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of metrics configurations for the provided cluster as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ClusterMetricsConfigurationInner> listByClusterAsync(
        String resourceGroupName, String clusterName, Context context) {
        return new PagedFlux<>(
            () -> listByClusterSinglePageAsync(resourceGroupName, clusterName, context),
            nextLink -> listByClusterNextSinglePageAsync(nextLink, context));
    }

    /**
     * List metrics configurations of the cluster.
     *
     * <p>Get a list of metrics configurations for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of metrics configurations for the provided cluster as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ClusterMetricsConfigurationInner> listByCluster(String resourceGroupName, String clusterName) {
        return new PagedIterable<>(listByClusterAsync(resourceGroupName, clusterName));
    }

    /**
     * List metrics configurations of the cluster.
     *
     * <p>Get a list of metrics configurations for the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of metrics configurations for the provided cluster as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ClusterMetricsConfigurationInner> listByCluster(
        String resourceGroupName, String clusterName, Context context) {
        return new PagedIterable<>(listByClusterAsync(resourceGroupName, clusterName, context));
    }

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

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

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

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

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

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

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

    /**
     * Create or update metrics configuration of the cluster.
     *
     * <p>Create new or update the existing metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of clusterMetricsConfiguration represents the metrics configuration of
     *     an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ClusterMetricsConfigurationInner>, ClusterMetricsConfigurationInner>
        beginCreateOrUpdateAsync(
            String resourceGroupName,
            String clusterName,
            String metricsConfigurationName,
            ClusterMetricsConfigurationInner metricsConfigurationParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationParameters);
        return this
            .client
            .<ClusterMetricsConfigurationInner, ClusterMetricsConfigurationInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ClusterMetricsConfigurationInner.class,
                ClusterMetricsConfigurationInner.class,
                this.client.getContext());
    }

    /**
     * Create or update metrics configuration of the cluster.
     *
     * <p>Create new or update the existing metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of clusterMetricsConfiguration represents the metrics configuration of
     *     an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ClusterMetricsConfigurationInner>, ClusterMetricsConfigurationInner>
        beginCreateOrUpdateAsync(
            String resourceGroupName,
            String clusterName,
            String metricsConfigurationName,
            ClusterMetricsConfigurationInner metricsConfigurationParameters,
            Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationParameters, context);
        return this
            .client
            .<ClusterMetricsConfigurationInner, ClusterMetricsConfigurationInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ClusterMetricsConfigurationInner.class,
                ClusterMetricsConfigurationInner.class,
                context);
    }

    /**
     * Create or update metrics configuration of the cluster.
     *
     * <p>Create new or update the existing metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of clusterMetricsConfiguration represents the metrics configuration of
     *     an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ClusterMetricsConfigurationInner>, ClusterMetricsConfigurationInner>
        beginCreateOrUpdate(
            String resourceGroupName,
            String clusterName,
            String metricsConfigurationName,
            ClusterMetricsConfigurationInner metricsConfigurationParameters) {
        return this
            .beginCreateOrUpdateAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationParameters)
            .getSyncPoller();
    }

    /**
     * Create or update metrics configuration of the cluster.
     *
     * <p>Create new or update the existing metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of clusterMetricsConfiguration represents the metrics configuration of
     *     an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ClusterMetricsConfigurationInner>, ClusterMetricsConfigurationInner>
        beginCreateOrUpdate(
            String resourceGroupName,
            String clusterName,
            String metricsConfigurationName,
            ClusterMetricsConfigurationInner metricsConfigurationParameters,
            Context context) {
        return this
            .beginCreateOrUpdateAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationParameters, context)
            .getSyncPoller();
    }

    /**
     * Create or update metrics configuration of the cluster.
     *
     * <p>Create new or update the existing metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return clusterMetricsConfiguration represents the metrics configuration of an on-premises Network Cloud cluster
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ClusterMetricsConfigurationInner> createOrUpdateAsync(
        String resourceGroupName,
        String clusterName,
        String metricsConfigurationName,
        ClusterMetricsConfigurationInner metricsConfigurationParameters) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update metrics configuration of the cluster.
     *
     * <p>Create new or update the existing metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return clusterMetricsConfiguration represents the metrics configuration of an on-premises Network Cloud cluster
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ClusterMetricsConfigurationInner> createOrUpdateAsync(
        String resourceGroupName,
        String clusterName,
        String metricsConfigurationName,
        ClusterMetricsConfigurationInner metricsConfigurationParameters,
        Context context) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update metrics configuration of the cluster.
     *
     * <p>Create new or update the existing metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return clusterMetricsConfiguration represents the metrics configuration of an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ClusterMetricsConfigurationInner createOrUpdate(
        String resourceGroupName,
        String clusterName,
        String metricsConfigurationName,
        ClusterMetricsConfigurationInner metricsConfigurationParameters) {
        return createOrUpdateAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationParameters)
            .block();
    }

    /**
     * Create or update metrics configuration of the cluster.
     *
     * <p>Create new or update the existing metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return clusterMetricsConfiguration represents the metrics configuration of an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ClusterMetricsConfigurationInner createOrUpdate(
        String resourceGroupName,
        String clusterName,
        String metricsConfigurationName,
        ClusterMetricsConfigurationInner metricsConfigurationParameters,
        Context context) {
        return createOrUpdateAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationParameters, context)
            .block();
    }

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

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

    /**
     * Delete the metrics configuration of the cluster.
     *
     * <p>Delete the metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String clusterName, String metricsConfigurationName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, clusterName, metricsConfigurationName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Delete the metrics configuration of the cluster.
     *
     * <p>Delete the metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String clusterName, String metricsConfigurationName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, clusterName, metricsConfigurationName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Delete the metrics configuration of the cluster.
     *
     * <p>Delete the metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String clusterName, String metricsConfigurationName) {
        return this.beginDeleteAsync(resourceGroupName, clusterName, metricsConfigurationName).getSyncPoller();
    }

    /**
     * Delete the metrics configuration of the cluster.
     *
     * <p>Delete the metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String clusterName, String metricsConfigurationName, Context context) {
        return this.beginDeleteAsync(resourceGroupName, clusterName, metricsConfigurationName, context).getSyncPoller();
    }

    /**
     * Delete the metrics configuration of the cluster.
     *
     * <p>Delete the metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String clusterName, String metricsConfigurationName) {
        return beginDeleteAsync(resourceGroupName, clusterName, metricsConfigurationName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete the metrics configuration of the cluster.
     *
     * <p>Delete the metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(
        String resourceGroupName, String clusterName, String metricsConfigurationName, Context context) {
        return beginDeleteAsync(resourceGroupName, clusterName, metricsConfigurationName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete the metrics configuration of the cluster.
     *
     * <p>Delete the metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String clusterName, String metricsConfigurationName) {
        deleteAsync(resourceGroupName, clusterName, metricsConfigurationName).block();
    }

    /**
     * Delete the metrics configuration of the cluster.
     *
     * <p>Delete the metrics configuration of the provided cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String clusterName, String metricsConfigurationName, Context context) {
        deleteAsync(resourceGroupName, clusterName, metricsConfigurationName, context).block();
    }

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

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

    /**
     * Patch metrics configuration of the cluster.
     *
     * <p>Patch properties of metrics configuration for the provided cluster, or update the tags associated with it.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationUpdateParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of clusterMetricsConfiguration represents the metrics configuration of
     *     an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ClusterMetricsConfigurationInner>, ClusterMetricsConfigurationInner> beginUpdateAsync(
        String resourceGroupName,
        String clusterName,
        String metricsConfigurationName,
        ClusterMetricsConfigurationPatchParameters metricsConfigurationUpdateParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationUpdateParameters);
        return this
            .client
            .<ClusterMetricsConfigurationInner, ClusterMetricsConfigurationInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ClusterMetricsConfigurationInner.class,
                ClusterMetricsConfigurationInner.class,
                this.client.getContext());
    }

    /**
     * Patch metrics configuration of the cluster.
     *
     * <p>Patch properties of metrics configuration for the provided cluster, or update the tags associated with it.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of clusterMetricsConfiguration represents the metrics configuration of
     *     an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ClusterMetricsConfigurationInner>, ClusterMetricsConfigurationInner> beginUpdateAsync(
        String resourceGroupName, String clusterName, String metricsConfigurationName) {
        final ClusterMetricsConfigurationPatchParameters metricsConfigurationUpdateParameters = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationUpdateParameters);
        return this
            .client
            .<ClusterMetricsConfigurationInner, ClusterMetricsConfigurationInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ClusterMetricsConfigurationInner.class,
                ClusterMetricsConfigurationInner.class,
                this.client.getContext());
    }

    /**
     * Patch metrics configuration of the cluster.
     *
     * <p>Patch properties of metrics configuration for the provided cluster, or update the tags associated with it.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationUpdateParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of clusterMetricsConfiguration represents the metrics configuration of
     *     an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ClusterMetricsConfigurationInner>, ClusterMetricsConfigurationInner> beginUpdateAsync(
        String resourceGroupName,
        String clusterName,
        String metricsConfigurationName,
        ClusterMetricsConfigurationPatchParameters metricsConfigurationUpdateParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(
                resourceGroupName,
                clusterName,
                metricsConfigurationName,
                metricsConfigurationUpdateParameters,
                context);
        return this
            .client
            .<ClusterMetricsConfigurationInner, ClusterMetricsConfigurationInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ClusterMetricsConfigurationInner.class,
                ClusterMetricsConfigurationInner.class,
                context);
    }

    /**
     * Patch metrics configuration of the cluster.
     *
     * <p>Patch properties of metrics configuration for the provided cluster, or update the tags associated with it.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of clusterMetricsConfiguration represents the metrics configuration of
     *     an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ClusterMetricsConfigurationInner>, ClusterMetricsConfigurationInner> beginUpdate(
        String resourceGroupName, String clusterName, String metricsConfigurationName) {
        final ClusterMetricsConfigurationPatchParameters metricsConfigurationUpdateParameters = null;
        return this
            .beginUpdateAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationUpdateParameters)
            .getSyncPoller();
    }

    /**
     * Patch metrics configuration of the cluster.
     *
     * <p>Patch properties of metrics configuration for the provided cluster, or update the tags associated with it.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationUpdateParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of clusterMetricsConfiguration represents the metrics configuration of
     *     an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ClusterMetricsConfigurationInner>, ClusterMetricsConfigurationInner> beginUpdate(
        String resourceGroupName,
        String clusterName,
        String metricsConfigurationName,
        ClusterMetricsConfigurationPatchParameters metricsConfigurationUpdateParameters,
        Context context) {
        return this
            .beginUpdateAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationUpdateParameters, context)
            .getSyncPoller();
    }

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

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

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

    /**
     * Patch metrics configuration of the cluster.
     *
     * <p>Patch properties of metrics configuration for the provided cluster, or update the tags associated with it.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return clusterMetricsConfiguration represents the metrics configuration of an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ClusterMetricsConfigurationInner update(
        String resourceGroupName, String clusterName, String metricsConfigurationName) {
        final ClusterMetricsConfigurationPatchParameters metricsConfigurationUpdateParameters = null;
        return updateAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationUpdateParameters)
            .block();
    }

    /**
     * Patch metrics configuration of the cluster.
     *
     * <p>Patch properties of metrics configuration for the provided cluster, or update the tags associated with it.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param clusterName The name of the cluster.
     * @param metricsConfigurationName The name of the metrics configuration for the cluster.
     * @param metricsConfigurationUpdateParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return clusterMetricsConfiguration represents the metrics configuration of an on-premises Network Cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ClusterMetricsConfigurationInner update(
        String resourceGroupName,
        String clusterName,
        String metricsConfigurationName,
        ClusterMetricsConfigurationPatchParameters metricsConfigurationUpdateParameters,
        Context context) {
        return updateAsync(
                resourceGroupName, clusterName, metricsConfigurationName, metricsConfigurationUpdateParameters, context)
            .block();
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return clusterMetricsConfigurationList represents a list of metrics configuration of the cluster along with
     *     {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ClusterMetricsConfigurationInner>> listByClusterNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listByClusterNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ClusterMetricsConfigurationInner>>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 clusterMetricsConfigurationList represents a list of metrics configuration of the cluster along with
     *     {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ClusterMetricsConfigurationInner>> listByClusterNextSinglePageAsync(
        String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByClusterNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
