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

package com.azure.resourcemanager.networkcloud.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.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.networkcloud.fluent.VirtualMachinesClient;
import com.azure.resourcemanager.networkcloud.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.networkcloud.models.VirtualMachineList;
import com.azure.resourcemanager.networkcloud.models.VirtualMachinePatchParameters;
import com.azure.resourcemanager.networkcloud.models.VirtualMachinePowerOffParameters;
import com.azure.resourcemanager.networkcloud.models.VirtualMachineVolumeParameters;
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 VirtualMachinesClient. */
public final class VirtualMachinesClientImpl implements VirtualMachinesClient {
    /** The proxy service used to perform REST calls. */
    private final VirtualMachinesService service;

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

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

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

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

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

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

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

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/virtualMachines/{virtualMachineName}/attachVolume")
        @ExpectedResponses({202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> attachVolume(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("virtualMachineName") String virtualMachineName,
            @BodyParam("application/json") VirtualMachineVolumeParameters virtualMachineAttachVolumeParameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/virtualMachines/{virtualMachineName}/detachVolume")
        @ExpectedResponses({202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> detachVolume(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("virtualMachineName") String virtualMachineName,
            @BodyParam("application/json") VirtualMachineVolumeParameters virtualMachineDetachVolumeParameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/virtualMachines/{virtualMachineName}/powerOff")
        @ExpectedResponses({202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> powerOff(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("virtualMachineName") String virtualMachineName,
            @BodyParam("application/json") VirtualMachinePowerOffParameters virtualMachinePowerOffParameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

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

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

    /**
     * List virtual machines in the subscription.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided subscription along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> 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.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .<PagedResponse<VirtualMachineInner>>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 virtual machines in the subscription.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided subscription along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> 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.getApiVersion(),
                this.client.getSubscriptionId(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List virtual machines in the subscription.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listAsync() {
        return new PagedFlux<>(
            () -> listSinglePageAsync(), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * List virtual machines in the subscription.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listAsync(Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(context), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * List virtual machines in the subscription.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided subscription as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualMachineInner> list() {
        return new PagedIterable<>(listAsync());
    }

    /**
     * List virtual machines in the subscription.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided subscription as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualMachineInner> list(Context context) {
        return new PagedIterable<>(listAsync(context));
    }

    /**
     * List virtual machines in the resource group.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided resource group along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> 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.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            accept,
                            context))
            .<PagedResponse<VirtualMachineInner>>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 virtual machines in the resource group.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided resource group along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> 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.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List virtual machines in the resource group.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided resource group as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listByResourceGroupAsync(String resourceGroupName) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * List virtual machines in the resource group.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided resource group as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listByResourceGroupAsync(String resourceGroupName, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, context),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * List virtual machines in the resource group.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided resource group as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualMachineInner> listByResourceGroup(String resourceGroupName) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName));
    }

    /**
     * List virtual machines in the resource group.
     *
     * <p>Get a list of virtual machines in the provided 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 a list of virtual machines in the provided resource group as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualMachineInner> listByResourceGroup(String resourceGroupName, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, context));
    }

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

    /**
     * Retrieve the virtual machine.
     *
     * <p>Get properties of the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 properties of the provided virtual machine along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<VirtualMachineInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String virtualMachineName, 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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getByResourceGroup(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualMachineName,
                accept,
                context);
    }

    /**
     * Retrieve the virtual machine.
     *
     * <p>Get properties of the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 properties of the provided virtual machine on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualMachineInner> getByResourceGroupAsync(String resourceGroupName, String virtualMachineName) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, virtualMachineName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Retrieve the virtual machine.
     *
     * <p>Get properties of the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 properties of the provided virtual machine along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<VirtualMachineInner> getByResourceGroupWithResponse(
        String resourceGroupName, String virtualMachineName, Context context) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, virtualMachineName, context).block();
    }

    /**
     * Retrieve the virtual machine.
     *
     * <p>Get properties of the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 properties of the provided virtual machine.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualMachineInner getByResourceGroup(String resourceGroupName, String virtualMachineName) {
        return getByResourceGroupWithResponse(resourceGroupName, virtualMachineName, Context.NONE).getValue();
    }

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

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

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

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

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

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

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

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

    /**
     * Create or update the virtual machine.
     *
     * <p>Create a new virtual machine or update the properties of the existing virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return virtualMachine represents the on-premises Network Cloud virtual machine.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualMachineInner createOrUpdate(
        String resourceGroupName, String virtualMachineName, VirtualMachineInner virtualMachineParameters) {
        return createOrUpdateAsync(resourceGroupName, virtualMachineName, virtualMachineParameters).block();
    }

    /**
     * Create or update the virtual machine.
     *
     * <p>Create a new virtual machine or update the properties of the existing virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return virtualMachine represents the on-premises Network Cloud virtual machine.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualMachineInner createOrUpdate(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineInner virtualMachineParameters,
        Context context) {
        return createOrUpdateAsync(resourceGroupName, virtualMachineName, virtualMachineParameters, context).block();
    }

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

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

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

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

    /**
     * Delete the virtual machine.
     *
     * <p>Delete the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 virtualMachineName) {
        return this.beginDeleteAsync(resourceGroupName, virtualMachineName).getSyncPoller();
    }

    /**
     * Delete the virtual machine.
     *
     * <p>Delete the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 virtualMachineName, Context context) {
        return this.beginDeleteAsync(resourceGroupName, virtualMachineName, context).getSyncPoller();
    }

    /**
     * Delete the virtual machine.
     *
     * <p>Delete the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 virtualMachineName) {
        return beginDeleteAsync(resourceGroupName, virtualMachineName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

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

    /**
     * Delete the virtual machine.
     *
     * <p>Delete the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 virtualMachineName) {
        deleteAsync(resourceGroupName, virtualMachineName).block();
    }

    /**
     * Delete the virtual machine.
     *
     * <p>Delete the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 virtualMachineName, Context context) {
        deleteAsync(resourceGroupName, virtualMachineName, context).block();
    }

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

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

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

    /**
     * Patch the virtual machine.
     *
     * <p>Patch the properties of the provided virtual machine, or update the tags associated with the virtual machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 virtualMachine represents the on-premises Network Cloud virtual
     *     machine.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<VirtualMachineInner>, VirtualMachineInner> beginUpdateAsync(
        String resourceGroupName, String virtualMachineName) {
        final VirtualMachinePatchParameters virtualMachineUpdateParameters = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, virtualMachineName, virtualMachineUpdateParameters);
        return this
            .client
            .<VirtualMachineInner, VirtualMachineInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                VirtualMachineInner.class,
                VirtualMachineInner.class,
                this.client.getContext());
    }

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

    /**
     * Patch the virtual machine.
     *
     * <p>Patch the properties of the provided virtual machine, or update the tags associated with the virtual machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 virtualMachine represents the on-premises Network Cloud virtual
     *     machine.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<VirtualMachineInner>, VirtualMachineInner> beginUpdate(
        String resourceGroupName, String virtualMachineName) {
        final VirtualMachinePatchParameters virtualMachineUpdateParameters = null;
        return this
            .beginUpdateAsync(resourceGroupName, virtualMachineName, virtualMachineUpdateParameters)
            .getSyncPoller();
    }

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

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

    /**
     * Patch the virtual machine.
     *
     * <p>Patch the properties of the provided virtual machine, or update the tags associated with the virtual machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 virtualMachine represents the on-premises Network Cloud virtual machine on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualMachineInner> updateAsync(String resourceGroupName, String virtualMachineName) {
        final VirtualMachinePatchParameters virtualMachineUpdateParameters = null;
        return beginUpdateAsync(resourceGroupName, virtualMachineName, virtualMachineUpdateParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

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

    /**
     * Patch the virtual machine.
     *
     * <p>Patch the properties of the provided virtual machine, or update the tags associated with the virtual machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 virtualMachine represents the on-premises Network Cloud virtual machine.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualMachineInner update(String resourceGroupName, String virtualMachineName) {
        final VirtualMachinePatchParameters virtualMachineUpdateParameters = null;
        return updateAsync(resourceGroupName, virtualMachineName, virtualMachineUpdateParameters).block();
    }

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

    /**
     * Attach volume to the virtual machine.
     *
     * <p>Attach volume to the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineAttachVolumeParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> attachVolumeWithResponseAsync(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineAttachVolumeParameters) {
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (virtualMachineAttachVolumeParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter virtualMachineAttachVolumeParameters is required and cannot be null."));
        } else {
            virtualMachineAttachVolumeParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .attachVolume(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualMachineName,
                            virtualMachineAttachVolumeParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Attach volume to the virtual machine.
     *
     * <p>Attach volume to the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineAttachVolumeParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> attachVolumeWithResponseAsync(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineAttachVolumeParameters,
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (virtualMachineAttachVolumeParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter virtualMachineAttachVolumeParameters is required and cannot be null."));
        } else {
            virtualMachineAttachVolumeParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .attachVolume(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualMachineName,
                virtualMachineAttachVolumeParameters,
                accept,
                context);
    }

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

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

    /**
     * Attach volume to the virtual machine.
     *
     * <p>Attach volume to the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineAttachVolumeParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginAttachVolume(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineAttachVolumeParameters) {
        return this
            .beginAttachVolumeAsync(resourceGroupName, virtualMachineName, virtualMachineAttachVolumeParameters)
            .getSyncPoller();
    }

    /**
     * Attach volume to the virtual machine.
     *
     * <p>Attach volume to the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineAttachVolumeParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginAttachVolume(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineAttachVolumeParameters,
        Context context) {
        return this
            .beginAttachVolumeAsync(
                resourceGroupName, virtualMachineName, virtualMachineAttachVolumeParameters, context)
            .getSyncPoller();
    }

    /**
     * Attach volume to the virtual machine.
     *
     * <p>Attach volume to the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineAttachVolumeParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> attachVolumeAsync(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineAttachVolumeParameters) {
        return beginAttachVolumeAsync(resourceGroupName, virtualMachineName, virtualMachineAttachVolumeParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

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

    /**
     * Attach volume to the virtual machine.
     *
     * <p>Attach volume to the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineAttachVolumeParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void attachVolume(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineAttachVolumeParameters) {
        attachVolumeAsync(resourceGroupName, virtualMachineName, virtualMachineAttachVolumeParameters).block();
    }

    /**
     * Attach volume to the virtual machine.
     *
     * <p>Attach volume to the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineAttachVolumeParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void attachVolume(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineAttachVolumeParameters,
        Context context) {
        attachVolumeAsync(resourceGroupName, virtualMachineName, virtualMachineAttachVolumeParameters, context).block();
    }

    /**
     * Detach volume from the virtual machine.
     *
     * <p>Detach volume from the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineDetachVolumeParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> detachVolumeWithResponseAsync(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineDetachVolumeParameters) {
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (virtualMachineDetachVolumeParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter virtualMachineDetachVolumeParameters is required and cannot be null."));
        } else {
            virtualMachineDetachVolumeParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .detachVolume(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualMachineName,
                            virtualMachineDetachVolumeParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Detach volume from the virtual machine.
     *
     * <p>Detach volume from the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineDetachVolumeParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> detachVolumeWithResponseAsync(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineDetachVolumeParameters,
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (virtualMachineDetachVolumeParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter virtualMachineDetachVolumeParameters is required and cannot be null."));
        } else {
            virtualMachineDetachVolumeParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .detachVolume(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualMachineName,
                virtualMachineDetachVolumeParameters,
                accept,
                context);
    }

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

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

    /**
     * Detach volume from the virtual machine.
     *
     * <p>Detach volume from the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineDetachVolumeParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDetachVolume(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineDetachVolumeParameters) {
        return this
            .beginDetachVolumeAsync(resourceGroupName, virtualMachineName, virtualMachineDetachVolumeParameters)
            .getSyncPoller();
    }

    /**
     * Detach volume from the virtual machine.
     *
     * <p>Detach volume from the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineDetachVolumeParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDetachVolume(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineDetachVolumeParameters,
        Context context) {
        return this
            .beginDetachVolumeAsync(
                resourceGroupName, virtualMachineName, virtualMachineDetachVolumeParameters, context)
            .getSyncPoller();
    }

    /**
     * Detach volume from the virtual machine.
     *
     * <p>Detach volume from the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineDetachVolumeParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> detachVolumeAsync(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineDetachVolumeParameters) {
        return beginDetachVolumeAsync(resourceGroupName, virtualMachineName, virtualMachineDetachVolumeParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Detach volume from the virtual machine.
     *
     * <p>Detach volume from the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineDetachVolumeParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> detachVolumeAsync(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineDetachVolumeParameters,
        Context context) {
        return beginDetachVolumeAsync(
                resourceGroupName, virtualMachineName, virtualMachineDetachVolumeParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Detach volume from the virtual machine.
     *
     * <p>Detach volume from the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineDetachVolumeParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void detachVolume(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineDetachVolumeParameters) {
        detachVolumeAsync(resourceGroupName, virtualMachineName, virtualMachineDetachVolumeParameters).block();
    }

    /**
     * Detach volume from the virtual machine.
     *
     * <p>Detach volume from the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachineDetachVolumeParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void detachVolume(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachineVolumeParameters virtualMachineDetachVolumeParameters,
        Context context) {
        detachVolumeAsync(resourceGroupName, virtualMachineName, virtualMachineDetachVolumeParameters, context).block();
    }

    /**
     * Power off the virtual machine.
     *
     * <p>Power off the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachinePowerOffParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> powerOffWithResponseAsync(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachinePowerOffParameters virtualMachinePowerOffParameters) {
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (virtualMachinePowerOffParameters != null) {
            virtualMachinePowerOffParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .powerOff(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualMachineName,
                            virtualMachinePowerOffParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Power off the virtual machine.
     *
     * <p>Power off the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachinePowerOffParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> powerOffWithResponseAsync(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachinePowerOffParameters virtualMachinePowerOffParameters,
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (virtualMachinePowerOffParameters != null) {
            virtualMachinePowerOffParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .powerOff(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualMachineName,
                virtualMachinePowerOffParameters,
                accept,
                context);
    }

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

    /**
     * Power off the virtual machine.
     *
     * <p>Power off the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginPowerOffAsync(String resourceGroupName, String virtualMachineName) {
        final VirtualMachinePowerOffParameters virtualMachinePowerOffParameters = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            powerOffWithResponseAsync(resourceGroupName, virtualMachineName, virtualMachinePowerOffParameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

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

    /**
     * Power off the virtual machine.
     *
     * <p>Power off the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginPowerOff(String resourceGroupName, String virtualMachineName) {
        final VirtualMachinePowerOffParameters virtualMachinePowerOffParameters = null;
        return this
            .beginPowerOffAsync(resourceGroupName, virtualMachineName, virtualMachinePowerOffParameters)
            .getSyncPoller();
    }

    /**
     * Power off the virtual machine.
     *
     * <p>Power off the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachinePowerOffParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginPowerOff(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachinePowerOffParameters virtualMachinePowerOffParameters,
        Context context) {
        return this
            .beginPowerOffAsync(resourceGroupName, virtualMachineName, virtualMachinePowerOffParameters, context)
            .getSyncPoller();
    }

    /**
     * Power off the virtual machine.
     *
     * <p>Power off the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachinePowerOffParameters The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> powerOffAsync(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachinePowerOffParameters virtualMachinePowerOffParameters) {
        return beginPowerOffAsync(resourceGroupName, virtualMachineName, virtualMachinePowerOffParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Power off the virtual machine.
     *
     * <p>Power off the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> powerOffAsync(String resourceGroupName, String virtualMachineName) {
        final VirtualMachinePowerOffParameters virtualMachinePowerOffParameters = null;
        return beginPowerOffAsync(resourceGroupName, virtualMachineName, virtualMachinePowerOffParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

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

    /**
     * Power off the virtual machine.
     *
     * <p>Power off the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 powerOff(String resourceGroupName, String virtualMachineName) {
        final VirtualMachinePowerOffParameters virtualMachinePowerOffParameters = null;
        powerOffAsync(resourceGroupName, virtualMachineName, virtualMachinePowerOffParameters).block();
    }

    /**
     * Power off the virtual machine.
     *
     * <p>Power off the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param virtualMachinePowerOffParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void powerOff(
        String resourceGroupName,
        String virtualMachineName,
        VirtualMachinePowerOffParameters virtualMachinePowerOffParameters,
        Context context) {
        powerOffAsync(resourceGroupName, virtualMachineName, virtualMachinePowerOffParameters, context).block();
    }

    /**
     * Reimage the virtual machine.
     *
     * <p>Reimage the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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>>> reimageWithResponseAsync(
        String resourceGroupName, String virtualMachineName) {
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .reimage(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualMachineName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Reimage the virtual machine.
     *
     * <p>Reimage the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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>>> reimageWithResponseAsync(
        String resourceGroupName, String virtualMachineName, 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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .reimage(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualMachineName,
                accept,
                context);
    }

    /**
     * Reimage the virtual machine.
     *
     * <p>Reimage the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginReimageAsync(String resourceGroupName, String virtualMachineName) {
        Mono<Response<Flux<ByteBuffer>>> mono = reimageWithResponseAsync(resourceGroupName, virtualMachineName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Reimage the virtual machine.
     *
     * <p>Reimage the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginReimageAsync(
        String resourceGroupName, String virtualMachineName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            reimageWithResponseAsync(resourceGroupName, virtualMachineName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Reimage the virtual machine.
     *
     * <p>Reimage the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginReimage(String resourceGroupName, String virtualMachineName) {
        return this.beginReimageAsync(resourceGroupName, virtualMachineName).getSyncPoller();
    }

    /**
     * Reimage the virtual machine.
     *
     * <p>Reimage the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginReimage(
        String resourceGroupName, String virtualMachineName, Context context) {
        return this.beginReimageAsync(resourceGroupName, virtualMachineName, context).getSyncPoller();
    }

    /**
     * Reimage the virtual machine.
     *
     * <p>Reimage the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> reimageAsync(String resourceGroupName, String virtualMachineName) {
        return beginReimageAsync(resourceGroupName, virtualMachineName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Reimage the virtual machine.
     *
     * <p>Reimage the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> reimageAsync(String resourceGroupName, String virtualMachineName, Context context) {
        return beginReimageAsync(resourceGroupName, virtualMachineName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Reimage the virtual machine.
     *
     * <p>Reimage the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 reimage(String resourceGroupName, String virtualMachineName) {
        reimageAsync(resourceGroupName, virtualMachineName).block();
    }

    /**
     * Reimage the virtual machine.
     *
     * <p>Reimage the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 reimage(String resourceGroupName, String virtualMachineName, Context context) {
        reimageAsync(resourceGroupName, virtualMachineName, context).block();
    }

    /**
     * Restart the virtual machine.
     *
     * <p>Restart the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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>>> restartWithResponseAsync(
        String resourceGroupName, String virtualMachineName) {
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .restart(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualMachineName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Restart the virtual machine.
     *
     * <p>Restart the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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>>> restartWithResponseAsync(
        String resourceGroupName, String virtualMachineName, 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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .restart(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualMachineName,
                accept,
                context);
    }

    /**
     * Restart the virtual machine.
     *
     * <p>Restart the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginRestartAsync(String resourceGroupName, String virtualMachineName) {
        Mono<Response<Flux<ByteBuffer>>> mono = restartWithResponseAsync(resourceGroupName, virtualMachineName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Restart the virtual machine.
     *
     * <p>Restart the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginRestartAsync(
        String resourceGroupName, String virtualMachineName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            restartWithResponseAsync(resourceGroupName, virtualMachineName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Restart the virtual machine.
     *
     * <p>Restart the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginRestart(String resourceGroupName, String virtualMachineName) {
        return this.beginRestartAsync(resourceGroupName, virtualMachineName).getSyncPoller();
    }

    /**
     * Restart the virtual machine.
     *
     * <p>Restart the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginRestart(
        String resourceGroupName, String virtualMachineName, Context context) {
        return this.beginRestartAsync(resourceGroupName, virtualMachineName, context).getSyncPoller();
    }

    /**
     * Restart the virtual machine.
     *
     * <p>Restart the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> restartAsync(String resourceGroupName, String virtualMachineName) {
        return beginRestartAsync(resourceGroupName, virtualMachineName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Restart the virtual machine.
     *
     * <p>Restart the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> restartAsync(String resourceGroupName, String virtualMachineName, Context context) {
        return beginRestartAsync(resourceGroupName, virtualMachineName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Restart the virtual machine.
     *
     * <p>Restart the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 restart(String resourceGroupName, String virtualMachineName) {
        restartAsync(resourceGroupName, virtualMachineName).block();
    }

    /**
     * Restart the virtual machine.
     *
     * <p>Restart the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 restart(String resourceGroupName, String virtualMachineName, Context context) {
        restartAsync(resourceGroupName, virtualMachineName, context).block();
    }

    /**
     * Start the virtual machine.
     *
     * <p>Start the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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>>> startWithResponseAsync(
        String resourceGroupName, String virtualMachineName) {
        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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .start(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualMachineName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Start the virtual machine.
     *
     * <p>Start the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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>>> startWithResponseAsync(
        String resourceGroupName, String virtualMachineName, 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 (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .start(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualMachineName,
                accept,
                context);
    }

    /**
     * Start the virtual machine.
     *
     * <p>Start the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginStartAsync(String resourceGroupName, String virtualMachineName) {
        Mono<Response<Flux<ByteBuffer>>> mono = startWithResponseAsync(resourceGroupName, virtualMachineName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Start the virtual machine.
     *
     * <p>Start the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginStartAsync(
        String resourceGroupName, String virtualMachineName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = startWithResponseAsync(resourceGroupName, virtualMachineName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Start the virtual machine.
     *
     * <p>Start the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginStart(String resourceGroupName, String virtualMachineName) {
        return this.beginStartAsync(resourceGroupName, virtualMachineName).getSyncPoller();
    }

    /**
     * Start the virtual machine.
     *
     * <p>Start the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> beginStart(
        String resourceGroupName, String virtualMachineName, Context context) {
        return this.beginStartAsync(resourceGroupName, virtualMachineName, context).getSyncPoller();
    }

    /**
     * Start the virtual machine.
     *
     * <p>Start the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> startAsync(String resourceGroupName, String virtualMachineName) {
        return beginStartAsync(resourceGroupName, virtualMachineName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Start the virtual machine.
     *
     * <p>Start the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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> startAsync(String resourceGroupName, String virtualMachineName, Context context) {
        return beginStartAsync(resourceGroupName, virtualMachineName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Start the virtual machine.
     *
     * <p>Start the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 start(String resourceGroupName, String virtualMachineName) {
        startAsync(resourceGroupName, virtualMachineName).block();
    }

    /**
     * Start the virtual machine.
     *
     * <p>Start the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @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 start(String resourceGroupName, String virtualMachineName, Context context) {
        startAsync(resourceGroupName, virtualMachineName, 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 virtualMachineList represents a list of virtual machines along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> 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<VirtualMachineInner>>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 virtualMachineList represents a list of virtual machines along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> 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));
    }

    /**
     * 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 virtualMachineList represents a list of virtual machines along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> 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<VirtualMachineInner>>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 virtualMachineList represents a list of virtual machines along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> 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));
    }
}
