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

package com.azure.resourcemanager.hybridcontainerservice.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.hybridcontainerservice.fluent.VirtualNetworksOperationsClient;
import com.azure.resourcemanager.hybridcontainerservice.fluent.models.VirtualNetworksInner;
import com.azure.resourcemanager.hybridcontainerservice.models.VirtualNetworksListResult;
import com.azure.resourcemanager.hybridcontainerservice.models.VirtualNetworksPatch;
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 VirtualNetworksOperationsClient. */
public final class VirtualNetworksOperationsClientImpl implements VirtualNetworksOperationsClient {
    /** The proxy service used to perform REST calls. */
    private final VirtualNetworksOperationsService service;

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

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

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

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

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

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

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

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

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

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

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

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

    /**
     * Gets the virtual network
     *
     * <p>Gets the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Hybrid AKS virtual network on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualNetworksInner> getByResourceGroupAsync(String resourceGroupName, String virtualNetworksName) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, virtualNetworksName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets the virtual network
     *
     * <p>Gets the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @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 Hybrid AKS virtual network along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<VirtualNetworksInner> getByResourceGroupWithResponse(
        String resourceGroupName, String virtualNetworksName, Context context) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, virtualNetworksName, context).block();
    }

    /**
     * Gets the virtual network
     *
     * <p>Gets the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Hybrid AKS virtual network.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualNetworksInner getByResourceGroup(String resourceGroupName, String virtualNetworksName) {
        return getByResourceGroupWithResponse(resourceGroupName, virtualNetworksName, Context.NONE).getValue();
    }

    /**
     * Puts the virtual network
     *
     * <p>Puts the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource definition.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtualNetworks resource definition along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksInner virtualNetworks) {
        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 (virtualNetworksName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualNetworksName is required and cannot be null."));
        }
        if (virtualNetworks == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualNetworks is required and cannot be null."));
        } else {
            virtualNetworks.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualNetworksName,
                            this.client.getApiVersion(),
                            virtualNetworks,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Puts the virtual network
     *
     * <p>Puts the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource definition.
     * @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 virtualNetworks resource definition along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksInner virtualNetworks, 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 (virtualNetworksName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualNetworksName is required and cannot be null."));
        }
        if (virtualNetworks == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualNetworks is required and cannot be null."));
        } else {
            virtualNetworks.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualNetworksName,
                this.client.getApiVersion(),
                virtualNetworks,
                accept,
                context);
    }

    /**
     * Puts the virtual network
     *
     * <p>Puts the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource definition.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of the virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<VirtualNetworksInner>, VirtualNetworksInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksInner virtualNetworks) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, virtualNetworksName, virtualNetworks);
        return this
            .client
            .<VirtualNetworksInner, VirtualNetworksInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                VirtualNetworksInner.class,
                VirtualNetworksInner.class,
                this.client.getContext());
    }

    /**
     * Puts the virtual network
     *
     * <p>Puts the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource definition.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of the virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<VirtualNetworksInner>, VirtualNetworksInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksInner virtualNetworks, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, virtualNetworksName, virtualNetworks, context);
        return this
            .client
            .<VirtualNetworksInner, VirtualNetworksInner>getLroResult(
                mono, this.client.getHttpPipeline(), VirtualNetworksInner.class, VirtualNetworksInner.class, context);
    }

    /**
     * Puts the virtual network
     *
     * <p>Puts the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource definition.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of the virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<VirtualNetworksInner>, VirtualNetworksInner> beginCreateOrUpdate(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksInner virtualNetworks) {
        return this.beginCreateOrUpdateAsync(resourceGroupName, virtualNetworksName, virtualNetworks).getSyncPoller();
    }

    /**
     * Puts the virtual network
     *
     * <p>Puts the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource definition.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of the virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<VirtualNetworksInner>, VirtualNetworksInner> beginCreateOrUpdate(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksInner virtualNetworks, Context context) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, virtualNetworksName, virtualNetworks, context)
            .getSyncPoller();
    }

    /**
     * Puts the virtual network
     *
     * <p>Puts the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource definition.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtualNetworks resource definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualNetworksInner> createOrUpdateAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksInner virtualNetworks) {
        return beginCreateOrUpdateAsync(resourceGroupName, virtualNetworksName, virtualNetworks)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Puts the virtual network
     *
     * <p>Puts the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource definition.
     * @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 virtualNetworks resource definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualNetworksInner> createOrUpdateAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksInner virtualNetworks, Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, virtualNetworksName, virtualNetworks, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Puts the virtual network
     *
     * <p>Puts the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource definition.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualNetworksInner createOrUpdate(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksInner virtualNetworks) {
        return createOrUpdateAsync(resourceGroupName, virtualNetworksName, virtualNetworks).block();
    }

    /**
     * Puts the virtual network
     *
     * <p>Puts the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource definition.
     * @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 virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualNetworksInner createOrUpdate(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksInner virtualNetworks, Context context) {
        return createOrUpdateAsync(resourceGroupName, virtualNetworksName, virtualNetworks, context).block();
    }

    /**
     * Deletes the virtual network
     *
     * <p>Deletes the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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<Void>> deleteWithResponseAsync(String resourceGroupName, String virtualNetworksName) {
        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 (virtualNetworksName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualNetworksName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualNetworksName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

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

    /**
     * Deletes the virtual network
     *
     * <p>Deletes the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtualNetworksName) {
        return deleteWithResponseAsync(resourceGroupName, virtualNetworksName).flatMap(ignored -> Mono.empty());
    }

    /**
     * Deletes the virtual network
     *
     * <p>Deletes the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @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}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(String resourceGroupName, String virtualNetworksName, Context context) {
        return deleteWithResponseAsync(resourceGroupName, virtualNetworksName, context).block();
    }

    /**
     * Deletes the virtual network
     *
     * <p>Deletes the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 virtualNetworksName) {
        deleteWithResponse(resourceGroupName, virtualNetworksName, Context.NONE);
    }

    /**
     * Patches the virtual network
     *
     * <p>Patches the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource patch definition.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtualNetworks resource definition along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksPatch virtualNetworks) {
        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 (virtualNetworksName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualNetworksName is required and cannot be null."));
        }
        if (virtualNetworks == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualNetworks is required and cannot be null."));
        } else {
            virtualNetworks.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            virtualNetworksName,
                            this.client.getApiVersion(),
                            virtualNetworks,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Patches the virtual network
     *
     * <p>Patches the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource patch definition.
     * @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 virtualNetworks resource definition along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksPatch virtualNetworks, 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 (virtualNetworksName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualNetworksName is required and cannot be null."));
        }
        if (virtualNetworks == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter virtualNetworks is required and cannot be null."));
        } else {
            virtualNetworks.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                virtualNetworksName,
                this.client.getApiVersion(),
                virtualNetworks,
                accept,
                context);
    }

    /**
     * Patches the virtual network
     *
     * <p>Patches the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource patch definition.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of the virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<VirtualNetworksInner>, VirtualNetworksInner> beginUpdateAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksPatch virtualNetworks) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, virtualNetworksName, virtualNetworks);
        return this
            .client
            .<VirtualNetworksInner, VirtualNetworksInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                VirtualNetworksInner.class,
                VirtualNetworksInner.class,
                this.client.getContext());
    }

    /**
     * Patches the virtual network
     *
     * <p>Patches the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource patch definition.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of the virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<VirtualNetworksInner>, VirtualNetworksInner> beginUpdateAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksPatch virtualNetworks, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, virtualNetworksName, virtualNetworks, context);
        return this
            .client
            .<VirtualNetworksInner, VirtualNetworksInner>getLroResult(
                mono, this.client.getHttpPipeline(), VirtualNetworksInner.class, VirtualNetworksInner.class, context);
    }

    /**
     * Patches the virtual network
     *
     * <p>Patches the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource patch definition.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of the virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<VirtualNetworksInner>, VirtualNetworksInner> beginUpdate(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksPatch virtualNetworks) {
        return this.beginUpdateAsync(resourceGroupName, virtualNetworksName, virtualNetworks).getSyncPoller();
    }

    /**
     * Patches the virtual network
     *
     * <p>Patches the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource patch definition.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of the virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<VirtualNetworksInner>, VirtualNetworksInner> beginUpdate(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksPatch virtualNetworks, Context context) {
        return this.beginUpdateAsync(resourceGroupName, virtualNetworksName, virtualNetworks, context).getSyncPoller();
    }

    /**
     * Patches the virtual network
     *
     * <p>Patches the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource patch definition.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtualNetworks resource definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualNetworksInner> updateAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksPatch virtualNetworks) {
        return beginUpdateAsync(resourceGroupName, virtualNetworksName, virtualNetworks)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patches the virtual network
     *
     * <p>Patches the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource patch definition.
     * @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 virtualNetworks resource definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VirtualNetworksInner> updateAsync(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksPatch virtualNetworks, Context context) {
        return beginUpdateAsync(resourceGroupName, virtualNetworksName, virtualNetworks, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patches the virtual network
     *
     * <p>Patches the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource patch definition.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualNetworksInner update(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksPatch virtualNetworks) {
        return updateAsync(resourceGroupName, virtualNetworksName, virtualNetworks).block();
    }

    /**
     * Patches the virtual network
     *
     * <p>Patches the Hybrid AKS virtual network.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param virtualNetworksName Parameter for the name of the virtual network.
     * @param virtualNetworks The virtualNetworks resource patch definition.
     * @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 virtualNetworks resource definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VirtualNetworksInner update(
        String resourceGroupName, String virtualNetworksName, VirtualNetworksPatch virtualNetworks, Context context) {
        return updateAsync(resourceGroupName, virtualNetworksName, virtualNetworks, context).block();
    }

    /**
     * List virtual networks by resource group
     *
     * <p>Lists the Hybrid AKS virtual networks by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualNetworksInner>> listByResourceGroupSinglePageAsync(String resourceGroupName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<VirtualNetworksInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List virtual networks by resource group
     *
     * <p>Lists the Hybrid AKS virtual networks by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualNetworksInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List virtual networks by resource group
     *
     * <p>Lists the Hybrid AKS virtual networks by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualNetworksInner> listByResourceGroupAsync(String resourceGroupName) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * List virtual networks by resource group
     *
     * <p>Lists the Hybrid AKS virtual networks by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualNetworksInner> listByResourceGroupAsync(String resourceGroupName, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, context),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * List virtual networks by resource group
     *
     * <p>Lists the Hybrid AKS virtual networks by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualNetworksInner> listByResourceGroup(String resourceGroupName) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName));
    }

    /**
     * List virtual networks by resource group
     *
     * <p>Lists the Hybrid AKS virtual networks by resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualNetworksInner> listByResourceGroup(String resourceGroupName, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, context));
    }

    /**
     * List virtual networks by subscription
     *
     * <p>Lists the Hybrid AKS virtual networks by subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualNetworksInner>> listSinglePageAsync() {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<VirtualNetworksInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List virtual networks by subscription
     *
     * <p>Lists the Hybrid AKS virtual networks by subscription.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualNetworksInner>> listSinglePageAsync(Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List virtual networks by subscription
     *
     * <p>Lists the Hybrid AKS virtual networks by subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualNetworksInner> listAsync() {
        return new PagedFlux<>(
            () -> listSinglePageAsync(), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * List virtual networks by subscription
     *
     * <p>Lists the Hybrid AKS virtual networks by subscription.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VirtualNetworksInner> listAsync(Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(context), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * List virtual networks by subscription
     *
     * <p>Lists the Hybrid AKS virtual networks by subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualNetworksInner> list() {
        return new PagedIterable<>(listAsync());
    }

    /**
     * List virtual networks by subscription
     *
     * <p>Lists the Hybrid AKS virtual networks by subscription.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VirtualNetworksInner> list(Context context) {
        return new PagedIterable<>(listAsync(context));
    }

    /**
     * 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 the response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualNetworksInner>> listByResourceGroupNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context -> service.listByResourceGroupNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<VirtualNetworksInner>>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 the response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualNetworksInner>> listByResourceGroupNextSinglePageAsync(
        String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByResourceGroupNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualNetworksInner>> listBySubscriptionNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context -> service.listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<VirtualNetworksInner>>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 the response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VirtualNetworksInner>> listBySubscriptionNextSinglePageAsync(
        String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
