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

package com.azure.resourcemanager.reservations.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.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.reservations.fluent.QuotasClient;
import com.azure.resourcemanager.reservations.fluent.models.CurrentQuotaLimitBaseInner;
import com.azure.resourcemanager.reservations.models.QuotasGetResponse;
import com.azure.resourcemanager.reservations.models.QuotasListNextResponse;
import com.azure.resourcemanager.reservations.models.QuotasListResponse;
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 QuotasClient. */
public final class QuotasClientImpl implements QuotasClient {
    /** The proxy service used to perform REST calls. */
    private final QuotasService service;

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

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

    /**
     * The interface defining all the services for AzureReservationApiQuotas to be used by the proxy service to perform
     * REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "AzureReservationApiQ")
    public interface QuotasService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/providers/Microsoft.Capacity/resourceProviders/{providerId}/locations/{location}/serviceLimits/{resourceName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<QuotasGetResponse> get(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("providerId") String providerId,
            @PathParam("location") String location,
            @QueryParam("api-version") String apiVersion,
            @PathParam("resourceName") String resourceName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/providers/Microsoft.Capacity/resourceProviders/{providerId}/locations/{location}/serviceLimits/{resourceName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("providerId") String providerId,
            @PathParam("location") String location,
            @PathParam("resourceName") String resourceName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") CurrentQuotaLimitBaseInner createQuotaRequest,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/providers/Microsoft.Capacity/resourceProviders/{providerId}/locations/{location}/serviceLimits/{resourceName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> update(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("providerId") String providerId,
            @PathParam("location") String location,
            @PathParam("resourceName") String resourceName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") CurrentQuotaLimitBaseInner createQuotaRequest,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

    /**
     * Get the current quota (service limit) and usage of a resource. You can use the response from the GET operation to
     * submit quota update request.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @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 current quota (service limit) and usage of a resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<QuotasGetResponse> getWithResponseAsync(
        String subscriptionId, String providerId, String location, String resourceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (providerId == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerId is required and cannot be null."));
        }
        if (location == null) {
            return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        final String apiVersion = "2020-10-25";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            subscriptionId,
                            providerId,
                            location,
                            apiVersion,
                            resourceName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the current quota (service limit) and usage of a resource. You can use the response from the GET operation to
     * submit quota update request.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @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 current quota (service limit) and usage of a resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<QuotasGetResponse> getWithResponseAsync(
        String subscriptionId, String providerId, String location, String resourceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (providerId == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerId is required and cannot be null."));
        }
        if (location == null) {
            return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        final String apiVersion = "2020-10-25";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                subscriptionId,
                providerId,
                location,
                apiVersion,
                resourceName,
                accept,
                context);
    }

    /**
     * Get the current quota (service limit) and usage of a resource. You can use the response from the GET operation to
     * submit quota update request.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @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 current quota (service limit) and usage of a resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CurrentQuotaLimitBaseInner> getAsync(
        String subscriptionId, String providerId, String location, String resourceName) {
        return getWithResponseAsync(subscriptionId, providerId, location, resourceName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get the current quota (service limit) and usage of a resource. You can use the response from the GET operation to
     * submit quota update request.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @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 current quota (service limit) and usage of a resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public QuotasGetResponse getWithResponse(
        String subscriptionId, String providerId, String location, String resourceName, Context context) {
        return getWithResponseAsync(subscriptionId, providerId, location, resourceName, context).block();
    }

    /**
     * Get the current quota (service limit) and usage of a resource. You can use the response from the GET operation to
     * submit quota update request.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @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 current quota (service limit) and usage of a resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CurrentQuotaLimitBaseInner get(
        String subscriptionId, String providerId, String location, String resourceName) {
        return getWithResponse(subscriptionId, providerId, location, resourceName, Context.NONE).getValue();
    }

    /**
     * Create or update the quota (service limits) of a resource to the requested value. Steps: 1. Make the Get request
     * to get the quota information for specific resource. 2. To increase the quota, update the limit field in the
     * response from Get request to new value. 3. Submit the JSON to the quota request API to update the quota. The
     * Create quota request may be constructed as follows. The PUT operation can be used to update the quota.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Quota requests payload.
     * @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 quota properties along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (providerId == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerId is required and cannot be null."));
        }
        if (location == null) {
            return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (createQuotaRequest == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter createQuotaRequest is required and cannot be null."));
        } else {
            createQuotaRequest.validate();
        }
        final String apiVersion = "2020-10-25";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            subscriptionId,
                            providerId,
                            location,
                            resourceName,
                            apiVersion,
                            createQuotaRequest,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create or update the quota (service limits) of a resource to the requested value. Steps: 1. Make the Get request
     * to get the quota information for specific resource. 2. To increase the quota, update the limit field in the
     * response from Get request to new value. 3. Submit the JSON to the quota request API to update the quota. The
     * Create quota request may be constructed as follows. The PUT operation can be used to update the quota.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Quota requests payload.
     * @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 quota properties along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (providerId == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerId is required and cannot be null."));
        }
        if (location == null) {
            return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (createQuotaRequest == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter createQuotaRequest is required and cannot be null."));
        } else {
            createQuotaRequest.validate();
        }
        final String apiVersion = "2020-10-25";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                subscriptionId,
                providerId,
                location,
                resourceName,
                apiVersion,
                createQuotaRequest,
                accept,
                context);
    }

    /**
     * Create or update the quota (service limits) of a resource to the requested value. Steps: 1. Make the Get request
     * to get the quota information for specific resource. 2. To increase the quota, update the limit field in the
     * response from Get request to new value. 3. Submit the JSON to the quota request API to update the quota. The
     * Create quota request may be constructed as follows. The PUT operation can be used to update the quota.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Quota requests payload.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CurrentQuotaLimitBaseInner>, CurrentQuotaLimitBaseInner> beginCreateOrUpdateAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest);
        return this
            .client
            .<CurrentQuotaLimitBaseInner, CurrentQuotaLimitBaseInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CurrentQuotaLimitBaseInner.class,
                CurrentQuotaLimitBaseInner.class,
                this.client.getContext());
    }

    /**
     * Create or update the quota (service limits) of a resource to the requested value. Steps: 1. Make the Get request
     * to get the quota information for specific resource. 2. To increase the quota, update the limit field in the
     * response from Get request to new value. 3. Submit the JSON to the quota request API to update the quota. The
     * Create quota request may be constructed as follows. The PUT operation can be used to update the quota.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Quota requests payload.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CurrentQuotaLimitBaseInner>, CurrentQuotaLimitBaseInner> beginCreateOrUpdateAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                subscriptionId, providerId, location, resourceName, createQuotaRequest, context);
        return this
            .client
            .<CurrentQuotaLimitBaseInner, CurrentQuotaLimitBaseInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CurrentQuotaLimitBaseInner.class,
                CurrentQuotaLimitBaseInner.class,
                context);
    }

    /**
     * Create or update the quota (service limits) of a resource to the requested value. Steps: 1. Make the Get request
     * to get the quota information for specific resource. 2. To increase the quota, update the limit field in the
     * response from Get request to new value. 3. Submit the JSON to the quota request API to update the quota. The
     * Create quota request may be constructed as follows. The PUT operation can be used to update the quota.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Quota requests payload.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CurrentQuotaLimitBaseInner>, CurrentQuotaLimitBaseInner> beginCreateOrUpdate(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest) {
        return this
            .beginCreateOrUpdateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest)
            .getSyncPoller();
    }

    /**
     * Create or update the quota (service limits) of a resource to the requested value. Steps: 1. Make the Get request
     * to get the quota information for specific resource. 2. To increase the quota, update the limit field in the
     * response from Get request to new value. 3. Submit the JSON to the quota request API to update the quota. The
     * Create quota request may be constructed as follows. The PUT operation can be used to update the quota.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Quota requests payload.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CurrentQuotaLimitBaseInner>, CurrentQuotaLimitBaseInner> beginCreateOrUpdate(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest,
        Context context) {
        return this
            .beginCreateOrUpdateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest, context)
            .getSyncPoller();
    }

    /**
     * Create or update the quota (service limits) of a resource to the requested value. Steps: 1. Make the Get request
     * to get the quota information for specific resource. 2. To increase the quota, update the limit field in the
     * response from Get request to new value. 3. Submit the JSON to the quota request API to update the quota. The
     * Create quota request may be constructed as follows. The PUT operation can be used to update the quota.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Quota requests payload.
     * @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 quota properties on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CurrentQuotaLimitBaseInner> createOrUpdateAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest) {
        return beginCreateOrUpdateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update the quota (service limits) of a resource to the requested value. Steps: 1. Make the Get request
     * to get the quota information for specific resource. 2. To increase the quota, update the limit field in the
     * response from Get request to new value. 3. Submit the JSON to the quota request API to update the quota. The
     * Create quota request may be constructed as follows. The PUT operation can be used to update the quota.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Quota requests payload.
     * @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 quota properties on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CurrentQuotaLimitBaseInner> createOrUpdateAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest,
        Context context) {
        return beginCreateOrUpdateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update the quota (service limits) of a resource to the requested value. Steps: 1. Make the Get request
     * to get the quota information for specific resource. 2. To increase the quota, update the limit field in the
     * response from Get request to new value. 3. Submit the JSON to the quota request API to update the quota. The
     * Create quota request may be constructed as follows. The PUT operation can be used to update the quota.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Quota requests payload.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CurrentQuotaLimitBaseInner createOrUpdate(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest) {
        return createOrUpdateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest).block();
    }

    /**
     * Create or update the quota (service limits) of a resource to the requested value. Steps: 1. Make the Get request
     * to get the quota information for specific resource. 2. To increase the quota, update the limit field in the
     * response from Get request to new value. 3. Submit the JSON to the quota request API to update the quota. The
     * Create quota request may be constructed as follows. The PUT operation can be used to update the quota.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Quota requests payload.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CurrentQuotaLimitBaseInner createOrUpdate(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest,
        Context context) {
        return createOrUpdateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest, context)
            .block();
    }

    /**
     * Update the quota (service limits) of this resource to the requested value. • To get the quota information for
     * specific resource, send a GET request. • To increase the quota, update the limit field from the GET response to a
     * new value. • To update the quota value, submit the JSON response to the quota request API to update the quota. •
     * To update the quota. use the PATCH operation.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Payload for the quota request.
     * @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 quota properties along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (providerId == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerId is required and cannot be null."));
        }
        if (location == null) {
            return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (createQuotaRequest == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter createQuotaRequest is required and cannot be null."));
        } else {
            createQuotaRequest.validate();
        }
        final String apiVersion = "2020-10-25";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            subscriptionId,
                            providerId,
                            location,
                            resourceName,
                            apiVersion,
                            createQuotaRequest,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Update the quota (service limits) of this resource to the requested value. • To get the quota information for
     * specific resource, send a GET request. • To increase the quota, update the limit field from the GET response to a
     * new value. • To update the quota value, submit the JSON response to the quota request API to update the quota. •
     * To update the quota. use the PATCH operation.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Payload for the quota request.
     * @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 quota properties along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (providerId == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerId is required and cannot be null."));
        }
        if (location == null) {
            return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null."));
        }
        if (resourceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceName is required and cannot be null."));
        }
        if (createQuotaRequest == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter createQuotaRequest is required and cannot be null."));
        } else {
            createQuotaRequest.validate();
        }
        final String apiVersion = "2020-10-25";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                subscriptionId,
                providerId,
                location,
                resourceName,
                apiVersion,
                createQuotaRequest,
                accept,
                context);
    }

    /**
     * Update the quota (service limits) of this resource to the requested value. • To get the quota information for
     * specific resource, send a GET request. • To increase the quota, update the limit field from the GET response to a
     * new value. • To update the quota value, submit the JSON response to the quota request API to update the quota. •
     * To update the quota. use the PATCH operation.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Payload for the quota request.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CurrentQuotaLimitBaseInner>, CurrentQuotaLimitBaseInner> beginUpdateAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest);
        return this
            .client
            .<CurrentQuotaLimitBaseInner, CurrentQuotaLimitBaseInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CurrentQuotaLimitBaseInner.class,
                CurrentQuotaLimitBaseInner.class,
                this.client.getContext());
    }

    /**
     * Update the quota (service limits) of this resource to the requested value. • To get the quota information for
     * specific resource, send a GET request. • To increase the quota, update the limit field from the GET response to a
     * new value. • To update the quota value, submit the JSON response to the quota request API to update the quota. •
     * To update the quota. use the PATCH operation.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Payload for the quota request.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CurrentQuotaLimitBaseInner>, CurrentQuotaLimitBaseInner> beginUpdateAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest, context);
        return this
            .client
            .<CurrentQuotaLimitBaseInner, CurrentQuotaLimitBaseInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CurrentQuotaLimitBaseInner.class,
                CurrentQuotaLimitBaseInner.class,
                context);
    }

    /**
     * Update the quota (service limits) of this resource to the requested value. • To get the quota information for
     * specific resource, send a GET request. • To increase the quota, update the limit field from the GET response to a
     * new value. • To update the quota value, submit the JSON response to the quota request API to update the quota. •
     * To update the quota. use the PATCH operation.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Payload for the quota request.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CurrentQuotaLimitBaseInner>, CurrentQuotaLimitBaseInner> beginUpdate(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest) {
        return this
            .beginUpdateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest)
            .getSyncPoller();
    }

    /**
     * Update the quota (service limits) of this resource to the requested value. • To get the quota information for
     * specific resource, send a GET request. • To increase the quota, update the limit field from the GET response to a
     * new value. • To update the quota value, submit the JSON response to the quota request API to update the quota. •
     * To update the quota. use the PATCH operation.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Payload for the quota request.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CurrentQuotaLimitBaseInner>, CurrentQuotaLimitBaseInner> beginUpdate(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest,
        Context context) {
        return this
            .beginUpdateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest, context)
            .getSyncPoller();
    }

    /**
     * Update the quota (service limits) of this resource to the requested value. • To get the quota information for
     * specific resource, send a GET request. • To increase the quota, update the limit field from the GET response to a
     * new value. • To update the quota value, submit the JSON response to the quota request API to update the quota. •
     * To update the quota. use the PATCH operation.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Payload for the quota request.
     * @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 quota properties on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CurrentQuotaLimitBaseInner> updateAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest) {
        return beginUpdateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Update the quota (service limits) of this resource to the requested value. • To get the quota information for
     * specific resource, send a GET request. • To increase the quota, update the limit field from the GET response to a
     * new value. • To update the quota value, submit the JSON response to the quota request API to update the quota. •
     * To update the quota. use the PATCH operation.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Payload for the quota request.
     * @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 quota properties on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CurrentQuotaLimitBaseInner> updateAsync(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest,
        Context context) {
        return beginUpdateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Update the quota (service limits) of this resource to the requested value. • To get the quota information for
     * specific resource, send a GET request. • To increase the quota, update the limit field from the GET response to a
     * new value. • To update the quota value, submit the JSON response to the quota request API to update the quota. •
     * To update the quota. use the PATCH operation.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Payload for the quota request.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CurrentQuotaLimitBaseInner update(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest) {
        return updateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest).block();
    }

    /**
     * Update the quota (service limits) of this resource to the requested value. • To get the quota information for
     * specific resource, send a GET request. • To increase the quota, update the limit field from the GET response to a
     * new value. • To update the quota value, submit the JSON response to the quota request API to update the quota. •
     * To update the quota. use the PATCH operation.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param resourceName The resource name for a resource provider, such as SKU name for Microsoft.Compute, Sku or
     *     TotalLowPriorityCores for Microsoft.MachineLearningServices.
     * @param createQuotaRequest Payload for the quota request.
     * @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 quota properties.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CurrentQuotaLimitBaseInner update(
        String subscriptionId,
        String providerId,
        String location,
        String resourceName,
        CurrentQuotaLimitBaseInner createQuotaRequest,
        Context context) {
        return updateAsync(subscriptionId, providerId, location, resourceName, createQuotaRequest, context).block();
    }

    /**
     * Gets a list of current quotas (service limits) and usage for all resources. The response from the list quota
     * operation can be leveraged to request quota updates.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of current quotas (service limits) and usage for all resources along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CurrentQuotaLimitBaseInner>> listSinglePageAsync(
        String subscriptionId, String providerId, String location) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (providerId == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerId is required and cannot be null."));
        }
        if (location == null) {
            return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null."));
        }
        final String apiVersion = "2020-10-25";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            subscriptionId,
                            providerId,
                            location,
                            apiVersion,
                            accept,
                            context))
            .<PagedResponse<CurrentQuotaLimitBaseInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        res.getDeserializedHeaders()))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets a list of current quotas (service limits) and usage for all resources. The response from the list quota
     * operation can be leveraged to request quota updates.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of current quotas (service limits) and usage for all resources along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CurrentQuotaLimitBaseInner>> listSinglePageAsync(
        String subscriptionId, String providerId, String location, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (subscriptionId == null) {
            return Mono.error(new IllegalArgumentException("Parameter subscriptionId is required and cannot be null."));
        }
        if (providerId == null) {
            return Mono.error(new IllegalArgumentException("Parameter providerId is required and cannot be null."));
        }
        if (location == null) {
            return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null."));
        }
        final String apiVersion = "2020-10-25";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(this.client.getEndpoint(), subscriptionId, providerId, location, apiVersion, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        res.getDeserializedHeaders()));
    }

    /**
     * Gets a list of current quotas (service limits) and usage for all resources. The response from the list quota
     * operation can be leveraged to request quota updates.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of current quotas (service limits) and usage for all resources as paginated response with {@link
     *     PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CurrentQuotaLimitBaseInner> listAsync(String subscriptionId, String providerId, String location) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(subscriptionId, providerId, location),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Gets a list of current quotas (service limits) and usage for all resources. The response from the list quota
     * operation can be leveraged to request quota updates.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of current quotas (service limits) and usage for all resources as paginated response with {@link
     *     PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CurrentQuotaLimitBaseInner> listAsync(
        String subscriptionId, String providerId, String location, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(subscriptionId, providerId, location, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets a list of current quotas (service limits) and usage for all resources. The response from the list quota
     * operation can be leveraged to request quota updates.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of current quotas (service limits) and usage for all resources as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CurrentQuotaLimitBaseInner> list(String subscriptionId, String providerId, String location) {
        return new PagedIterable<>(listAsync(subscriptionId, providerId, location));
    }

    /**
     * Gets a list of current quotas (service limits) and usage for all resources. The response from the list quota
     * operation can be leveraged to request quota updates.
     *
     * @param subscriptionId Azure subscription ID.
     * @param providerId Azure resource provider ID.
     * @param location Azure region.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of current quotas (service limits) and usage for all resources as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CurrentQuotaLimitBaseInner> list(
        String subscriptionId, String providerId, String location, Context context) {
        return new PagedIterable<>(listAsync(subscriptionId, providerId, location, 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 quota limits along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CurrentQuotaLimitBaseInner>> 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<CurrentQuotaLimitBaseInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        res.getDeserializedHeaders()))
            .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 quota limits along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CurrentQuotaLimitBaseInner>> 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(),
                        res.getDeserializedHeaders()));
    }
}
