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

package com.azure.resourcemanager.networkcloud.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.networkcloud.fluent.ConsolesClient;
import com.azure.resourcemanager.networkcloud.fluent.models.ConsoleInner;
import com.azure.resourcemanager.networkcloud.models.ConsoleList;
import com.azure.resourcemanager.networkcloud.models.ConsolePatchParameters;
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 ConsolesClient. */
public final class ConsolesClientImpl implements ConsolesClient {
    /** The proxy service used to perform REST calls. */
    private final ConsolesService service;

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

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

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

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

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

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

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

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

    /**
     * List consoles of the virtual machine.
     *
     * <p>Get a list of consoles for the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of consoles for the provided virtual machine along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ConsoleInner>> listByVirtualMachineSinglePageAsync(
        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
                        .listByVirtualMachine(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualMachineName,
                            accept,
                            context))
            .<PagedResponse<ConsoleInner>>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 consoles of the virtual machine.
     *
     * <p>Get a list of consoles for the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of consoles for the provided virtual machine along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ConsoleInner>> listByVirtualMachineSinglePageAsync(
        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
            .listByVirtualMachine(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualMachineName,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List consoles of the virtual machine.
     *
     * <p>Get a list of consoles for the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of consoles for the provided virtual machine as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ConsoleInner> listByVirtualMachineAsync(String resourceGroupName, String virtualMachineName) {
        return new PagedFlux<>(
            () -> listByVirtualMachineSinglePageAsync(resourceGroupName, virtualMachineName),
            nextLink -> listByVirtualMachineNextSinglePageAsync(nextLink));
    }

    /**
     * List consoles of the virtual machine.
     *
     * <p>Get a list of consoles for the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of consoles for the provided virtual machine as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ConsoleInner> listByVirtualMachineAsync(
        String resourceGroupName, String virtualMachineName, Context context) {
        return new PagedFlux<>(
            () -> listByVirtualMachineSinglePageAsync(resourceGroupName, virtualMachineName, context),
            nextLink -> listByVirtualMachineNextSinglePageAsync(nextLink, context));
    }

    /**
     * List consoles of the virtual machine.
     *
     * <p>Get a list of consoles for the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of consoles for the provided virtual machine as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ConsoleInner> listByVirtualMachine(String resourceGroupName, String virtualMachineName) {
        return new PagedIterable<>(listByVirtualMachineAsync(resourceGroupName, virtualMachineName));
    }

    /**
     * List consoles of the virtual machine.
     *
     * <p>Get a list of consoles for the provided virtual machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of consoles for the provided virtual machine as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ConsoleInner> listByVirtualMachine(
        String resourceGroupName, String virtualMachineName, Context context) {
        return new PagedIterable<>(listByVirtualMachineAsync(resourceGroupName, virtualMachineName, context));
    }

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

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

    /**
     * Retrieve the virtual machine console.
     *
     * <p>Get properties of the provided virtual machine console.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param consoleName The name of the virtual machine console.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of the provided virtual machine console on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ConsoleInner> getAsync(String resourceGroupName, String virtualMachineName, String consoleName) {
        return getWithResponseAsync(resourceGroupName, virtualMachineName, consoleName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Retrieve the virtual machine console.
     *
     * <p>Get properties of the provided virtual machine console.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param consoleName The name of the virtual machine console.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of the provided virtual machine console along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ConsoleInner> getWithResponse(
        String resourceGroupName, String virtualMachineName, String consoleName, Context context) {
        return getWithResponseAsync(resourceGroupName, virtualMachineName, consoleName, context).block();
    }

    /**
     * Retrieve the virtual machine console.
     *
     * <p>Get properties of the provided virtual machine console.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param consoleName The name of the virtual machine console.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return properties of the provided virtual machine console.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ConsoleInner get(String resourceGroupName, String virtualMachineName, String consoleName) {
        return getWithResponse(resourceGroupName, virtualMachineName, consoleName, Context.NONE).getValue();
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * Patch the virtual machine console.
     *
     * <p>Patch the properties of the provided virtual machine console, or update the tags associated with the virtual
     * machine console. Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualMachineName The name of the virtual machine.
     * @param consoleName The name of the virtual machine console.
     * @param consoleUpdateParameters The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return console represents the console of an on-premises Network Cloud virtual machine.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ConsoleInner update(
        String resourceGroupName,
        String virtualMachineName,
        String consoleName,
        ConsolePatchParameters consoleUpdateParameters,
        Context context) {
        return updateAsync(resourceGroupName, virtualMachineName, consoleName, consoleUpdateParameters, 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 consoleList represents a list of virtual machine consoles along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ConsoleInner>> listByVirtualMachineNextSinglePageAsync(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.listByVirtualMachineNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ConsoleInner>>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 consoleList represents a list of virtual machine consoles along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ConsoleInner>> listByVirtualMachineNextSinglePageAsync(
        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
            .listByVirtualMachineNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
