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

package com.azure.resourcemanager.vmwarecloudsimple.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.vmwarecloudsimple.fluent.VirtualMachinesClient;
import com.azure.resourcemanager.vmwarecloudsimple.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.vmwarecloudsimple.models.PatchPayload;
import com.azure.resourcemanager.vmwarecloudsimple.models.StopMode;
import com.azure.resourcemanager.vmwarecloudsimple.models.VirtualMachineListResponse;
import com.azure.resourcemanager.vmwarecloudsimple.models.VirtualMachineStopMode;
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 VMwareCloudSimpleImpl client;

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

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

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

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

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

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

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

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.VMwareCloudSimple"
                + "/virtualMachines/{virtualMachineName}/stop")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> stop(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @HeaderParam("Referer") String referer,
            @PathParam("virtualMachineName") String virtualMachineName,
            @QueryParam("mode") StopMode mode,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") VirtualMachineStopMode m,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Implements list virtual machine within subscription method
     *
     * <p>Returns list virtual machine within subscription.
     *
     * @param filter The filter to apply on the list operation.
     * @param top The maximum number of record sets to return.
     * @param skipToken to be used by nextLink implementation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> listSinglePageAsync(String filter, Integer top, String skipToken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            filter,
                            top,
                            skipToken,
                            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()));
    }

    /**
     * Implements list virtual machine within subscription method
     *
     * <p>Returns list virtual machine within subscription.
     *
     * @param filter The filter to apply on the list operation.
     * @param top The maximum number of record sets to return.
     * @param skipToken to be used by nextLink implementation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> listSinglePageAsync(
        String filter, Integer top, String skipToken, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                filter,
                top,
                skipToken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Implements list virtual machine within subscription method
     *
     * <p>Returns list virtual machine within subscription.
     *
     * @param filter The filter to apply on the list operation.
     * @param top The maximum number of record sets to return.
     * @param skipToken to be used by nextLink implementation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listAsync(String filter, Integer top, String skipToken) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(filter, top, skipToken),
            nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Implements list virtual machine within subscription method
     *
     * <p>Returns list virtual machine within subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listAsync() {
        final String filter = null;
        final Integer top = null;
        final String skipToken = null;
        return new PagedFlux<>(
            () -> listSinglePageAsync(filter, top, skipToken),
            nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Implements list virtual machine within subscription method
     *
     * <p>Returns list virtual machine within subscription.
     *
     * @param filter The filter to apply on the list operation.
     * @param top The maximum number of record sets to return.
     * @param skipToken to be used by nextLink implementation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listAsync(String filter, Integer top, String skipToken, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(filter, top, skipToken, context),
            nextLink -> listBySubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * Implements list virtual machine within subscription method
     *
     * <p>Returns list virtual machine within subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualMachineInner> list() {
        final String filter = null;
        final Integer top = null;
        final String skipToken = null;
        return new PagedIterable<>(listAsync(filter, top, skipToken));
    }

    /**
     * Implements list virtual machine within subscription method
     *
     * <p>Returns list virtual machine within subscription.
     *
     * @param filter The filter to apply on the list operation.
     * @param top The maximum number of record sets to return.
     * @param skipToken to be used by nextLink implementation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualMachineInner> list(String filter, Integer top, String skipToken, Context context) {
        return new PagedIterable<>(listAsync(filter, top, skipToken, context));
    }

    /**
     * Implements list virtual machine within RG method
     *
     * <p>Returns list of virtual machine within resource group.
     *
     * @param resourceGroupName The name of the resource group.
     * @param filter The filter to apply on the list operation.
     * @param top The maximum number of record sets to return.
     * @param skipToken to be used by nextLink implementation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, String filter, Integer top, String skipToken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            filter,
                            top,
                            skipToken,
                            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()));
    }

    /**
     * Implements list virtual machine within RG method
     *
     * <p>Returns list of virtual machine within resource group.
     *
     * @param resourceGroupName The name of the resource group.
     * @param filter The filter to apply on the list operation.
     * @param top The maximum number of record sets to return.
     * @param skipToken to be used by nextLink implementation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, String filter, Integer top, String skipToken, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                filter,
                top,
                skipToken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Implements list virtual machine within RG method
     *
     * <p>Returns list of virtual machine within resource group.
     *
     * @param resourceGroupName The name of the resource group.
     * @param filter The filter to apply on the list operation.
     * @param top The maximum number of record sets to return.
     * @param skipToken to be used by nextLink implementation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listByResourceGroupAsync(
        String resourceGroupName, String filter, Integer top, String skipToken) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, filter, top, skipToken),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Implements list virtual machine within RG method
     *
     * <p>Returns list of virtual machine within resource group.
     *
     * @param resourceGroupName The name of the resource group.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listByResourceGroupAsync(String resourceGroupName) {
        final String filter = null;
        final Integer top = null;
        final String skipToken = null;
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, filter, top, skipToken),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Implements list virtual machine within RG method
     *
     * <p>Returns list of virtual machine within resource group.
     *
     * @param resourceGroupName The name of the resource group.
     * @param filter The filter to apply on the list operation.
     * @param top The maximum number of record sets to return.
     * @param skipToken to be used by nextLink implementation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listByResourceGroupAsync(
        String resourceGroupName, String filter, Integer top, String skipToken, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, filter, top, skipToken, context),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * Implements list virtual machine within RG method
     *
     * <p>Returns list of virtual machine within resource group.
     *
     * @param resourceGroupName The name of the resource group.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualMachineInner> listByResourceGroup(String resourceGroupName) {
        final String filter = null;
        final Integer top = null;
        final String skipToken = null;
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, filter, top, skipToken));
    }

    /**
     * Implements list virtual machine within RG method
     *
     * <p>Returns list of virtual machine within resource group.
     *
     * @param resourceGroupName The name of the resource group.
     * @param filter The filter to apply on the list operation.
     * @param top The maximum number of record sets to return.
     * @param skipToken to be used by nextLink implementation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of virtual machines as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualMachineInner> listByResourceGroup(
        String resourceGroupName, String filter, Integer top, String skipToken, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, filter, top, skipToken, context));
    }

    /**
     * Implements virtual machine GET method
     *
     * <p>Get virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return 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.getSubscriptionId(),
                            resourceGroupName,
                            virtualMachineName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Implements virtual machine GET method
     *
     * <p>Get virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return 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.getSubscriptionId(),
                resourceGroupName,
                virtualMachineName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Implements virtual machine GET method
     *
     * <p>Get virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return 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()));
    }

    /**
     * Implements virtual machine GET method
     *
     * <p>Get virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return 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();
    }

    /**
     * Implements virtual machine GET method
     *
     * <p>Get virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return virtual machine.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualMachineInner getByResourceGroup(String resourceGroupName, String virtualMachineName) {
        return getByResourceGroupWithResponse(resourceGroupName, virtualMachineName, Context.NONE).getValue();
    }

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

    /**
     * Implements virtual machine PUT method
     *
     * <p>Create Or Update Virtual Machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Create or Update Virtual Machine request.
     * @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 virtual machine model along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        VirtualMachineInner virtualMachineRequest,
        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 (referer == null) {
            return Mono.error(new IllegalArgumentException("Parameter referer is required and cannot be null."));
        }
        if (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (virtualMachineRequest == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineRequest is required and cannot be null."));
        } else {
            virtualMachineRequest.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                referer,
                virtualMachineName,
                this.client.getApiVersion(),
                virtualMachineRequest,
                accept,
                context);
    }

    /**
     * Implements virtual machine PUT method
     *
     * <p>Create Or Update Virtual Machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Create or Update Virtual Machine request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<VirtualMachineInner>, VirtualMachineInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        VirtualMachineInner virtualMachineRequest) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, referer, virtualMachineName, virtualMachineRequest);
        return this
            .client
            .<VirtualMachineInner, VirtualMachineInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                VirtualMachineInner.class,
                VirtualMachineInner.class,
                this.client.getContext());
    }

    /**
     * Implements virtual machine PUT method
     *
     * <p>Create Or Update Virtual Machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Create or Update Virtual Machine request.
     * @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 virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<VirtualMachineInner>, VirtualMachineInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        VirtualMachineInner virtualMachineRequest,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, referer, virtualMachineName, virtualMachineRequest, context);
        return this
            .client
            .<VirtualMachineInner, VirtualMachineInner>getLroResult(
                mono, this.client.getHttpPipeline(), VirtualMachineInner.class, VirtualMachineInner.class, context);
    }

    /**
     * Implements virtual machine PUT method
     *
     * <p>Create Or Update Virtual Machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Create or Update Virtual Machine request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<VirtualMachineInner>, VirtualMachineInner> beginCreateOrUpdate(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        VirtualMachineInner virtualMachineRequest) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, referer, virtualMachineName, virtualMachineRequest)
            .getSyncPoller();
    }

    /**
     * Implements virtual machine PUT method
     *
     * <p>Create Or Update Virtual Machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Create or Update Virtual Machine request.
     * @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 virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<VirtualMachineInner>, VirtualMachineInner> beginCreateOrUpdate(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        VirtualMachineInner virtualMachineRequest,
        Context context) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, referer, virtualMachineName, virtualMachineRequest, context)
            .getSyncPoller();
    }

    /**
     * Implements virtual machine PUT method
     *
     * <p>Create Or Update Virtual Machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Create or Update Virtual Machine request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return virtual machine model on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualMachineInner> createOrUpdateAsync(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        VirtualMachineInner virtualMachineRequest) {
        return beginCreateOrUpdateAsync(resourceGroupName, referer, virtualMachineName, virtualMachineRequest)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements virtual machine PUT method
     *
     * <p>Create Or Update Virtual Machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Create or Update Virtual Machine request.
     * @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 virtual machine model on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualMachineInner> createOrUpdateAsync(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        VirtualMachineInner virtualMachineRequest,
        Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, referer, virtualMachineName, virtualMachineRequest, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements virtual machine PUT method
     *
     * <p>Create Or Update Virtual Machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Create or Update Virtual Machine request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualMachineInner createOrUpdate(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        VirtualMachineInner virtualMachineRequest) {
        return createOrUpdateAsync(resourceGroupName, referer, virtualMachineName, virtualMachineRequest).block();
    }

    /**
     * Implements virtual machine PUT method
     *
     * <p>Create Or Update Virtual Machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Create or Update Virtual Machine request.
     * @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 virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualMachineInner createOrUpdate(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        VirtualMachineInner virtualMachineRequest,
        Context context) {
        return createOrUpdateAsync(resourceGroupName, referer, virtualMachineName, virtualMachineRequest, context)
            .block();
    }

    /**
     * Implements virtual machine DELETE method
     *
     * <p>Delete virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String referer, 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 (referer == null) {
            return Mono.error(new IllegalArgumentException("Parameter referer 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.getSubscriptionId(),
                            resourceGroupName,
                            referer,
                            virtualMachineName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Implements virtual machine DELETE method
     *
     * <p>Delete virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String referer, 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 (referer == null) {
            return Mono.error(new IllegalArgumentException("Parameter referer 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.getSubscriptionId(),
                resourceGroupName,
                referer,
                virtualMachineName,
                this.client.getApiVersion(),
                accept,
                context);
    }

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

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

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

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

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

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

    /**
     * Implements virtual machine DELETE method
     *
     * <p>Delete virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String referer, String virtualMachineName) {
        deleteAsync(resourceGroupName, referer, virtualMachineName).block();
    }

    /**
     * Implements virtual machine DELETE method
     *
     * <p>Delete virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String referer, String virtualMachineName, Context context) {
        deleteAsync(resourceGroupName, referer, virtualMachineName, context).block();
    }

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

    /**
     * Implements virtual machine PATCH method
     *
     * <p>Patch virtual machine properties.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Patch virtual machine request.
     * @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 virtual machine model along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName, String virtualMachineName, PatchPayload virtualMachineRequest, 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 (virtualMachineRequest == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineRequest is required and cannot be null."));
        } else {
            virtualMachineRequest.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualMachineName,
                this.client.getApiVersion(),
                virtualMachineRequest,
                accept,
                context);
    }

    /**
     * Implements virtual machine PATCH method
     *
     * <p>Patch virtual machine properties.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Patch virtual machine request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<VirtualMachineInner>, VirtualMachineInner> beginUpdateAsync(
        String resourceGroupName, String virtualMachineName, PatchPayload virtualMachineRequest) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, virtualMachineName, virtualMachineRequest);
        return this
            .client
            .<VirtualMachineInner, VirtualMachineInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                VirtualMachineInner.class,
                VirtualMachineInner.class,
                this.client.getContext());
    }

    /**
     * Implements virtual machine PATCH method
     *
     * <p>Patch virtual machine properties.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Patch virtual machine request.
     * @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 virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<VirtualMachineInner>, VirtualMachineInner> beginUpdateAsync(
        String resourceGroupName, String virtualMachineName, PatchPayload virtualMachineRequest, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, virtualMachineName, virtualMachineRequest, context);
        return this
            .client
            .<VirtualMachineInner, VirtualMachineInner>getLroResult(
                mono, this.client.getHttpPipeline(), VirtualMachineInner.class, VirtualMachineInner.class, context);
    }

    /**
     * Implements virtual machine PATCH method
     *
     * <p>Patch virtual machine properties.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Patch virtual machine request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<VirtualMachineInner>, VirtualMachineInner> beginUpdate(
        String resourceGroupName, String virtualMachineName, PatchPayload virtualMachineRequest) {
        return this.beginUpdateAsync(resourceGroupName, virtualMachineName, virtualMachineRequest).getSyncPoller();
    }

    /**
     * Implements virtual machine PATCH method
     *
     * <p>Patch virtual machine properties.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Patch virtual machine request.
     * @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 virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<VirtualMachineInner>, VirtualMachineInner> beginUpdate(
        String resourceGroupName, String virtualMachineName, PatchPayload virtualMachineRequest, Context context) {
        return this
            .beginUpdateAsync(resourceGroupName, virtualMachineName, virtualMachineRequest, context)
            .getSyncPoller();
    }

    /**
     * Implements virtual machine PATCH method
     *
     * <p>Patch virtual machine properties.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Patch virtual machine request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return virtual machine model on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualMachineInner> updateAsync(
        String resourceGroupName, String virtualMachineName, PatchPayload virtualMachineRequest) {
        return beginUpdateAsync(resourceGroupName, virtualMachineName, virtualMachineRequest)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements virtual machine PATCH method
     *
     * <p>Patch virtual machine properties.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Patch virtual machine request.
     * @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 virtual machine model on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualMachineInner> updateAsync(
        String resourceGroupName, String virtualMachineName, PatchPayload virtualMachineRequest, Context context) {
        return beginUpdateAsync(resourceGroupName, virtualMachineName, virtualMachineRequest, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements virtual machine PATCH method
     *
     * <p>Patch virtual machine properties.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Patch virtual machine request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualMachineInner update(
        String resourceGroupName, String virtualMachineName, PatchPayload virtualMachineRequest) {
        return updateAsync(resourceGroupName, virtualMachineName, virtualMachineRequest).block();
    }

    /**
     * Implements virtual machine PATCH method
     *
     * <p>Patch virtual machine properties.
     *
     * @param resourceGroupName The name of the resource group.
     * @param virtualMachineName virtual machine name.
     * @param virtualMachineRequest Patch virtual machine request.
     * @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 virtual machine model.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualMachineInner update(
        String resourceGroupName, String virtualMachineName, PatchPayload virtualMachineRequest, Context context) {
        return updateAsync(resourceGroupName, virtualMachineName, virtualMachineRequest, context).block();
    }

    /**
     * Implements a start method for a virtual machine
     *
     * <p>Power on virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> startWithResponseAsync(
        String resourceGroupName, String referer, 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 (referer == null) {
            return Mono.error(new IllegalArgumentException("Parameter referer 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.getSubscriptionId(),
                            resourceGroupName,
                            referer,
                            virtualMachineName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Implements a start method for a virtual machine
     *
     * <p>Power on virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> startWithResponseAsync(
        String resourceGroupName, String referer, 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 (referer == null) {
            return Mono.error(new IllegalArgumentException("Parameter referer 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.getSubscriptionId(),
                resourceGroupName,
                referer,
                virtualMachineName,
                this.client.getApiVersion(),
                accept,
                context);
    }

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

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

    /**
     * Implements a start method for a virtual machine
     *
     * <p>Power on virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginStart(
        String resourceGroupName, String referer, String virtualMachineName) {
        return this.beginStartAsync(resourceGroupName, referer, virtualMachineName).getSyncPoller();
    }

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

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

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

    /**
     * Implements a start method for a virtual machine
     *
     * <p>Power on virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void start(String resourceGroupName, String referer, String virtualMachineName) {
        startAsync(resourceGroupName, referer, virtualMachineName).block();
    }

    /**
     * Implements a start method for a virtual machine
     *
     * <p>Power on virtual machine.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void start(String resourceGroupName, String referer, String virtualMachineName, Context context) {
        startAsync(resourceGroupName, referer, virtualMachineName, context).block();
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param mode query stop mode parameter (reboot, shutdown, etc...).
     * @param m body stop mode parameter (reboot, shutdown, etc...).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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>>> stopWithResponseAsync(
        String resourceGroupName, String referer, String virtualMachineName, StopMode mode, VirtualMachineStopMode m) {
        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 (referer == null) {
            return Mono.error(new IllegalArgumentException("Parameter referer is required and cannot be null."));
        }
        if (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (m != null) {
            m.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .stop(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            referer,
                            virtualMachineName,
                            mode,
                            this.client.getApiVersion(),
                            m,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param mode query stop mode parameter (reboot, shutdown, etc...).
     * @param m body stop mode parameter (reboot, shutdown, etc...).
     * @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>>> stopWithResponseAsync(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        StopMode mode,
        VirtualMachineStopMode m,
        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 (referer == null) {
            return Mono.error(new IllegalArgumentException("Parameter referer is required and cannot be null."));
        }
        if (virtualMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineName is required and cannot be null."));
        }
        if (m != null) {
            m.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .stop(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                referer,
                virtualMachineName,
                mode,
                this.client.getApiVersion(),
                m,
                accept,
                context);
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param mode query stop mode parameter (reboot, shutdown, etc...).
     * @param m body stop mode parameter (reboot, shutdown, etc...).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> beginStopAsync(
        String resourceGroupName, String referer, String virtualMachineName, StopMode mode, VirtualMachineStopMode m) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            stopWithResponseAsync(resourceGroupName, referer, virtualMachineName, mode, m);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginStopAsync(
        String resourceGroupName, String referer, String virtualMachineName) {
        final StopMode mode = null;
        final VirtualMachineStopMode m = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            stopWithResponseAsync(resourceGroupName, referer, virtualMachineName, mode, m);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param mode query stop mode parameter (reboot, shutdown, etc...).
     * @param m body stop mode parameter (reboot, shutdown, etc...).
     * @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> beginStopAsync(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        StopMode mode,
        VirtualMachineStopMode m,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            stopWithResponseAsync(resourceGroupName, referer, virtualMachineName, mode, m, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginStop(
        String resourceGroupName, String referer, String virtualMachineName) {
        final StopMode mode = null;
        final VirtualMachineStopMode m = null;
        return this.beginStopAsync(resourceGroupName, referer, virtualMachineName, mode, m).getSyncPoller();
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param mode query stop mode parameter (reboot, shutdown, etc...).
     * @param m body stop mode parameter (reboot, shutdown, etc...).
     * @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> beginStop(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        StopMode mode,
        VirtualMachineStopMode m,
        Context context) {
        return this.beginStopAsync(resourceGroupName, referer, virtualMachineName, mode, m, context).getSyncPoller();
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param mode query stop mode parameter (reboot, shutdown, etc...).
     * @param m body stop mode parameter (reboot, shutdown, etc...).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> stopAsync(
        String resourceGroupName, String referer, String virtualMachineName, StopMode mode, VirtualMachineStopMode m) {
        return beginStopAsync(resourceGroupName, referer, virtualMachineName, mode, m)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> stopAsync(String resourceGroupName, String referer, String virtualMachineName) {
        final StopMode mode = null;
        final VirtualMachineStopMode m = null;
        return beginStopAsync(resourceGroupName, referer, virtualMachineName, mode, m)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param mode query stop mode parameter (reboot, shutdown, etc...).
     * @param m body stop mode parameter (reboot, shutdown, etc...).
     * @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> stopAsync(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        StopMode mode,
        VirtualMachineStopMode m,
        Context context) {
        return beginStopAsync(resourceGroupName, referer, virtualMachineName, mode, m, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void stop(String resourceGroupName, String referer, String virtualMachineName) {
        final StopMode mode = null;
        final VirtualMachineStopMode m = null;
        stopAsync(resourceGroupName, referer, virtualMachineName, mode, m).block();
    }

    /**
     * Implements shutdown, poweroff, and suspend method for a virtual machine
     *
     * <p>Power off virtual machine, options: shutdown, poweroff, and suspend.
     *
     * @param resourceGroupName The name of the resource group.
     * @param referer referer url.
     * @param virtualMachineName virtual machine name.
     * @param mode query stop mode parameter (reboot, shutdown, etc...).
     * @param m body stop mode parameter (reboot, shutdown, etc...).
     * @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 stop(
        String resourceGroupName,
        String referer,
        String virtualMachineName,
        StopMode mode,
        VirtualMachineStopMode m,
        Context context) {
        stopAsync(resourceGroupName, referer, virtualMachineName, mode, m, context).block();
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of 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 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 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 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));
    }
}
