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

package com.azure.resourcemanager.managednetworkfabric.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.Post;
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.managednetworkfabric.fluent.NetworkDevicesClient;
import com.azure.resourcemanager.managednetworkfabric.fluent.models.CommonPostActionResponseForStateUpdateInner;
import com.azure.resourcemanager.managednetworkfabric.fluent.models.NetworkDeviceInner;
import com.azure.resourcemanager.managednetworkfabric.models.NetworkDevicePatchParameters;
import com.azure.resourcemanager.managednetworkfabric.models.NetworkDevicesListResult;
import com.azure.resourcemanager.managednetworkfabric.models.RebootProperties;
import com.azure.resourcemanager.managednetworkfabric.models.UpdateDeviceAdministrativeState;
import com.azure.resourcemanager.managednetworkfabric.models.UpdateVersion;
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 NetworkDevicesClient. */
public final class NetworkDevicesClientImpl implements NetworkDevicesClient {
    /** The proxy service used to perform REST calls. */
    private final NetworkDevicesService service;

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

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

    /**
     * The interface defining all the services for AzureNetworkFabricManagementServiceApiNetworkDevices to be used by
     * the proxy service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "AzureNetworkFabricMa")
    public interface NetworkDevicesService {
        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedNetworkFabric/networkDevices/{networkDeviceName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> create(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("networkDeviceName") String networkDeviceName,
            @BodyParam("application/json") NetworkDeviceInner body,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

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

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

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedNetworkFabric/networkDevices/{networkDeviceName}/reboot")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> reboot(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("networkDeviceName") String networkDeviceName,
            @BodyParam("application/json") RebootProperties body,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedNetworkFabric/networkDevices/{networkDeviceName}/refreshConfiguration")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> refreshConfiguration(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("networkDeviceName") String networkDeviceName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedNetworkFabric/networkDevices/{networkDeviceName}/updateAdministrativeState")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> updateAdministrativeState(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("networkDeviceName") String networkDeviceName,
            @BodyParam("application/json") UpdateDeviceAdministrativeState body,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.ManagedNetworkFabric/networkDevices/{networkDeviceName}/upgrade")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> upgrade(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("networkDeviceName") String networkDeviceName,
            @BodyParam("application/json") UpdateVersion body,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

    /**
     * Create Network Device.
     *
     * <p>Create a Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 Network Device resource definition along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createWithResponseAsync(
        String resourceGroupName, String networkDeviceName, NetworkDeviceInner body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .create(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            networkDeviceName,
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create Network Device.
     *
     * <p>Create a Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 Network Device resource definition along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createWithResponseAsync(
        String resourceGroupName, String networkDeviceName, NetworkDeviceInner body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .create(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                networkDeviceName,
                body,
                accept,
                context);
    }

    /**
     * Create Network Device.
     *
     * <p>Create a Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of the Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<NetworkDeviceInner>, NetworkDeviceInner> beginCreateAsync(
        String resourceGroupName, String networkDeviceName, NetworkDeviceInner body) {
        Mono<Response<Flux<ByteBuffer>>> mono = createWithResponseAsync(resourceGroupName, networkDeviceName, body);
        return this
            .client
            .<NetworkDeviceInner, NetworkDeviceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                NetworkDeviceInner.class,
                NetworkDeviceInner.class,
                this.client.getContext());
    }

    /**
     * Create Network Device.
     *
     * <p>Create a Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of the Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<NetworkDeviceInner>, NetworkDeviceInner> beginCreateAsync(
        String resourceGroupName, String networkDeviceName, NetworkDeviceInner body, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createWithResponseAsync(resourceGroupName, networkDeviceName, body, context);
        return this
            .client
            .<NetworkDeviceInner, NetworkDeviceInner>getLroResult(
                mono, this.client.getHttpPipeline(), NetworkDeviceInner.class, NetworkDeviceInner.class, context);
    }

    /**
     * Create Network Device.
     *
     * <p>Create a Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of the Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<NetworkDeviceInner>, NetworkDeviceInner> beginCreate(
        String resourceGroupName, String networkDeviceName, NetworkDeviceInner body) {
        return this.beginCreateAsync(resourceGroupName, networkDeviceName, body).getSyncPoller();
    }

    /**
     * Create Network Device.
     *
     * <p>Create a Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of the Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<NetworkDeviceInner>, NetworkDeviceInner> beginCreate(
        String resourceGroupName, String networkDeviceName, NetworkDeviceInner body, Context context) {
        return this.beginCreateAsync(resourceGroupName, networkDeviceName, body, context).getSyncPoller();
    }

    /**
     * Create Network Device.
     *
     * <p>Create a Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 Network Device resource definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<NetworkDeviceInner> createAsync(
        String resourceGroupName, String networkDeviceName, NetworkDeviceInner body) {
        return beginCreateAsync(resourceGroupName, networkDeviceName, body)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create Network Device.
     *
     * <p>Create a Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 Network Device resource definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<NetworkDeviceInner> createAsync(
        String resourceGroupName, String networkDeviceName, NetworkDeviceInner body, Context context) {
        return beginCreateAsync(resourceGroupName, networkDeviceName, body, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create Network Device.
     *
     * <p>Create a Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public NetworkDeviceInner create(String resourceGroupName, String networkDeviceName, NetworkDeviceInner body) {
        return createAsync(resourceGroupName, networkDeviceName, body).block();
    }

    /**
     * Create Network Device.
     *
     * <p>Create a Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public NetworkDeviceInner create(
        String resourceGroupName, String networkDeviceName, NetworkDeviceInner body, Context context) {
        return createAsync(resourceGroupName, networkDeviceName, body, context).block();
    }

    /**
     * Gets a Network Device.
     *
     * <p>Gets the Network Device resource details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 Network Device resource details along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<NetworkDeviceInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String networkDeviceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            networkDeviceName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets a Network Device.
     *
     * <p>Gets the Network Device resource details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 Network Device resource details along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<NetworkDeviceInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String networkDeviceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getByResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                networkDeviceName,
                accept,
                context);
    }

    /**
     * Gets a Network Device.
     *
     * <p>Gets the Network Device resource details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 Network Device resource details on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<NetworkDeviceInner> getByResourceGroupAsync(String resourceGroupName, String networkDeviceName) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, networkDeviceName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets a Network Device.
     *
     * <p>Gets the Network Device resource details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 Network Device resource details along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<NetworkDeviceInner> getByResourceGroupWithResponse(
        String resourceGroupName, String networkDeviceName, Context context) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, networkDeviceName, context).block();
    }

    /**
     * Gets a Network Device.
     *
     * <p>Gets the Network Device resource details.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 Network Device resource details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public NetworkDeviceInner getByResourceGroup(String resourceGroupName, String networkDeviceName) {
        return getByResourceGroupWithResponse(resourceGroupName, networkDeviceName, Context.NONE).getValue();
    }

    /**
     * Updates a Network Device.
     *
     * <p>Update certain properties of the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Network Device properties to update.
     * @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 Network Device resource definition along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName, String networkDeviceName, NetworkDevicePatchParameters body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            networkDeviceName,
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Updates a Network Device.
     *
     * <p>Update certain properties of the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Network Device properties to update.
     * @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 Network Device resource definition along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName, String networkDeviceName, NetworkDevicePatchParameters body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                networkDeviceName,
                body,
                accept,
                context);
    }

    /**
     * Updates a Network Device.
     *
     * <p>Update certain properties of the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Network Device properties to update.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of the Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<NetworkDeviceInner>, NetworkDeviceInner> beginUpdateAsync(
        String resourceGroupName, String networkDeviceName, NetworkDevicePatchParameters body) {
        Mono<Response<Flux<ByteBuffer>>> mono = updateWithResponseAsync(resourceGroupName, networkDeviceName, body);
        return this
            .client
            .<NetworkDeviceInner, NetworkDeviceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                NetworkDeviceInner.class,
                NetworkDeviceInner.class,
                this.client.getContext());
    }

    /**
     * Updates a Network Device.
     *
     * <p>Update certain properties of the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Network Device properties to update.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of the Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<NetworkDeviceInner>, NetworkDeviceInner> beginUpdateAsync(
        String resourceGroupName, String networkDeviceName, NetworkDevicePatchParameters body, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, networkDeviceName, body, context);
        return this
            .client
            .<NetworkDeviceInner, NetworkDeviceInner>getLroResult(
                mono, this.client.getHttpPipeline(), NetworkDeviceInner.class, NetworkDeviceInner.class, context);
    }

    /**
     * Updates a Network Device.
     *
     * <p>Update certain properties of the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Network Device properties to update.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of the Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<NetworkDeviceInner>, NetworkDeviceInner> beginUpdate(
        String resourceGroupName, String networkDeviceName, NetworkDevicePatchParameters body) {
        return this.beginUpdateAsync(resourceGroupName, networkDeviceName, body).getSyncPoller();
    }

    /**
     * Updates a Network Device.
     *
     * <p>Update certain properties of the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Network Device properties to update.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of the Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<NetworkDeviceInner>, NetworkDeviceInner> beginUpdate(
        String resourceGroupName, String networkDeviceName, NetworkDevicePatchParameters body, Context context) {
        return this.beginUpdateAsync(resourceGroupName, networkDeviceName, body, context).getSyncPoller();
    }

    /**
     * Updates a Network Device.
     *
     * <p>Update certain properties of the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Network Device properties to update.
     * @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 Network Device resource definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<NetworkDeviceInner> updateAsync(
        String resourceGroupName, String networkDeviceName, NetworkDevicePatchParameters body) {
        return beginUpdateAsync(resourceGroupName, networkDeviceName, body)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates a Network Device.
     *
     * <p>Update certain properties of the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Network Device properties to update.
     * @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 Network Device resource definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<NetworkDeviceInner> updateAsync(
        String resourceGroupName, String networkDeviceName, NetworkDevicePatchParameters body, Context context) {
        return beginUpdateAsync(resourceGroupName, networkDeviceName, body, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates a Network Device.
     *
     * <p>Update certain properties of the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Network Device properties to update.
     * @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 Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public NetworkDeviceInner update(
        String resourceGroupName, String networkDeviceName, NetworkDevicePatchParameters body) {
        return updateAsync(resourceGroupName, networkDeviceName, body).block();
    }

    /**
     * Updates a Network Device.
     *
     * <p>Update certain properties of the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Network Device properties to update.
     * @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 Network Device resource definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public NetworkDeviceInner update(
        String resourceGroupName, String networkDeviceName, NetworkDevicePatchParameters body, Context context) {
        return updateAsync(resourceGroupName, networkDeviceName, body, context).block();
    }

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

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

    /**
     * Deletes a Network Device.
     *
     * <p>Delete the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 networkDeviceName) {
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(resourceGroupName, networkDeviceName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Deletes a Network Device.
     *
     * <p>Delete the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 networkDeviceName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(resourceGroupName, networkDeviceName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Deletes a Network Device.
     *
     * <p>Delete the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 networkDeviceName) {
        return this.beginDeleteAsync(resourceGroupName, networkDeviceName).getSyncPoller();
    }

    /**
     * Deletes a Network Device.
     *
     * <p>Delete the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 networkDeviceName, Context context) {
        return this.beginDeleteAsync(resourceGroupName, networkDeviceName, context).getSyncPoller();
    }

    /**
     * Deletes a Network Device.
     *
     * <p>Delete the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 networkDeviceName) {
        return beginDeleteAsync(resourceGroupName, networkDeviceName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a Network Device.
     *
     * <p>Delete the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 networkDeviceName, Context context) {
        return beginDeleteAsync(resourceGroupName, networkDeviceName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a Network Device.
     *
     * <p>Delete the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 networkDeviceName) {
        deleteAsync(resourceGroupName, networkDeviceName).block();
    }

    /**
     * Deletes a Network Device.
     *
     * <p>Delete the Network Device resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 networkDeviceName, Context context) {
        deleteAsync(resourceGroupName, networkDeviceName, context).block();
    }

    /**
     * List NetworkDevices by resource group.
     *
     * <p>List all the Network Device resources in a given resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 list of NetworkDevices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<NetworkDeviceInner>> listByResourceGroupSinglePageAsync(String resourceGroupName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<NetworkDeviceInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List NetworkDevices by resource group.
     *
     * <p>List all the Network Device resources in a given resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 list of NetworkDevices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<NetworkDeviceInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List NetworkDevices by resource group.
     *
     * <p>List all the Network Device resources in a given resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 list of NetworkDevices as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<NetworkDeviceInner> listByResourceGroupAsync(String resourceGroupName) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * List NetworkDevices by resource group.
     *
     * <p>List all the Network Device resources in a given resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 list of NetworkDevices as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<NetworkDeviceInner> listByResourceGroupAsync(String resourceGroupName, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, context),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * List NetworkDevices by resource group.
     *
     * <p>List all the Network Device resources in a given resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 list of NetworkDevices as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<NetworkDeviceInner> listByResourceGroup(String resourceGroupName) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName));
    }

    /**
     * List NetworkDevices by resource group.
     *
     * <p>List all the Network Device resources in a given resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 list of NetworkDevices as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<NetworkDeviceInner> listByResourceGroup(String resourceGroupName, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, context));
    }

    /**
     * List NetworkDevices by subscription.
     *
     * <p>List all the Network Device resources in a given subscription.
     *
     * @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 list of NetworkDevices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<NetworkDeviceInner>> listSinglePageAsync() {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<NetworkDeviceInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List NetworkDevices by subscription.
     *
     * <p>List all the Network Device resources in a given subscription.
     *
     * @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 list of NetworkDevices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<NetworkDeviceInner>> listSinglePageAsync(Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List NetworkDevices by subscription.
     *
     * <p>List all the Network Device resources in a given subscription.
     *
     * @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 list of NetworkDevices as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<NetworkDeviceInner> listAsync() {
        return new PagedFlux<>(
            () -> listSinglePageAsync(), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * List NetworkDevices by subscription.
     *
     * <p>List all the Network Device resources in a given subscription.
     *
     * @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 list of NetworkDevices as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<NetworkDeviceInner> listAsync(Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(context), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * List NetworkDevices by subscription.
     *
     * <p>List all the Network Device resources in a given subscription.
     *
     * @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 list of NetworkDevices as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<NetworkDeviceInner> list() {
        return new PagedIterable<>(listAsync());
    }

    /**
     * List NetworkDevices by subscription.
     *
     * <p>List all the Network Device resources in a given subscription.
     *
     * @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 list of NetworkDevices as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<NetworkDeviceInner> list(Context context) {
        return new PagedIterable<>(listAsync(context));
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Reboot the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> rebootWithResponseAsync(
        String resourceGroupName, String networkDeviceName, RebootProperties body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .reboot(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            networkDeviceName,
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Reboot the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> rebootWithResponseAsync(
        String resourceGroupName, String networkDeviceName, RebootProperties body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .reboot(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                networkDeviceName,
                body,
                accept,
                context);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Reboot the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginRebootAsync(String resourceGroupName, String networkDeviceName, RebootProperties body) {
        Mono<Response<Flux<ByteBuffer>>> mono = rebootWithResponseAsync(resourceGroupName, networkDeviceName, body);
        return this
            .client
            .<CommonPostActionResponseForStateUpdateInner, CommonPostActionResponseForStateUpdateInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommonPostActionResponseForStateUpdateInner.class,
                CommonPostActionResponseForStateUpdateInner.class,
                this.client.getContext());
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Reboot the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginRebootAsync(String resourceGroupName, String networkDeviceName, RebootProperties body, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            rebootWithResponseAsync(resourceGroupName, networkDeviceName, body, context);
        return this
            .client
            .<CommonPostActionResponseForStateUpdateInner, CommonPostActionResponseForStateUpdateInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommonPostActionResponseForStateUpdateInner.class,
                CommonPostActionResponseForStateUpdateInner.class,
                context);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Reboot the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginReboot(String resourceGroupName, String networkDeviceName, RebootProperties body) {
        return this.beginRebootAsync(resourceGroupName, networkDeviceName, body).getSyncPoller();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Reboot the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginReboot(String resourceGroupName, String networkDeviceName, RebootProperties body, Context context) {
        return this.beginRebootAsync(resourceGroupName, networkDeviceName, body, context).getSyncPoller();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Reboot the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommonPostActionResponseForStateUpdateInner> rebootAsync(
        String resourceGroupName, String networkDeviceName, RebootProperties body) {
        return beginRebootAsync(resourceGroupName, networkDeviceName, body)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Reboot the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommonPostActionResponseForStateUpdateInner> rebootAsync(
        String resourceGroupName, String networkDeviceName, RebootProperties body, Context context) {
        return beginRebootAsync(resourceGroupName, networkDeviceName, body, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Reboot the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommonPostActionResponseForStateUpdateInner reboot(
        String resourceGroupName, String networkDeviceName, RebootProperties body) {
        return rebootAsync(resourceGroupName, networkDeviceName, body).block();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Reboot the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommonPostActionResponseForStateUpdateInner reboot(
        String resourceGroupName, String networkDeviceName, RebootProperties body, Context context) {
        return rebootAsync(resourceGroupName, networkDeviceName, body, context).block();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Refreshes the configuration the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 common response for the state updates along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> refreshConfigurationWithResponseAsync(
        String resourceGroupName, String networkDeviceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .refreshConfiguration(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            networkDeviceName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Refreshes the configuration the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 common response for the state updates along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> refreshConfigurationWithResponseAsync(
        String resourceGroupName, String networkDeviceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .refreshConfiguration(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                networkDeviceName,
                accept,
                context);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Refreshes the configuration the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginRefreshConfigurationAsync(String resourceGroupName, String networkDeviceName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            refreshConfigurationWithResponseAsync(resourceGroupName, networkDeviceName);
        return this
            .client
            .<CommonPostActionResponseForStateUpdateInner, CommonPostActionResponseForStateUpdateInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommonPostActionResponseForStateUpdateInner.class,
                CommonPostActionResponseForStateUpdateInner.class,
                this.client.getContext());
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Refreshes the configuration the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginRefreshConfigurationAsync(String resourceGroupName, String networkDeviceName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            refreshConfigurationWithResponseAsync(resourceGroupName, networkDeviceName, context);
        return this
            .client
            .<CommonPostActionResponseForStateUpdateInner, CommonPostActionResponseForStateUpdateInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommonPostActionResponseForStateUpdateInner.class,
                CommonPostActionResponseForStateUpdateInner.class,
                context);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Refreshes the configuration the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginRefreshConfiguration(String resourceGroupName, String networkDeviceName) {
        return this.beginRefreshConfigurationAsync(resourceGroupName, networkDeviceName).getSyncPoller();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Refreshes the configuration the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginRefreshConfiguration(String resourceGroupName, String networkDeviceName, Context context) {
        return this.beginRefreshConfigurationAsync(resourceGroupName, networkDeviceName, context).getSyncPoller();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Refreshes the configuration the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 common response for the state updates on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommonPostActionResponseForStateUpdateInner> refreshConfigurationAsync(
        String resourceGroupName, String networkDeviceName) {
        return beginRefreshConfigurationAsync(resourceGroupName, networkDeviceName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Refreshes the configuration the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 common response for the state updates on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommonPostActionResponseForStateUpdateInner> refreshConfigurationAsync(
        String resourceGroupName, String networkDeviceName, Context context) {
        return beginRefreshConfigurationAsync(resourceGroupName, networkDeviceName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Refreshes the configuration the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommonPostActionResponseForStateUpdateInner refreshConfiguration(
        String resourceGroupName, String networkDeviceName) {
        return refreshConfigurationAsync(resourceGroupName, networkDeviceName).block();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Refreshes the configuration the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommonPostActionResponseForStateUpdateInner refreshConfiguration(
        String resourceGroupName, String networkDeviceName, Context context) {
        return refreshConfigurationAsync(resourceGroupName, networkDeviceName, context).block();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Updates the Administrative state of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateAdministrativeStateWithResponseAsync(
        String resourceGroupName, String networkDeviceName, UpdateDeviceAdministrativeState body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .updateAdministrativeState(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            networkDeviceName,
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Updates the Administrative state of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateAdministrativeStateWithResponseAsync(
        String resourceGroupName, String networkDeviceName, UpdateDeviceAdministrativeState body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .updateAdministrativeState(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                networkDeviceName,
                body,
                accept,
                context);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Updates the Administrative state of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginUpdateAdministrativeStateAsync(
            String resourceGroupName, String networkDeviceName, UpdateDeviceAdministrativeState body) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateAdministrativeStateWithResponseAsync(resourceGroupName, networkDeviceName, body);
        return this
            .client
            .<CommonPostActionResponseForStateUpdateInner, CommonPostActionResponseForStateUpdateInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommonPostActionResponseForStateUpdateInner.class,
                CommonPostActionResponseForStateUpdateInner.class,
                this.client.getContext());
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Updates the Administrative state of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginUpdateAdministrativeStateAsync(
            String resourceGroupName, String networkDeviceName, UpdateDeviceAdministrativeState body, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateAdministrativeStateWithResponseAsync(resourceGroupName, networkDeviceName, body, context);
        return this
            .client
            .<CommonPostActionResponseForStateUpdateInner, CommonPostActionResponseForStateUpdateInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommonPostActionResponseForStateUpdateInner.class,
                CommonPostActionResponseForStateUpdateInner.class,
                context);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Updates the Administrative state of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginUpdateAdministrativeState(
            String resourceGroupName, String networkDeviceName, UpdateDeviceAdministrativeState body) {
        return this.beginUpdateAdministrativeStateAsync(resourceGroupName, networkDeviceName, body).getSyncPoller();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Updates the Administrative state of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginUpdateAdministrativeState(
            String resourceGroupName, String networkDeviceName, UpdateDeviceAdministrativeState body, Context context) {
        return this
            .beginUpdateAdministrativeStateAsync(resourceGroupName, networkDeviceName, body, context)
            .getSyncPoller();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Updates the Administrative state of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommonPostActionResponseForStateUpdateInner> updateAdministrativeStateAsync(
        String resourceGroupName, String networkDeviceName, UpdateDeviceAdministrativeState body) {
        return beginUpdateAdministrativeStateAsync(resourceGroupName, networkDeviceName, body)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Updates the Administrative state of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommonPostActionResponseForStateUpdateInner> updateAdministrativeStateAsync(
        String resourceGroupName, String networkDeviceName, UpdateDeviceAdministrativeState body, Context context) {
        return beginUpdateAdministrativeStateAsync(resourceGroupName, networkDeviceName, body, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Updates the Administrative state of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommonPostActionResponseForStateUpdateInner updateAdministrativeState(
        String resourceGroupName, String networkDeviceName, UpdateDeviceAdministrativeState body) {
        return updateAdministrativeStateAsync(resourceGroupName, networkDeviceName, body).block();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Updates the Administrative state of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommonPostActionResponseForStateUpdateInner updateAdministrativeState(
        String resourceGroupName, String networkDeviceName, UpdateDeviceAdministrativeState body, Context context) {
        return updateAdministrativeStateAsync(resourceGroupName, networkDeviceName, body, context).block();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Upgrades the version of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> upgradeWithResponseAsync(
        String resourceGroupName, String networkDeviceName, UpdateVersion body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .upgrade(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            networkDeviceName,
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Upgrades the version of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> upgradeWithResponseAsync(
        String resourceGroupName, String networkDeviceName, UpdateVersion body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (networkDeviceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter networkDeviceName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .upgrade(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                networkDeviceName,
                body,
                accept,
                context);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Upgrades the version of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginUpgradeAsync(String resourceGroupName, String networkDeviceName, UpdateVersion body) {
        Mono<Response<Flux<ByteBuffer>>> mono = upgradeWithResponseAsync(resourceGroupName, networkDeviceName, body);
        return this
            .client
            .<CommonPostActionResponseForStateUpdateInner, CommonPostActionResponseForStateUpdateInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommonPostActionResponseForStateUpdateInner.class,
                CommonPostActionResponseForStateUpdateInner.class,
                this.client.getContext());
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Upgrades the version of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginUpgradeAsync(String resourceGroupName, String networkDeviceName, UpdateVersion body, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            upgradeWithResponseAsync(resourceGroupName, networkDeviceName, body, context);
        return this
            .client
            .<CommonPostActionResponseForStateUpdateInner, CommonPostActionResponseForStateUpdateInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommonPostActionResponseForStateUpdateInner.class,
                CommonPostActionResponseForStateUpdateInner.class,
                context);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Upgrades the version of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginUpgrade(String resourceGroupName, String networkDeviceName, UpdateVersion body) {
        return this.beginUpgradeAsync(resourceGroupName, networkDeviceName, body).getSyncPoller();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Upgrades the version of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<
            PollResult<CommonPostActionResponseForStateUpdateInner>, CommonPostActionResponseForStateUpdateInner>
        beginUpgrade(String resourceGroupName, String networkDeviceName, UpdateVersion body, Context context) {
        return this.beginUpgradeAsync(resourceGroupName, networkDeviceName, body, context).getSyncPoller();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Upgrades the version of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommonPostActionResponseForStateUpdateInner> upgradeAsync(
        String resourceGroupName, String networkDeviceName, UpdateVersion body) {
        return beginUpgradeAsync(resourceGroupName, networkDeviceName, body)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Upgrades the version of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommonPostActionResponseForStateUpdateInner> upgradeAsync(
        String resourceGroupName, String networkDeviceName, UpdateVersion body, Context context) {
        return beginUpgradeAsync(resourceGroupName, networkDeviceName, body, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Upgrades the version of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommonPostActionResponseForStateUpdateInner upgrade(
        String resourceGroupName, String networkDeviceName, UpdateVersion body) {
        return upgradeAsync(resourceGroupName, networkDeviceName, body).block();
    }

    /**
     * Implements the operation to the underlying resources.
     *
     * <p>Upgrades the version of the Network Device.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param networkDeviceName Name of the Network Device.
     * @param body Request payload.
     * @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 common response for the state updates.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommonPostActionResponseForStateUpdateInner upgrade(
        String resourceGroupName, String networkDeviceName, UpdateVersion body, Context context) {
        return upgradeAsync(resourceGroupName, networkDeviceName, body, context).block();
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of NetworkDevices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<NetworkDeviceInner>> listByResourceGroupNextSinglePageAsync(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.listByResourceGroupNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<NetworkDeviceInner>>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 list of NetworkDevices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<NetworkDeviceInner>> listByResourceGroupNextSinglePageAsync(
        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
            .listByResourceGroupNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

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