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

package com.azure.resourcemanager.avs.implementation;

import com.azure.core.annotation.BodyParam;
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.PathParam;
import com.azure.core.annotation.Post;
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.avs.fluent.VirtualMachinesClient;
import com.azure.resourcemanager.avs.fluent.models.VirtualMachineInner;
import com.azure.resourcemanager.avs.models.VirtualMachineRestrictMovement;
import com.azure.resourcemanager.avs.models.VirtualMachinesList;
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 AvsClientImpl client;

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

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

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AVS/privateClouds"
                + "/{privateCloudName}/clusters/{clusterName}/virtualMachines/{virtualMachineId}/restrictMovement")
        @ExpectedResponses({202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> restrictMovement(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("privateCloudName") String privateCloudName,
            @PathParam("clusterName") String clusterName,
            @PathParam("virtualMachineId") String virtualMachineId,
            @BodyParam("application/json") VirtualMachineRestrictMovement restrictMovement,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * List of virtual machines in a private cloud cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of Virtual Machines along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> listSinglePageAsync(
        String resourceGroupName, String privateCloudName, String clusterName) {
        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 (privateCloudName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter privateCloudName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            privateCloudName,
                            clusterName,
                            accept,
                            context))
            .<PagedResponse<VirtualMachineInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List of virtual machines in a private cloud cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of Virtual Machines along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> listSinglePageAsync(
        String resourceGroupName, String privateCloudName, String clusterName, 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 (privateCloudName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter privateCloudName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName 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(),
                resourceGroupName,
                this.client.getApiVersion(),
                privateCloudName,
                clusterName,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List of virtual machines in a private cloud cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of Virtual Machines as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listAsync(
        String resourceGroupName, String privateCloudName, String clusterName) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, privateCloudName, clusterName),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * List of virtual machines in a private cloud cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of Virtual Machines as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualMachineInner> listAsync(
        String resourceGroupName, String privateCloudName, String clusterName, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, privateCloudName, clusterName, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * List of virtual machines in a private cloud cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of Virtual Machines as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualMachineInner> list(
        String resourceGroupName, String privateCloudName, String clusterName) {
        return new PagedIterable<>(listAsync(resourceGroupName, privateCloudName, clusterName));
    }

    /**
     * List of virtual machines in a private cloud cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of Virtual Machines as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualMachineInner> list(
        String resourceGroupName, String privateCloudName, String clusterName, Context context) {
        return new PagedIterable<>(listAsync(resourceGroupName, privateCloudName, clusterName, context));
    }

    /**
     * Get a virtual machine by id in a private cloud cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtual machine by id in a private cloud cluster along with {@link Response} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<VirtualMachineInner>> getWithResponseAsync(
        String resourceGroupName, String privateCloudName, String clusterName, String virtualMachineId) {
        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 (privateCloudName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter privateCloudName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (virtualMachineId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineId is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            privateCloudName,
                            clusterName,
                            virtualMachineId,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get a virtual machine by id in a private cloud cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @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 virtual machine by id in a private cloud cluster along with {@link Response} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<VirtualMachineInner>> getWithResponseAsync(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        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 (privateCloudName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter privateCloudName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (virtualMachineId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineId is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                privateCloudName,
                clusterName,
                virtualMachineId,
                accept,
                context);
    }

    /**
     * Get a virtual machine by id in a private cloud cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtual machine by id in a private cloud cluster on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualMachineInner> getAsync(
        String resourceGroupName, String privateCloudName, String clusterName, String virtualMachineId) {
        return getWithResponseAsync(resourceGroupName, privateCloudName, clusterName, virtualMachineId)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get a virtual machine by id in a private cloud cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @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 virtual machine by id in a private cloud cluster along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<VirtualMachineInner> getWithResponse(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        Context context) {
        return getWithResponseAsync(resourceGroupName, privateCloudName, clusterName, virtualMachineId, context)
            .block();
    }

    /**
     * Get a virtual machine by id in a private cloud cluster.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtual machine by id in a private cloud cluster.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualMachineInner get(
        String resourceGroupName, String privateCloudName, String clusterName, String virtualMachineId) {
        return getWithResponse(resourceGroupName, privateCloudName, clusterName, virtualMachineId, Context.NONE)
            .getValue();
    }

    /**
     * Enable or disable DRS-driven VM movement restriction.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @param restrictMovement Whether VM DRS-driven movement is restricted (Enabled) or not (Disabled).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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>>> restrictMovementWithResponseAsync(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement) {
        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 (privateCloudName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter privateCloudName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (virtualMachineId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineId is required and cannot be null."));
        }
        if (restrictMovement == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter restrictMovement is required and cannot be null."));
        } else {
            restrictMovement.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .restrictMovement(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            privateCloudName,
                            clusterName,
                            virtualMachineId,
                            restrictMovement,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Enable or disable DRS-driven VM movement restriction.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @param restrictMovement Whether VM DRS-driven movement is restricted (Enabled) or not (Disabled).
     * @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>>> restrictMovementWithResponseAsync(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement,
        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 (privateCloudName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter privateCloudName is required and cannot be null."));
        }
        if (clusterName == null) {
            return Mono.error(new IllegalArgumentException("Parameter clusterName is required and cannot be null."));
        }
        if (virtualMachineId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualMachineId is required and cannot be null."));
        }
        if (restrictMovement == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter restrictMovement is required and cannot be null."));
        } else {
            restrictMovement.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .restrictMovement(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                privateCloudName,
                clusterName,
                virtualMachineId,
                restrictMovement,
                accept,
                context);
    }

    /**
     * Enable or disable DRS-driven VM movement restriction.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @param restrictMovement Whether VM DRS-driven movement is restricted (Enabled) or not (Disabled).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> beginRestrictMovementAsync(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            restrictMovementWithResponseAsync(
                resourceGroupName, privateCloudName, clusterName, virtualMachineId, restrictMovement);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Enable or disable DRS-driven VM movement restriction.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @param restrictMovement Whether VM DRS-driven movement is restricted (Enabled) or not (Disabled).
     * @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> beginRestrictMovementAsync(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            restrictMovementWithResponseAsync(
                resourceGroupName, privateCloudName, clusterName, virtualMachineId, restrictMovement, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Enable or disable DRS-driven VM movement restriction.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @param restrictMovement Whether VM DRS-driven movement is restricted (Enabled) or not (Disabled).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> beginRestrictMovement(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement) {
        return this
            .beginRestrictMovementAsync(
                resourceGroupName, privateCloudName, clusterName, virtualMachineId, restrictMovement)
            .getSyncPoller();
    }

    /**
     * Enable or disable DRS-driven VM movement restriction.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @param restrictMovement Whether VM DRS-driven movement is restricted (Enabled) or not (Disabled).
     * @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> beginRestrictMovement(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement,
        Context context) {
        return this
            .beginRestrictMovementAsync(
                resourceGroupName, privateCloudName, clusterName, virtualMachineId, restrictMovement, context)
            .getSyncPoller();
    }

    /**
     * Enable or disable DRS-driven VM movement restriction.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @param restrictMovement Whether VM DRS-driven movement is restricted (Enabled) or not (Disabled).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> restrictMovementAsync(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement) {
        return beginRestrictMovementAsync(
                resourceGroupName, privateCloudName, clusterName, virtualMachineId, restrictMovement)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Enable or disable DRS-driven VM movement restriction.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @param restrictMovement Whether VM DRS-driven movement is restricted (Enabled) or not (Disabled).
     * @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> restrictMovementAsync(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement,
        Context context) {
        return beginRestrictMovementAsync(
                resourceGroupName, privateCloudName, clusterName, virtualMachineId, restrictMovement, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Enable or disable DRS-driven VM movement restriction.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @param restrictMovement Whether VM DRS-driven movement is restricted (Enabled) or not (Disabled).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 restrictMovement(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement) {
        restrictMovementAsync(resourceGroupName, privateCloudName, clusterName, virtualMachineId, restrictMovement)
            .block();
    }

    /**
     * Enable or disable DRS-driven VM movement restriction.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param privateCloudName Name of the private cloud.
     * @param clusterName Name of the cluster in the private cloud.
     * @param virtualMachineId Virtual Machine identifier.
     * @param restrictMovement Whether VM DRS-driven movement is restricted (Enabled) or not (Disabled).
     * @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 restrictMovement(
        String resourceGroupName,
        String privateCloudName,
        String clusterName,
        String virtualMachineId,
        VirtualMachineRestrictMovement restrictMovement,
        Context context) {
        restrictMovementAsync(
                resourceGroupName, privateCloudName, clusterName, virtualMachineId, restrictMovement, 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 a list of Virtual Machines along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> listNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<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 a list of Virtual Machines along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualMachineInner>> listNextSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
