// 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.BodyParam;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.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.hybridnetwork.fluent.VendorNetworkFunctionsClient;
import com.azure.resourcemanager.hybridnetwork.fluent.models.VendorNetworkFunctionInner;
import com.azure.resourcemanager.hybridnetwork.models.VendorNetworkFunctionListResult;
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 VendorNetworkFunctionsClient. */
public final class VendorNetworkFunctionsClientImpl implements VendorNetworkFunctionsClient {
    /** The proxy service used to perform REST calls. */
    private final VendorNetworkFunctionsService service;

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

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

    /**
     * The interface defining all the services for HybridNetworkManagementClientVendorNetworkFunctions to be used by the
     * proxy service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "HybridNetworkManagem")
    private interface VendorNetworkFunctionsService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/locations/{locationName}/vendors"
                + "/{vendorName}/networkFunctions/{serviceKey}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<VendorNetworkFunctionInner>> get(
            @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"})
        @Put(
            "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/locations/{locationName}/vendors"
                + "/{vendorName}/networkFunctions/{serviceKey}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @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,
            @BodyParam("application/json") VendorNetworkFunctionInner parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/providers/Microsoft.HybridNetwork/locations/{locationName}/vendors"
                + "/{vendorName}/networkFunctions")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<VendorNetworkFunctionListResult>> list(
            @HostParam("$host") String endpoint,
            @PathParam("locationName") String locationName,
            @PathParam("vendorName") String vendorName,
            @QueryParam("$filter") String filter,
            @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<VendorNetworkFunctionListResult>> listNext(
            @PathParam(value = "nextLink", encoded = true) String nextLink,
            @HostParam("$host") String endpoint,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * Gets information about the specified vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by the 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 information about the specified vendor network function along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<VendorNetworkFunctionInner>> getWithResponseAsync(
        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
                        .get(
                            this.client.getEndpoint(),
                            locationName,
                            vendorName,
                            serviceKey,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets information about the specified vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by the 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 information about the specified vendor network function along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<VendorNetworkFunctionInner>> getWithResponseAsync(
        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
            .get(
                this.client.getEndpoint(),
                locationName,
                vendorName,
                serviceKey,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                accept,
                context);
    }

    /**
     * Gets information about the specified vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by the 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 information about the specified vendor network function on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VendorNetworkFunctionInner> getAsync(String locationName, String vendorName, String serviceKey) {
        return getWithResponseAsync(locationName, vendorName, serviceKey)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

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

    /**
     * Gets information about the specified vendor network function.
     *
     * @param locationName The Azure region where the network function resource was created by the 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 information about the specified vendor network function.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VendorNetworkFunctionInner get(String locationName, String vendorName, String serviceKey) {
        return getWithResponse(locationName, vendorName, serviceKey, Context.NONE).getValue();
    }

    /**
     * Creates or updates a vendor network function. This operation can take up to 6 hours to complete. This is expected
     * service behavior.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param parameters Parameters supplied to the create or update vendor network function 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 vendor network function sub resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String locationName, String vendorName, String serviceKey, VendorNetworkFunctionInner parameters) {
        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."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            locationName,
                            vendorName,
                            serviceKey,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a vendor network function. This operation can take up to 6 hours to complete. This is expected
     * service behavior.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param parameters Parameters supplied to the create or update vendor network function operation.
     * @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 vendor network function sub resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String locationName,
        String vendorName,
        String serviceKey,
        VendorNetworkFunctionInner parameters,
        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."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                locationName,
                vendorName,
                serviceKey,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                parameters,
                accept,
                context);
    }

    /**
     * Creates or updates a vendor network function. This operation can take up to 6 hours to complete. This is expected
     * service behavior.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param parameters Parameters supplied to the create or update vendor network function 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 vendor network function sub resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<VendorNetworkFunctionInner>, VendorNetworkFunctionInner> beginCreateOrUpdateAsync(
        String locationName, String vendorName, String serviceKey, VendorNetworkFunctionInner parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(locationName, vendorName, serviceKey, parameters);
        return this
            .client
            .<VendorNetworkFunctionInner, VendorNetworkFunctionInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                VendorNetworkFunctionInner.class,
                VendorNetworkFunctionInner.class,
                this.client.getContext());
    }

    /**
     * Creates or updates a vendor network function. This operation can take up to 6 hours to complete. This is expected
     * service behavior.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param parameters Parameters supplied to the create or update vendor network function operation.
     * @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 vendor network function sub resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<VendorNetworkFunctionInner>, VendorNetworkFunctionInner> beginCreateOrUpdateAsync(
        String locationName,
        String vendorName,
        String serviceKey,
        VendorNetworkFunctionInner parameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(locationName, vendorName, serviceKey, parameters, context);
        return this
            .client
            .<VendorNetworkFunctionInner, VendorNetworkFunctionInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                VendorNetworkFunctionInner.class,
                VendorNetworkFunctionInner.class,
                context);
    }

    /**
     * Creates or updates a vendor network function. This operation can take up to 6 hours to complete. This is expected
     * service behavior.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param parameters Parameters supplied to the create or update vendor network function 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 vendor network function sub resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<VendorNetworkFunctionInner>, VendorNetworkFunctionInner> beginCreateOrUpdate(
        String locationName, String vendorName, String serviceKey, VendorNetworkFunctionInner parameters) {
        return beginCreateOrUpdateAsync(locationName, vendorName, serviceKey, parameters).getSyncPoller();
    }

    /**
     * Creates or updates a vendor network function. This operation can take up to 6 hours to complete. This is expected
     * service behavior.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param parameters Parameters supplied to the create or update vendor network function operation.
     * @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 vendor network function sub resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<VendorNetworkFunctionInner>, VendorNetworkFunctionInner> beginCreateOrUpdate(
        String locationName,
        String vendorName,
        String serviceKey,
        VendorNetworkFunctionInner parameters,
        Context context) {
        return beginCreateOrUpdateAsync(locationName, vendorName, serviceKey, parameters, context).getSyncPoller();
    }

    /**
     * Creates or updates a vendor network function. This operation can take up to 6 hours to complete. This is expected
     * service behavior.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param parameters Parameters supplied to the create or update vendor network function 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 vendor network function sub resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VendorNetworkFunctionInner> createOrUpdateAsync(
        String locationName, String vendorName, String serviceKey, VendorNetworkFunctionInner parameters) {
        return beginCreateOrUpdateAsync(locationName, vendorName, serviceKey, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates a vendor network function. This operation can take up to 6 hours to complete. This is expected
     * service behavior.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param parameters Parameters supplied to the create or update vendor network function operation.
     * @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 vendor network function sub resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<VendorNetworkFunctionInner> createOrUpdateAsync(
        String locationName,
        String vendorName,
        String serviceKey,
        VendorNetworkFunctionInner parameters,
        Context context) {
        return beginCreateOrUpdateAsync(locationName, vendorName, serviceKey, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates a vendor network function. This operation can take up to 6 hours to complete. This is expected
     * service behavior.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param parameters Parameters supplied to the create or update vendor network function 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 vendor network function sub resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VendorNetworkFunctionInner createOrUpdate(
        String locationName, String vendorName, String serviceKey, VendorNetworkFunctionInner parameters) {
        return createOrUpdateAsync(locationName, vendorName, serviceKey, parameters).block();
    }

    /**
     * Creates or updates a vendor network function. This operation can take up to 6 hours to complete. This is expected
     * service behavior.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param serviceKey The GUID for the vendor network function.
     * @param parameters Parameters supplied to the create or update vendor network function operation.
     * @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 vendor network function sub resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public VendorNetworkFunctionInner createOrUpdate(
        String locationName,
        String vendorName,
        String serviceKey,
        VendorNetworkFunctionInner parameters,
        Context context) {
        return createOrUpdateAsync(locationName, vendorName, serviceKey, parameters, context).block();
    }

    /**
     * Lists all the vendor network function sub resources in an Azure region, filtered by skuType, skuName,
     * vendorProvisioningState.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param filter The filter to apply on the operation. The properties you can use for eq (equals) are: skuType,
     *     skuName and vendorProvisioningState.
     * @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 response for vendors API service call along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VendorNetworkFunctionInner>> listSinglePageAsync(
        String locationName, String vendorName, String filter) {
        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 (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,
                            filter,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .<PagedResponse<VendorNetworkFunctionInner>>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 all the vendor network function sub resources in an Azure region, filtered by skuType, skuName,
     * vendorProvisioningState.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param filter The filter to apply on the operation. The properties you can use for eq (equals) are: skuType,
     *     skuName and vendorProvisioningState.
     * @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 response for vendors API service call along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VendorNetworkFunctionInner>> listSinglePageAsync(
        String locationName, String vendorName, String filter, 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 (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,
                filter,
                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 all the vendor network function sub resources in an Azure region, filtered by skuType, skuName,
     * vendorProvisioningState.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param filter The filter to apply on the operation. The properties you can use for eq (equals) are: skuType,
     *     skuName and vendorProvisioningState.
     * @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 response for vendors API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VendorNetworkFunctionInner> listAsync(String locationName, String vendorName, String filter) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(locationName, vendorName, filter), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Lists all the vendor network function sub resources in an Azure region, filtered by skuType, skuName,
     * vendorProvisioningState.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @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 response for vendors API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VendorNetworkFunctionInner> listAsync(String locationName, String vendorName) {
        final String filter = null;
        return new PagedFlux<>(
            () -> listSinglePageAsync(locationName, vendorName, filter), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Lists all the vendor network function sub resources in an Azure region, filtered by skuType, skuName,
     * vendorProvisioningState.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param filter The filter to apply on the operation. The properties you can use for eq (equals) are: skuType,
     *     skuName and vendorProvisioningState.
     * @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 response for vendors API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<VendorNetworkFunctionInner> listAsync(
        String locationName, String vendorName, String filter, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(locationName, vendorName, filter, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists all the vendor network function sub resources in an Azure region, filtered by skuType, skuName,
     * vendorProvisioningState.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @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 response for vendors API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VendorNetworkFunctionInner> list(String locationName, String vendorName) {
        final String filter = null;
        return new PagedIterable<>(listAsync(locationName, vendorName, filter));
    }

    /**
     * Lists all the vendor network function sub resources in an Azure region, filtered by skuType, skuName,
     * vendorProvisioningState.
     *
     * @param locationName The Azure region where the network function resource was created by the customer.
     * @param vendorName The name of the vendor.
     * @param filter The filter to apply on the operation. The properties you can use for eq (equals) are: skuType,
     *     skuName and vendorProvisioningState.
     * @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 response for vendors API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<VendorNetworkFunctionInner> list(
        String locationName, String vendorName, String filter, Context context) {
        return new PagedIterable<>(listAsync(locationName, vendorName, filter, 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 response for vendors API service call along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VendorNetworkFunctionInner>> 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<VendorNetworkFunctionInner>>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 response for vendors API service call along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<VendorNetworkFunctionInner>> 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));
    }
}
