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

package com.azure.resourcemanager.peering.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.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.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.resourcemanager.peering.fluent.PrefixesClient;
import com.azure.resourcemanager.peering.fluent.models.PeeringServicePrefixInner;
import com.azure.resourcemanager.peering.models.PeeringServicePrefixListResult;
import reactor.core.publisher.Mono;

/** An instance of this class provides access to all the operations defined in PrefixesClient. */
public final class PrefixesClientImpl implements PrefixesClient {
    /** The proxy service used to perform REST calls. */
    private final PrefixesService service;

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

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

    /**
     * The interface defining all the services for PeeringManagementClientPrefixes to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "PeeringManagementCli")
    public interface PrefixesService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Peering"
                + "/peeringServices/{peeringServiceName}/prefixes/{prefixName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PeeringServicePrefixInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("peeringServiceName") String peeringServiceName,
            @PathParam("prefixName") String prefixName,
            @QueryParam("$expand") String expand,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

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

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

    /**
     * Gets an existing prefix with the specified name under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @param expand The properties to be expanded.
     * @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 an existing prefix with the specified name under the given subscription, resource group and peering
     *     service along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<PeeringServicePrefixInner>> getWithResponseAsync(
        String resourceGroupName, String peeringServiceName, String prefixName, String expand) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (peeringServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter peeringServiceName is required and cannot be null."));
        }
        if (prefixName == null) {
            return Mono.error(new IllegalArgumentException("Parameter prefixName 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(),
                            resourceGroupName,
                            peeringServiceName,
                            prefixName,
                            expand,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets an existing prefix with the specified name under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @param expand The properties to be expanded.
     * @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 an existing prefix with the specified name under the given subscription, resource group and peering
     *     service along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<PeeringServicePrefixInner>> getWithResponseAsync(
        String resourceGroupName, String peeringServiceName, String prefixName, String expand, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (peeringServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter peeringServiceName is required and cannot be null."));
        }
        if (prefixName == null) {
            return Mono.error(new IllegalArgumentException("Parameter prefixName 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(),
                resourceGroupName,
                peeringServiceName,
                prefixName,
                expand,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Gets an existing prefix with the specified name under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @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 an existing prefix with the specified name under the given subscription, resource group and peering
     *     service on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PeeringServicePrefixInner> getAsync(
        String resourceGroupName, String peeringServiceName, String prefixName) {
        final String expand = null;
        return getWithResponseAsync(resourceGroupName, peeringServiceName, prefixName, expand)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets an existing prefix with the specified name under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @param expand The properties to be expanded.
     * @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 an existing prefix with the specified name under the given subscription, resource group and peering
     *     service along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<PeeringServicePrefixInner> getWithResponse(
        String resourceGroupName, String peeringServiceName, String prefixName, String expand, Context context) {
        return getWithResponseAsync(resourceGroupName, peeringServiceName, prefixName, expand, context).block();
    }

    /**
     * Gets an existing prefix with the specified name under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @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 an existing prefix with the specified name under the given subscription, resource group and peering
     *     service.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PeeringServicePrefixInner get(String resourceGroupName, String peeringServiceName, String prefixName) {
        final String expand = null;
        return getWithResponse(resourceGroupName, peeringServiceName, prefixName, expand, Context.NONE).getValue();
    }

    /**
     * Creates a new prefix with the specified name under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @param peeringServicePrefix The properties needed to create a prefix.
     * @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 peering service prefix class along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<PeeringServicePrefixInner>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String peeringServiceName,
        String prefixName,
        PeeringServicePrefixInner peeringServicePrefix) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (peeringServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter peeringServiceName is required and cannot be null."));
        }
        if (prefixName == null) {
            return Mono.error(new IllegalArgumentException("Parameter prefixName 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 (peeringServicePrefix == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter peeringServicePrefix is required and cannot be null."));
        } else {
            peeringServicePrefix.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            peeringServiceName,
                            prefixName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            peeringServicePrefix,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates a new prefix with the specified name under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @param peeringServicePrefix The properties needed to create a prefix.
     * @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 peering service prefix class along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<PeeringServicePrefixInner>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String peeringServiceName,
        String prefixName,
        PeeringServicePrefixInner peeringServicePrefix,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (peeringServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter peeringServiceName is required and cannot be null."));
        }
        if (prefixName == null) {
            return Mono.error(new IllegalArgumentException("Parameter prefixName 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 (peeringServicePrefix == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter peeringServicePrefix is required and cannot be null."));
        } else {
            peeringServicePrefix.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                resourceGroupName,
                peeringServiceName,
                prefixName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                peeringServicePrefix,
                accept,
                context);
    }

    /**
     * Creates a new prefix with the specified name under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @param peeringServicePrefix The properties needed to create a prefix.
     * @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 peering service prefix class on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PeeringServicePrefixInner> createOrUpdateAsync(
        String resourceGroupName,
        String peeringServiceName,
        String prefixName,
        PeeringServicePrefixInner peeringServicePrefix) {
        return createOrUpdateWithResponseAsync(resourceGroupName, peeringServiceName, prefixName, peeringServicePrefix)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates a new prefix with the specified name under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @param peeringServicePrefix The properties needed to create a prefix.
     * @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 peering service prefix class along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<PeeringServicePrefixInner> createOrUpdateWithResponse(
        String resourceGroupName,
        String peeringServiceName,
        String prefixName,
        PeeringServicePrefixInner peeringServicePrefix,
        Context context) {
        return createOrUpdateWithResponseAsync(
                resourceGroupName, peeringServiceName, prefixName, peeringServicePrefix, context)
            .block();
    }

    /**
     * Creates a new prefix with the specified name under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @param peeringServicePrefix The properties needed to create a prefix.
     * @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 peering service prefix class.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PeeringServicePrefixInner createOrUpdate(
        String resourceGroupName,
        String peeringServiceName,
        String prefixName,
        PeeringServicePrefixInner peeringServicePrefix) {
        return createOrUpdateWithResponse(
                resourceGroupName, peeringServiceName, prefixName, peeringServicePrefix, Context.NONE)
            .getValue();
    }

    /**
     * Deletes an existing prefix with the specified name under the given subscription, resource group and peering
     * service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(
        String resourceGroupName, String peeringServiceName, String prefixName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (peeringServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter peeringServiceName is required and cannot be null."));
        }
        if (prefixName == null) {
            return Mono.error(new IllegalArgumentException("Parameter prefixName 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
                        .delete(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            peeringServiceName,
                            prefixName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes an existing prefix with the specified name under the given subscription, resource group and peering
     * service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(
        String resourceGroupName, String peeringServiceName, String prefixName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (peeringServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter peeringServiceName is required and cannot be null."));
        }
        if (prefixName == null) {
            return Mono.error(new IllegalArgumentException("Parameter prefixName 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
            .delete(
                this.client.getEndpoint(),
                resourceGroupName,
                peeringServiceName,
                prefixName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Deletes an existing prefix with the specified name under the given subscription, resource group and peering
     * service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String peeringServiceName, String prefixName) {
        return deleteWithResponseAsync(resourceGroupName, peeringServiceName, prefixName)
            .flatMap(ignored -> Mono.empty());
    }

    /**
     * Deletes an existing prefix with the specified name under the given subscription, resource group and peering
     * service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(
        String resourceGroupName, String peeringServiceName, String prefixName, Context context) {
        return deleteWithResponseAsync(resourceGroupName, peeringServiceName, prefixName, context).block();
    }

    /**
     * Deletes an existing prefix with the specified name under the given subscription, resource group and peering
     * service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param prefixName The name of the prefix.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String peeringServiceName, String prefixName) {
        deleteWithResponse(resourceGroupName, peeringServiceName, prefixName, Context.NONE);
    }

    /**
     * Lists all prefixes under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param expand The properties to be expanded.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated list of peering service prefixes along with {@link PagedResponse} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PeeringServicePrefixInner>> listByPeeringServiceSinglePageAsync(
        String resourceGroupName, String peeringServiceName, String expand) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (peeringServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter peeringServiceName 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
                        .listByPeeringService(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            peeringServiceName,
                            expand,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<PeeringServicePrefixInner>>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 prefixes under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param expand The properties to be expanded.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated list of peering service prefixes along with {@link PagedResponse} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PeeringServicePrefixInner>> listByPeeringServiceSinglePageAsync(
        String resourceGroupName, String peeringServiceName, String expand, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (peeringServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter peeringServiceName 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
            .listByPeeringService(
                this.client.getEndpoint(),
                resourceGroupName,
                peeringServiceName,
                expand,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Lists all prefixes under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param expand The properties to be expanded.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated list of peering service prefixes as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PeeringServicePrefixInner> listByPeeringServiceAsync(
        String resourceGroupName, String peeringServiceName, String expand) {
        return new PagedFlux<>(
            () -> listByPeeringServiceSinglePageAsync(resourceGroupName, peeringServiceName, expand),
            nextLink -> listByPeeringServiceNextSinglePageAsync(nextLink));
    }

    /**
     * Lists all prefixes under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated list of peering service prefixes as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PeeringServicePrefixInner> listByPeeringServiceAsync(
        String resourceGroupName, String peeringServiceName) {
        final String expand = null;
        return new PagedFlux<>(
            () -> listByPeeringServiceSinglePageAsync(resourceGroupName, peeringServiceName, expand),
            nextLink -> listByPeeringServiceNextSinglePageAsync(nextLink));
    }

    /**
     * Lists all prefixes under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param expand The properties to be expanded.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated list of peering service prefixes as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<PeeringServicePrefixInner> listByPeeringServiceAsync(
        String resourceGroupName, String peeringServiceName, String expand, Context context) {
        return new PagedFlux<>(
            () -> listByPeeringServiceSinglePageAsync(resourceGroupName, peeringServiceName, expand, context),
            nextLink -> listByPeeringServiceNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists all prefixes under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated list of peering service prefixes as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PeeringServicePrefixInner> listByPeeringService(
        String resourceGroupName, String peeringServiceName) {
        final String expand = null;
        return new PagedIterable<>(listByPeeringServiceAsync(resourceGroupName, peeringServiceName, expand));
    }

    /**
     * Lists all prefixes under the given subscription, resource group and peering service.
     *
     * @param resourceGroupName The name of the resource group.
     * @param peeringServiceName The name of the peering service.
     * @param expand The properties to be expanded.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated list of peering service prefixes as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<PeeringServicePrefixInner> listByPeeringService(
        String resourceGroupName, String peeringServiceName, String expand, Context context) {
        return new PagedIterable<>(listByPeeringServiceAsync(resourceGroupName, peeringServiceName, expand, context));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated list of peering service prefixes along with {@link PagedResponse} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PeeringServicePrefixInner>> listByPeeringServiceNextSinglePageAsync(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.listByPeeringServiceNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<PeeringServicePrefixInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated list of peering service prefixes along with {@link PagedResponse} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<PeeringServicePrefixInner>> listByPeeringServiceNextSinglePageAsync(
        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
            .listByPeeringServiceNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
