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

package com.azure.resourcemanager.networkfunction.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.networkfunction.fluent.CollectorPoliciesClient;
import com.azure.resourcemanager.networkfunction.fluent.models.CollectorPolicyInner;
import com.azure.resourcemanager.networkfunction.models.CollectorPolicyListResult;
import com.azure.resourcemanager.networkfunction.models.TagsObject;
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 CollectorPoliciesClient. */
public final class CollectorPoliciesClientImpl implements CollectorPoliciesClient {
    /** The proxy service used to perform REST calls. */
    private final CollectorPoliciesService service;

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

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

    /**
     * The interface defining all the services for AzureTrafficCollectorManagementClientCollectorPolicies to be used by
     * the proxy service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "AzureTrafficCollecto")
    public interface CollectorPoliciesService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkFunction"
                + "/azureTrafficCollectors/{azureTrafficCollectorName}/collectorPolicies")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<CollectorPolicyListResult>> list(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("azureTrafficCollectorName") String azureTrafficCollectorName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkFunction"
                + "/azureTrafficCollectors/{azureTrafficCollectorName}/collectorPolicies/{collectorPolicyName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<CollectorPolicyInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("azureTrafficCollectorName") String azureTrafficCollectorName,
            @PathParam("collectorPolicyName") String collectorPolicyName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkFunction"
                + "/azureTrafficCollectors/{azureTrafficCollectorName}/collectorPolicies/{collectorPolicyName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("azureTrafficCollectorName") String azureTrafficCollectorName,
            @PathParam("collectorPolicyName") String collectorPolicyName,
            @BodyParam("application/json") CollectorPolicyInner parameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkFunction"
                + "/azureTrafficCollectors/{azureTrafficCollectorName}/collectorPolicies/{collectorPolicyName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<CollectorPolicyInner>> updateTags(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("azureTrafficCollectorName") String azureTrafficCollectorName,
            @PathParam("collectorPolicyName") String collectorPolicyName,
            @BodyParam("application/json") TagsObject parameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Return list of Collector policies in a Azure Traffic Collector.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @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 response for the ListCollectorPolicies API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CollectorPolicyInner>> listSinglePageAsync(
        String resourceGroupName, String azureTrafficCollectorName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (azureTrafficCollectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter azureTrafficCollectorName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            azureTrafficCollectorName,
                            accept,
                            context))
            .<PagedResponse<CollectorPolicyInner>>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()));
    }

    /**
     * Return list of Collector policies in a Azure Traffic Collector.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @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 response for the ListCollectorPolicies API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CollectorPolicyInner>> listSinglePageAsync(
        String resourceGroupName, String azureTrafficCollectorName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (azureTrafficCollectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter azureTrafficCollectorName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                azureTrafficCollectorName,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Return list of Collector policies in a Azure Traffic Collector.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @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 response for the ListCollectorPolicies API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CollectorPolicyInner> listAsync(String resourceGroupName, String azureTrafficCollectorName) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, azureTrafficCollectorName),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Return list of Collector policies in a Azure Traffic Collector.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @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 response for the ListCollectorPolicies API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CollectorPolicyInner> listAsync(
        String resourceGroupName, String azureTrafficCollectorName, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, azureTrafficCollectorName, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Return list of Collector policies in a Azure Traffic Collector.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @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 response for the ListCollectorPolicies API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CollectorPolicyInner> list(String resourceGroupName, String azureTrafficCollectorName) {
        return new PagedIterable<>(listAsync(resourceGroupName, azureTrafficCollectorName));
    }

    /**
     * Return list of Collector policies in a Azure Traffic Collector.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @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 response for the ListCollectorPolicies API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CollectorPolicyInner> list(
        String resourceGroupName, String azureTrafficCollectorName, Context context) {
        return new PagedIterable<>(listAsync(resourceGroupName, azureTrafficCollectorName, context));
    }

    /**
     * Gets the collector policy in a specified Traffic Collector.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 collector policy in a specified Traffic Collector along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CollectorPolicyInner>> getWithResponseAsync(
        String resourceGroupName, String azureTrafficCollectorName, String collectorPolicyName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (azureTrafficCollectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter azureTrafficCollectorName is required and cannot be null."));
        }
        if (collectorPolicyName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter collectorPolicyName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            azureTrafficCollectorName,
                            collectorPolicyName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets the collector policy in a specified Traffic Collector.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 collector policy in a specified Traffic Collector along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CollectorPolicyInner>> getWithResponseAsync(
        String resourceGroupName, String azureTrafficCollectorName, String collectorPolicyName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (azureTrafficCollectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter azureTrafficCollectorName is required and cannot be null."));
        }
        if (collectorPolicyName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter collectorPolicyName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                azureTrafficCollectorName,
                collectorPolicyName,
                accept,
                context);
    }

    /**
     * Gets the collector policy in a specified Traffic Collector.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 collector policy in a specified Traffic Collector on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CollectorPolicyInner> getAsync(
        String resourceGroupName, String azureTrafficCollectorName, String collectorPolicyName) {
        return getWithResponseAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets the collector policy in a specified Traffic Collector.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 collector policy in a specified Traffic Collector along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CollectorPolicyInner> getWithResponse(
        String resourceGroupName, String azureTrafficCollectorName, String collectorPolicyName, Context context) {
        return getWithResponseAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName, context).block();
    }

    /**
     * Gets the collector policy in a specified Traffic Collector.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 collector policy in a specified Traffic Collector.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CollectorPolicyInner get(
        String resourceGroupName, String azureTrafficCollectorName, String collectorPolicyName) {
        return getWithResponse(resourceGroupName, azureTrafficCollectorName, collectorPolicyName, Context.NONE)
            .getValue();
    }

    /**
     * Creates or updates a Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters The parameters to provide for the created Collector Policy.
     * @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 collector policy resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        CollectorPolicyInner parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (azureTrafficCollectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter azureTrafficCollectorName is required and cannot be null."));
        }
        if (collectorPolicyName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter collectorPolicyName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            azureTrafficCollectorName,
                            collectorPolicyName,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters The parameters to provide for the created Collector Policy.
     * @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 collector policy resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        CollectorPolicyInner parameters,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (azureTrafficCollectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter azureTrafficCollectorName is required and cannot be null."));
        }
        if (collectorPolicyName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter collectorPolicyName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                azureTrafficCollectorName,
                collectorPolicyName,
                parameters,
                accept,
                context);
    }

    /**
     * Creates or updates a Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters The parameters to provide for the created Collector Policy.
     * @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 collector policy resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CollectorPolicyInner>, CollectorPolicyInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        CollectorPolicyInner parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, azureTrafficCollectorName, collectorPolicyName, parameters);
        return this
            .client
            .<CollectorPolicyInner, CollectorPolicyInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CollectorPolicyInner.class,
                CollectorPolicyInner.class,
                this.client.getContext());
    }

    /**
     * Creates or updates a Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters The parameters to provide for the created Collector Policy.
     * @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 collector policy resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CollectorPolicyInner>, CollectorPolicyInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        CollectorPolicyInner parameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, azureTrafficCollectorName, collectorPolicyName, parameters, context);
        return this
            .client
            .<CollectorPolicyInner, CollectorPolicyInner>getLroResult(
                mono, this.client.getHttpPipeline(), CollectorPolicyInner.class, CollectorPolicyInner.class, context);
    }

    /**
     * Creates or updates a Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters The parameters to provide for the created Collector Policy.
     * @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 collector policy resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CollectorPolicyInner>, CollectorPolicyInner> beginCreateOrUpdate(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        CollectorPolicyInner parameters) {
        return beginCreateOrUpdateAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName, parameters)
            .getSyncPoller();
    }

    /**
     * Creates or updates a Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters The parameters to provide for the created Collector Policy.
     * @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 collector policy resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CollectorPolicyInner>, CollectorPolicyInner> beginCreateOrUpdate(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        CollectorPolicyInner parameters,
        Context context) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, azureTrafficCollectorName, collectorPolicyName, parameters, context)
            .getSyncPoller();
    }

    /**
     * Creates or updates a Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters The parameters to provide for the created Collector Policy.
     * @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 collector policy resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CollectorPolicyInner> createOrUpdateAsync(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        CollectorPolicyInner parameters) {
        return beginCreateOrUpdateAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates a Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters The parameters to provide for the created Collector Policy.
     * @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 collector policy resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CollectorPolicyInner> createOrUpdateAsync(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        CollectorPolicyInner parameters,
        Context context) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, azureTrafficCollectorName, collectorPolicyName, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates a Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters The parameters to provide for the created Collector Policy.
     * @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 collector policy resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CollectorPolicyInner createOrUpdate(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        CollectorPolicyInner parameters) {
        return createOrUpdateAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName, parameters)
            .block();
    }

    /**
     * Creates or updates a Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters The parameters to provide for the created Collector Policy.
     * @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 collector policy resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CollectorPolicyInner createOrUpdate(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        CollectorPolicyInner parameters,
        Context context) {
        return createOrUpdateAsync(
                resourceGroupName, azureTrafficCollectorName, collectorPolicyName, parameters, context)
            .block();
    }

    /**
     * Deletes a specified Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 azureTrafficCollectorName, String collectorPolicyName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (azureTrafficCollectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter azureTrafficCollectorName is required and cannot be null."));
        }
        if (collectorPolicyName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter collectorPolicyName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            azureTrafficCollectorName,
                            collectorPolicyName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes a specified Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 azureTrafficCollectorName, String collectorPolicyName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (azureTrafficCollectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter azureTrafficCollectorName is required and cannot be null."));
        }
        if (collectorPolicyName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter collectorPolicyName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                azureTrafficCollectorName,
                collectorPolicyName,
                accept,
                context);
    }

    /**
     * Deletes a specified Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 azureTrafficCollectorName, String collectorPolicyName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Deletes a specified Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 azureTrafficCollectorName, String collectorPolicyName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Deletes a specified Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 azureTrafficCollectorName, String collectorPolicyName) {
        return beginDeleteAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName).getSyncPoller();
    }

    /**
     * Deletes a specified Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 azureTrafficCollectorName, String collectorPolicyName, Context context) {
        return beginDeleteAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName, context)
            .getSyncPoller();
    }

    /**
     * Deletes a specified Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 azureTrafficCollectorName, String collectorPolicyName) {
        return beginDeleteAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a specified Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 azureTrafficCollectorName, String collectorPolicyName, Context context) {
        return beginDeleteAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a specified Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 azureTrafficCollectorName, String collectorPolicyName) {
        deleteAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName).block();
    }

    /**
     * Deletes a specified Collector Policy resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @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 azureTrafficCollectorName, String collectorPolicyName, Context context) {
        deleteAsync(resourceGroupName, azureTrafficCollectorName, collectorPolicyName, context).block();
    }

    /**
     * Updates the specified Collector Policy tags.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters Parameters supplied to update Collector Policy tags.
     * @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 collector policy resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CollectorPolicyInner>> updateTagsWithResponseAsync(
        String resourceGroupName, String azureTrafficCollectorName, String collectorPolicyName, TagsObject parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (azureTrafficCollectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter azureTrafficCollectorName is required and cannot be null."));
        }
        if (collectorPolicyName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter collectorPolicyName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .updateTags(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            azureTrafficCollectorName,
                            collectorPolicyName,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Updates the specified Collector Policy tags.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters Parameters supplied to update Collector Policy tags.
     * @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 collector policy resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CollectorPolicyInner>> updateTagsWithResponseAsync(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        TagsObject parameters,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (azureTrafficCollectorName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter azureTrafficCollectorName is required and cannot be null."));
        }
        if (collectorPolicyName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter collectorPolicyName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .updateTags(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                azureTrafficCollectorName,
                collectorPolicyName,
                parameters,
                accept,
                context);
    }

    /**
     * Updates the specified Collector Policy tags.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters Parameters supplied to update Collector Policy tags.
     * @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 collector policy resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CollectorPolicyInner> updateTagsAsync(
        String resourceGroupName, String azureTrafficCollectorName, String collectorPolicyName, TagsObject parameters) {
        return updateTagsWithResponseAsync(
                resourceGroupName, azureTrafficCollectorName, collectorPolicyName, parameters)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Updates the specified Collector Policy tags.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters Parameters supplied to update Collector Policy tags.
     * @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 collector policy resource along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CollectorPolicyInner> updateTagsWithResponse(
        String resourceGroupName,
        String azureTrafficCollectorName,
        String collectorPolicyName,
        TagsObject parameters,
        Context context) {
        return updateTagsWithResponseAsync(
                resourceGroupName, azureTrafficCollectorName, collectorPolicyName, parameters, context)
            .block();
    }

    /**
     * Updates the specified Collector Policy tags.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param collectorPolicyName Collector Policy Name.
     * @param parameters Parameters supplied to update Collector Policy tags.
     * @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 collector policy resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CollectorPolicyInner updateTags(
        String resourceGroupName, String azureTrafficCollectorName, String collectorPolicyName, TagsObject parameters) {
        return updateTagsWithResponse(
                resourceGroupName, azureTrafficCollectorName, collectorPolicyName, parameters, Context.NONE)
            .getValue();
    }

    /**
     * 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 response for the ListCollectorPolicies API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CollectorPolicyInner>> 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<CollectorPolicyInner>>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 response for the ListCollectorPolicies API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CollectorPolicyInner>> 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));
    }
}
