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

package com.azure.resourcemanager.hybridnetwork.implementation;

import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Post;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.hybridnetwork.fluent.RoleInstancesClient;
import com.azure.resourcemanager.hybridnetwork.fluent.models.RoleInstanceInner;
import com.azure.resourcemanager.hybridnetwork.models.NetworkFunctionRoleInstanceListResult;
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 RoleInstancesClient. */
public final class RoleInstancesClientImpl implements RoleInstancesClient {
    /** The proxy service used to perform REST calls. */
    private final RoleInstancesService service;

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

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

    /**
     * The interface defining all the services for HybridNetworkManagementClientRoleInstances to be used by the proxy
     * service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "HybridNetworkManagem")
    private interface RoleInstancesService {
        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/locations/{locationName}/vendors"
                + "/{vendorName}/networkFunctions/{serviceKey}/roleInstances/{roleInstanceName}/start")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> start(
            @HostParam("$host") String endpoint,
            @PathParam("locationName") String locationName,
            @PathParam("vendorName") String vendorName,
            @PathParam("serviceKey") String serviceKey,
            @PathParam("roleInstanceName") String roleInstanceName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/locations/{locationName}/vendors"
                + "/{vendorName}/networkFunctions/{serviceKey}/roleInstances/{roleInstanceName}/stop")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> stop(
            @HostParam("$host") String endpoint,
            @PathParam("locationName") String locationName,
            @PathParam("vendorName") String vendorName,
            @PathParam("serviceKey") String serviceKey,
            @PathParam("roleInstanceName") String roleInstanceName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/locations/{locationName}/vendors"
                + "/{vendorName}/networkFunctions/{serviceKey}/roleInstances/{roleInstanceName}/restart")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> restart(
            @HostParam("$host") String endpoint,
            @PathParam("locationName") String locationName,
            @PathParam("vendorName") String vendorName,
            @PathParam("serviceKey") String serviceKey,
            @PathParam("roleInstanceName") String roleInstanceName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/locations/{locationName}/vendors"
                + "/{vendorName}/networkFunctions/{serviceKey}/roleInstances/{roleInstanceName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RoleInstanceInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("locationName") String locationName,
            @PathParam("vendorName") String vendorName,
            @PathParam("serviceKey") String serviceKey,
            @PathParam("roleInstanceName") String roleInstanceName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/locations/{locationName}/vendors"
                + "/{vendorName}/networkFunctions/{serviceKey}/roleInstances")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<NetworkFunctionRoleInstanceListResult>> list(
            @HostParam("$host") String endpoint,
            @PathParam("locationName") String locationName,
            @PathParam("vendorName") String vendorName,
            @PathParam("serviceKey") String serviceKey,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Starts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> startWithResponseAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (locationName == null) {
            return Mono.error(new IllegalArgumentException("Parameter locationName is required and cannot be null."));
        }
        if (vendorName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vendorName is required and cannot be null."));
        }
        if (serviceKey == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceKey is required and cannot be null."));
        }
        if (roleInstanceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter roleInstanceName 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
                        .start(
                            this.client.getEndpoint(),
                            locationName,
                            vendorName,
                            serviceKey,
                            roleInstanceName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Starts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> startWithResponseAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (locationName == null) {
            return Mono.error(new IllegalArgumentException("Parameter locationName is required and cannot be null."));
        }
        if (vendorName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vendorName is required and cannot be null."));
        }
        if (serviceKey == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceKey is required and cannot be null."));
        }
        if (roleInstanceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter roleInstanceName 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
            .start(
                this.client.getEndpoint(),
                locationName,
                vendorName,
                serviceKey,
                roleInstanceName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                accept,
                context);
    }

    /**
     * Starts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginStartAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            startWithResponseAsync(locationName, vendorName, serviceKey, roleInstanceName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Starts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginStartAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            startWithResponseAsync(locationName, vendorName, serviceKey, roleInstanceName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Starts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginStart(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        return beginStartAsync(locationName, vendorName, serviceKey, roleInstanceName).getSyncPoller();
    }

    /**
     * Starts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginStart(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        return beginStartAsync(locationName, vendorName, serviceKey, roleInstanceName, context).getSyncPoller();
    }

    /**
     * Starts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> startAsync(String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        return beginStartAsync(locationName, vendorName, serviceKey, roleInstanceName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Starts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> startAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        return beginStartAsync(locationName, vendorName, serviceKey, roleInstanceName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Starts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void start(String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        startAsync(locationName, vendorName, serviceKey, roleInstanceName).block();
    }

    /**
     * Starts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void start(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        startAsync(locationName, vendorName, serviceKey, roleInstanceName, context).block();
    }

    /**
     * Powers off (stop) a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> stopWithResponseAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (locationName == null) {
            return Mono.error(new IllegalArgumentException("Parameter locationName is required and cannot be null."));
        }
        if (vendorName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vendorName is required and cannot be null."));
        }
        if (serviceKey == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceKey is required and cannot be null."));
        }
        if (roleInstanceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter roleInstanceName 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
                        .stop(
                            this.client.getEndpoint(),
                            locationName,
                            vendorName,
                            serviceKey,
                            roleInstanceName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Powers off (stop) a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> stopWithResponseAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (locationName == null) {
            return Mono.error(new IllegalArgumentException("Parameter locationName is required and cannot be null."));
        }
        if (vendorName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vendorName is required and cannot be null."));
        }
        if (serviceKey == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceKey is required and cannot be null."));
        }
        if (roleInstanceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter roleInstanceName 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
            .stop(
                this.client.getEndpoint(),
                locationName,
                vendorName,
                serviceKey,
                roleInstanceName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                accept,
                context);
    }

    /**
     * Powers off (stop) a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginStopAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            stopWithResponseAsync(locationName, vendorName, serviceKey, roleInstanceName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Powers off (stop) a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginStopAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            stopWithResponseAsync(locationName, vendorName, serviceKey, roleInstanceName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Powers off (stop) a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginStop(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        return beginStopAsync(locationName, vendorName, serviceKey, roleInstanceName).getSyncPoller();
    }

    /**
     * Powers off (stop) a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginStop(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        return beginStopAsync(locationName, vendorName, serviceKey, roleInstanceName, context).getSyncPoller();
    }

    /**
     * Powers off (stop) a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> stopAsync(String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        return beginStopAsync(locationName, vendorName, serviceKey, roleInstanceName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Powers off (stop) a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> stopAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        return beginStopAsync(locationName, vendorName, serviceKey, roleInstanceName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Powers off (stop) a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void stop(String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        stopAsync(locationName, vendorName, serviceKey, roleInstanceName).block();
    }

    /**
     * Powers off (stop) a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void stop(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        stopAsync(locationName, vendorName, serviceKey, roleInstanceName, context).block();
    }

    /**
     * Restarts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> restartWithResponseAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (locationName == null) {
            return Mono.error(new IllegalArgumentException("Parameter locationName is required and cannot be null."));
        }
        if (vendorName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vendorName is required and cannot be null."));
        }
        if (serviceKey == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceKey is required and cannot be null."));
        }
        if (roleInstanceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter roleInstanceName 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
                        .restart(
                            this.client.getEndpoint(),
                            locationName,
                            vendorName,
                            serviceKey,
                            roleInstanceName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Restarts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> restartWithResponseAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (locationName == null) {
            return Mono.error(new IllegalArgumentException("Parameter locationName is required and cannot be null."));
        }
        if (vendorName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vendorName is required and cannot be null."));
        }
        if (serviceKey == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceKey is required and cannot be null."));
        }
        if (roleInstanceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter roleInstanceName 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
            .restart(
                this.client.getEndpoint(),
                locationName,
                vendorName,
                serviceKey,
                roleInstanceName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                accept,
                context);
    }

    /**
     * Restarts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginRestartAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            restartWithResponseAsync(locationName, vendorName, serviceKey, roleInstanceName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Restarts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginRestartAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            restartWithResponseAsync(locationName, vendorName, serviceKey, roleInstanceName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Restarts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginRestart(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        return beginRestartAsync(locationName, vendorName, serviceKey, roleInstanceName).getSyncPoller();
    }

    /**
     * Restarts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginRestart(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        return beginRestartAsync(locationName, vendorName, serviceKey, roleInstanceName, context).getSyncPoller();
    }

    /**
     * Restarts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> restartAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        return beginRestartAsync(locationName, vendorName, serviceKey, roleInstanceName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Restarts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> restartAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        return beginRestartAsync(locationName, vendorName, serviceKey, roleInstanceName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Restarts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void restart(String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        restartAsync(locationName, vendorName, serviceKey, roleInstanceName).block();
    }

    /**
     * Restarts a role instance of a vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void restart(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        restartAsync(locationName, vendorName, serviceKey, roleInstanceName, context).block();
    }

    /**
     * Gets the information of role instance of vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 information of role instance of vendor network function along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RoleInstanceInner>> getWithResponseAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (locationName == null) {
            return Mono.error(new IllegalArgumentException("Parameter locationName is required and cannot be null."));
        }
        if (vendorName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vendorName is required and cannot be null."));
        }
        if (serviceKey == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceKey is required and cannot be null."));
        }
        if (roleInstanceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter roleInstanceName 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
                        .get(
                            this.client.getEndpoint(),
                            locationName,
                            vendorName,
                            serviceKey,
                            roleInstanceName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets the information of role instance of vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @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 information of role instance of vendor network function along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RoleInstanceInner>> getWithResponseAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (locationName == null) {
            return Mono.error(new IllegalArgumentException("Parameter locationName is required and cannot be null."));
        }
        if (vendorName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vendorName is required and cannot be null."));
        }
        if (serviceKey == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceKey is required and cannot be null."));
        }
        if (roleInstanceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter roleInstanceName 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
            .get(
                this.client.getEndpoint(),
                locationName,
                vendorName,
                serviceKey,
                roleInstanceName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                accept,
                context);
    }

    /**
     * Gets the information of role instance of vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 information of role instance of vendor network function on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RoleInstanceInner> getAsync(
        String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        return getWithResponseAsync(locationName, vendorName, serviceKey, roleInstanceName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets the information of role instance of vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @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 information of role instance of vendor network function along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RoleInstanceInner> getWithResponse(
        String locationName, String vendorName, String serviceKey, String roleInstanceName, Context context) {
        return getWithResponseAsync(locationName, vendorName, serviceKey, roleInstanceName, context).block();
    }

    /**
     * Gets the information of role instance of vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param roleInstanceName The name of the role instance of the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 information of role instance of vendor network function.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RoleInstanceInner get(String locationName, String vendorName, String serviceKey, String roleInstanceName) {
        return getWithResponse(locationName, vendorName, serviceKey, roleInstanceName, Context.NONE).getValue();
    }

    /**
     * Lists the information of role instances of vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of role instances of vendor network function along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RoleInstanceInner>> listSinglePageAsync(
        String locationName, String vendorName, String serviceKey) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (locationName == null) {
            return Mono.error(new IllegalArgumentException("Parameter locationName is required and cannot be null."));
        }
        if (vendorName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vendorName is required and cannot be null."));
        }
        if (serviceKey == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceKey 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(),
                            locationName,
                            vendorName,
                            serviceKey,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .<PagedResponse<RoleInstanceInner>>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()));
    }

    /**
     * Lists the information of role instances of vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of role instances of vendor network function along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RoleInstanceInner>> listSinglePageAsync(
        String locationName, String vendorName, String serviceKey, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (locationName == null) {
            return Mono.error(new IllegalArgumentException("Parameter locationName is required and cannot be null."));
        }
        if (vendorName == null) {
            return Mono.error(new IllegalArgumentException("Parameter vendorName is required and cannot be null."));
        }
        if (serviceKey == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceKey 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(),
                locationName,
                vendorName,
                serviceKey,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Lists the information of role instances of vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of role instances of vendor network function as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RoleInstanceInner> listAsync(String locationName, String vendorName, String serviceKey) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(locationName, vendorName, serviceKey),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Lists the information of role instances of vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of role instances of vendor network function as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RoleInstanceInner> listAsync(
        String locationName, String vendorName, String serviceKey, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(locationName, vendorName, serviceKey, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists the information of role instances of vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of role instances of vendor network function as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RoleInstanceInner> list(String locationName, String vendorName, String serviceKey) {
        return new PagedIterable<>(listAsync(locationName, vendorName, serviceKey));
    }

    /**
     * Lists the information of role instances of vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of role instances of vendor network function as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RoleInstanceInner> list(
        String locationName, String vendorName, String serviceKey, Context context) {
        return new PagedIterable<>(listAsync(locationName, vendorName, serviceKey, 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 list of role instances of vendor network function along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RoleInstanceInner>> listNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<RoleInstanceInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

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