// 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.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.AzureTrafficCollectorsClient;
import com.azure.resourcemanager.networkfunction.fluent.models.AzureTrafficCollectorInner;
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 AzureTrafficCollectorsClient. */
public final class AzureTrafficCollectorsClientImpl implements AzureTrafficCollectorsClient {
    /** The proxy service used to perform REST calls. */
    private final AzureTrafficCollectorsService service;

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

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

    /**
     * The interface defining all the services for AzureTrafficCollectorManagementClientAzureTrafficCollectors to be
     * used by the proxy service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "AzureTrafficCollecto")
    public interface AzureTrafficCollectorsService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkFunction"
                + "/azureTrafficCollectors/{azureTrafficCollectorName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<AzureTrafficCollectorInner>> getByResourceGroup(
            @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"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkFunction"
                + "/azureTrafficCollectors/{azureTrafficCollectorName}")
        @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,
            @BodyParam("application/json") AzureTrafficCollectorInner parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkFunction"
                + "/azureTrafficCollectors/{azureTrafficCollectorName}")
        @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,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Gets the specified Azure Traffic Collector in a specified resource group.
     *
     * @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 the specified Azure Traffic Collector in a specified resource group along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<AzureTrafficCollectorInner>> getByResourceGroupWithResponseAsync(
        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
                        .getByResourceGroup(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            azureTrafficCollectorName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets the specified Azure Traffic Collector in a specified resource group.
     *
     * @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 the specified Azure Traffic Collector in a specified resource group along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<AzureTrafficCollectorInner>> getByResourceGroupWithResponseAsync(
        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
            .getByResourceGroup(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                azureTrafficCollectorName,
                accept,
                context);
    }

    /**
     * Gets the specified Azure Traffic Collector in a specified resource group.
     *
     * @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 the specified Azure Traffic Collector in a specified resource group on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AzureTrafficCollectorInner> getByResourceGroupAsync(
        String resourceGroupName, String azureTrafficCollectorName) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, azureTrafficCollectorName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets the specified Azure Traffic Collector in a specified resource group.
     *
     * @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 the specified Azure Traffic Collector in a specified resource group along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<AzureTrafficCollectorInner> getByResourceGroupWithResponse(
        String resourceGroupName, String azureTrafficCollectorName, Context context) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, azureTrafficCollectorName, context).block();
    }

    /**
     * Gets the specified Azure Traffic Collector in a specified resource group.
     *
     * @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 the specified Azure Traffic Collector in a specified resource group.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AzureTrafficCollectorInner getByResourceGroup(String resourceGroupName, String azureTrafficCollectorName) {
        return getByResourceGroupWithResponse(resourceGroupName, azureTrafficCollectorName, Context.NONE).getValue();
    }

    /**
     * Creates or updates a Azure Traffic Collector resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param parameters The parameters to provide for the created Azure Traffic Collector.
     * @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 azure Traffic Collector 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, AzureTrafficCollectorInner 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 (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,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a Azure Traffic Collector resource.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param parameters The parameters to provide for the created Azure Traffic Collector.
     * @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 azure Traffic Collector 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,
        AzureTrafficCollectorInner 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 (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,
                parameters,
                accept,
                context);
    }

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

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

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

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

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

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

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

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

    /**
     * Deletes a specified Azure Traffic Collector resource.
     *
     * @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 the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        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
                        .delete(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            azureTrafficCollectorName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes a specified Azure Traffic Collector resource.
     *
     * @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 the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        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
            .delete(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                azureTrafficCollectorName,
                accept,
                context);
    }

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

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

    /**
     * Deletes a specified Azure Traffic Collector resource.
     *
     * @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 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) {
        return beginDeleteAsync(resourceGroupName, azureTrafficCollectorName).getSyncPoller();
    }

    /**
     * Deletes a specified Azure Traffic Collector resource.
     *
     * @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 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, Context context) {
        return beginDeleteAsync(resourceGroupName, azureTrafficCollectorName, context).getSyncPoller();
    }

    /**
     * Deletes a specified Azure Traffic Collector resource.
     *
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String azureTrafficCollectorName) {
        return beginDeleteAsync(resourceGroupName, azureTrafficCollectorName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a specified Azure Traffic Collector resource.
     *
     * @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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String azureTrafficCollectorName, Context context) {
        return beginDeleteAsync(resourceGroupName, azureTrafficCollectorName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a specified Azure Traffic Collector resource.
     *
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String azureTrafficCollectorName) {
        deleteAsync(resourceGroupName, azureTrafficCollectorName).block();
    }

    /**
     * Deletes a specified Azure Traffic Collector resource.
     *
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String azureTrafficCollectorName, Context context) {
        deleteAsync(resourceGroupName, azureTrafficCollectorName, context).block();
    }

    /**
     * Updates the specified Azure Traffic Collector tags.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param parameters Parameters supplied to update Azure Traffic Collector 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 azure Traffic Collector resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<AzureTrafficCollectorInner>> updateTagsWithResponseAsync(
        String resourceGroupName, String azureTrafficCollectorName, 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 (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,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Updates the specified Azure Traffic Collector tags.
     *
     * @param resourceGroupName The name of the resource group.
     * @param azureTrafficCollectorName Azure Traffic Collector name.
     * @param parameters Parameters supplied to update Azure Traffic Collector 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 azure Traffic Collector resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<AzureTrafficCollectorInner>> updateTagsWithResponseAsync(
        String resourceGroupName, String azureTrafficCollectorName, 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 (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,
                parameters,
                accept,
                context);
    }

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

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

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