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

package com.azure.resourcemanager.cognitiveservices.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.cognitiveservices.fluent.CommitmentPlansClient;
import com.azure.resourcemanager.cognitiveservices.fluent.models.CommitmentPlanAccountAssociationInner;
import com.azure.resourcemanager.cognitiveservices.fluent.models.CommitmentPlanInner;
import com.azure.resourcemanager.cognitiveservices.models.CommitmentPlanAccountAssociationListResult;
import com.azure.resourcemanager.cognitiveservices.models.CommitmentPlanListResult;
import com.azure.resourcemanager.cognitiveservices.models.PatchResourceTagsAndSku;
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 CommitmentPlansClient. */
public final class CommitmentPlansClientImpl implements CommitmentPlansClient {
    /** The proxy service used to perform REST calls. */
    private final CommitmentPlansService service;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.CognitiveServices"
                + "/commitmentPlans/{commitmentPlanName}/accountAssociations/{commitmentPlanAssociationName}")
        @ExpectedResponses({200, 202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> deleteAssociation(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("commitmentPlanName") String commitmentPlanName,
            @PathParam("commitmentPlanAssociationName") String commitmentPlanAssociationName,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

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

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

    /**
     * Gets the commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @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 commitmentPlans associated with the Cognitive Services account along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CommitmentPlanInner>> listSinglePageAsync(String resourceGroupName, String accountName) {
        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 (accountName == null) {
            return Mono.error(new IllegalArgumentException("Parameter accountName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            accountName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .<PagedResponse<CommitmentPlanInner>>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()));
    }

    /**
     * Gets the commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @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 commitmentPlans associated with the Cognitive Services account along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CommitmentPlanInner>> listSinglePageAsync(
        String resourceGroupName, String accountName, 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 (accountName == null) {
            return Mono.error(new IllegalArgumentException("Parameter accountName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                resourceGroupName,
                accountName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Gets the commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @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 commitmentPlans associated with the Cognitive Services account as paginated response with {@link
     *     PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CommitmentPlanInner> listAsync(String resourceGroupName, String accountName) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, accountName), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Gets the commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @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 commitmentPlans associated with the Cognitive Services account as paginated response with {@link
     *     PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CommitmentPlanInner> listAsync(String resourceGroupName, String accountName, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, accountName, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets the commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @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 commitmentPlans associated with the Cognitive Services account as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CommitmentPlanInner> list(String resourceGroupName, String accountName) {
        return new PagedIterable<>(listAsync(resourceGroupName, accountName));
    }

    /**
     * Gets the commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @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 commitmentPlans associated with the Cognitive Services account as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CommitmentPlanInner> list(String resourceGroupName, String accountName, Context context) {
        return new PagedIterable<>(listAsync(resourceGroupName, accountName, context));
    }

    /**
     * Gets the specified commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 specified commitmentPlans associated with the Cognitive Services account along with {@link Response}
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CommitmentPlanInner>> getWithResponseAsync(
        String resourceGroupName, String accountName, String commitmentPlanName) {
        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 (accountName == null) {
            return Mono.error(new IllegalArgumentException("Parameter accountName 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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            accountName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            commitmentPlanName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets the specified commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 specified commitmentPlans associated with the Cognitive Services account along with {@link Response}
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CommitmentPlanInner>> getWithResponseAsync(
        String resourceGroupName, String accountName, String commitmentPlanName, 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 (accountName == null) {
            return Mono.error(new IllegalArgumentException("Parameter accountName 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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                resourceGroupName,
                accountName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                commitmentPlanName,
                accept,
                context);
    }

    /**
     * Gets the specified commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 specified commitmentPlans associated with the Cognitive Services account on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommitmentPlanInner> getAsync(
        String resourceGroupName, String accountName, String commitmentPlanName) {
        return getWithResponseAsync(resourceGroupName, accountName, commitmentPlanName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets the specified commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 specified commitmentPlans associated with the Cognitive Services account along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CommitmentPlanInner> getWithResponse(
        String resourceGroupName, String accountName, String commitmentPlanName, Context context) {
        return getWithResponseAsync(resourceGroupName, accountName, commitmentPlanName, context).block();
    }

    /**
     * Gets the specified commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 specified commitmentPlans associated with the Cognitive Services account.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommitmentPlanInner get(String resourceGroupName, String accountName, String commitmentPlanName) {
        return getWithResponse(resourceGroupName, accountName, commitmentPlanName, Context.NONE).getValue();
    }

    /**
     * Update the state of specified commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The commitmentPlan properties.
     * @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 cognitive Services account commitment plan along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CommitmentPlanInner>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String accountName, String commitmentPlanName, CommitmentPlanInner commitmentPlan) {
        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 (accountName == null) {
            return Mono.error(new IllegalArgumentException("Parameter accountName 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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        if (commitmentPlan == null) {
            return Mono.error(new IllegalArgumentException("Parameter commitmentPlan is required and cannot be null."));
        } else {
            commitmentPlan.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            accountName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            commitmentPlanName,
                            commitmentPlan,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Update the state of specified commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The commitmentPlan properties.
     * @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 cognitive Services account commitment plan along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CommitmentPlanInner>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String accountName,
        String commitmentPlanName,
        CommitmentPlanInner commitmentPlan,
        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 (accountName == null) {
            return Mono.error(new IllegalArgumentException("Parameter accountName 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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        if (commitmentPlan == null) {
            return Mono.error(new IllegalArgumentException("Parameter commitmentPlan is required and cannot be null."));
        } else {
            commitmentPlan.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                resourceGroupName,
                accountName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                commitmentPlanName,
                commitmentPlan,
                accept,
                context);
    }

    /**
     * Update the state of specified commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The commitmentPlan properties.
     * @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 cognitive Services account commitment plan on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommitmentPlanInner> createOrUpdateAsync(
        String resourceGroupName, String accountName, String commitmentPlanName, CommitmentPlanInner commitmentPlan) {
        return createOrUpdateWithResponseAsync(resourceGroupName, accountName, commitmentPlanName, commitmentPlan)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Update the state of specified commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The commitmentPlan properties.
     * @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 cognitive Services account commitment plan along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CommitmentPlanInner> createOrUpdateWithResponse(
        String resourceGroupName,
        String accountName,
        String commitmentPlanName,
        CommitmentPlanInner commitmentPlan,
        Context context) {
        return createOrUpdateWithResponseAsync(
                resourceGroupName, accountName, commitmentPlanName, commitmentPlan, context)
            .block();
    }

    /**
     * Update the state of specified commitmentPlans associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The commitmentPlan properties.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommitmentPlanInner createOrUpdate(
        String resourceGroupName, String accountName, String commitmentPlanName, CommitmentPlanInner commitmentPlan) {
        return createOrUpdateWithResponse(
                resourceGroupName, accountName, commitmentPlanName, commitmentPlan, Context.NONE)
            .getValue();
    }

    /**
     * Deletes the specified commitmentPlan associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String accountName, String commitmentPlanName) {
        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 (accountName == null) {
            return Mono.error(new IllegalArgumentException("Parameter accountName 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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            accountName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            commitmentPlanName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes the specified commitmentPlan associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String accountName, String commitmentPlanName, 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 (accountName == null) {
            return Mono.error(new IllegalArgumentException("Parameter accountName 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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                resourceGroupName,
                accountName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                commitmentPlanName,
                accept,
                context);
    }

    /**
     * Deletes the specified commitmentPlan associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String accountName, String commitmentPlanName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, accountName, commitmentPlanName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Deletes the specified commitmentPlan associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String accountName, String commitmentPlanName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, accountName, commitmentPlanName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Deletes the specified commitmentPlan associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String accountName, String commitmentPlanName) {
        return this.beginDeleteAsync(resourceGroupName, accountName, commitmentPlanName).getSyncPoller();
    }

    /**
     * Deletes the specified commitmentPlan associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String accountName, String commitmentPlanName, Context context) {
        return this.beginDeleteAsync(resourceGroupName, accountName, commitmentPlanName, context).getSyncPoller();
    }

    /**
     * Deletes the specified commitmentPlan associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 accountName, String commitmentPlanName) {
        return beginDeleteAsync(resourceGroupName, accountName, commitmentPlanName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes the specified commitmentPlan associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(
        String resourceGroupName, String accountName, String commitmentPlanName, Context context) {
        return beginDeleteAsync(resourceGroupName, accountName, commitmentPlanName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes the specified commitmentPlan associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 accountName, String commitmentPlanName) {
        deleteAsync(resourceGroupName, accountName, commitmentPlanName).block();
    }

    /**
     * Deletes the specified commitmentPlan associated with the Cognitive Services account.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param accountName The name of Cognitive Services account.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String accountName, String commitmentPlanName, Context context) {
        deleteAsync(resourceGroupName, accountName, commitmentPlanName, context).block();
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdatePlanWithResponseAsync(
        String resourceGroupName, String commitmentPlanName, CommitmentPlanInner commitmentPlan) {
        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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName 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 (commitmentPlan == null) {
            return Mono.error(new IllegalArgumentException("Parameter commitmentPlan is required and cannot be null."));
        } else {
            commitmentPlan.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdatePlan(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            commitmentPlanName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            commitmentPlan,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdatePlanWithResponseAsync(
        String resourceGroupName, String commitmentPlanName, CommitmentPlanInner commitmentPlan, 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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName 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 (commitmentPlan == null) {
            return Mono.error(new IllegalArgumentException("Parameter commitmentPlan is required and cannot be null."));
        } else {
            commitmentPlan.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdatePlan(
                this.client.getEndpoint(),
                resourceGroupName,
                commitmentPlanName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                commitmentPlan,
                accept,
                context);
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CommitmentPlanInner>, CommitmentPlanInner> beginCreateOrUpdatePlanAsync(
        String resourceGroupName, String commitmentPlanName, CommitmentPlanInner commitmentPlan) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdatePlanWithResponseAsync(resourceGroupName, commitmentPlanName, commitmentPlan);
        return this
            .client
            .<CommitmentPlanInner, CommitmentPlanInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommitmentPlanInner.class,
                CommitmentPlanInner.class,
                this.client.getContext());
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CommitmentPlanInner>, CommitmentPlanInner> beginCreateOrUpdatePlanAsync(
        String resourceGroupName, String commitmentPlanName, CommitmentPlanInner commitmentPlan, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdatePlanWithResponseAsync(resourceGroupName, commitmentPlanName, commitmentPlan, context);
        return this
            .client
            .<CommitmentPlanInner, CommitmentPlanInner>getLroResult(
                mono, this.client.getHttpPipeline(), CommitmentPlanInner.class, CommitmentPlanInner.class, context);
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CommitmentPlanInner>, CommitmentPlanInner> beginCreateOrUpdatePlan(
        String resourceGroupName, String commitmentPlanName, CommitmentPlanInner commitmentPlan) {
        return this.beginCreateOrUpdatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan).getSyncPoller();
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CommitmentPlanInner>, CommitmentPlanInner> beginCreateOrUpdatePlan(
        String resourceGroupName, String commitmentPlanName, CommitmentPlanInner commitmentPlan, Context context) {
        return this
            .beginCreateOrUpdatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan, context)
            .getSyncPoller();
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommitmentPlanInner> createOrUpdatePlanAsync(
        String resourceGroupName, String commitmentPlanName, CommitmentPlanInner commitmentPlan) {
        return beginCreateOrUpdatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommitmentPlanInner> createOrUpdatePlanAsync(
        String resourceGroupName, String commitmentPlanName, CommitmentPlanInner commitmentPlan, Context context) {
        return beginCreateOrUpdatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommitmentPlanInner createOrUpdatePlan(
        String resourceGroupName, String commitmentPlanName, CommitmentPlanInner commitmentPlan) {
        return createOrUpdatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan).block();
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommitmentPlanInner createOrUpdatePlan(
        String resourceGroupName, String commitmentPlanName, CommitmentPlanInner commitmentPlan, Context context) {
        return createOrUpdatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan, context).block();
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updatePlanWithResponseAsync(
        String resourceGroupName, String commitmentPlanName, PatchResourceTagsAndSku commitmentPlan) {
        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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName 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 (commitmentPlan == null) {
            return Mono.error(new IllegalArgumentException("Parameter commitmentPlan is required and cannot be null."));
        } else {
            commitmentPlan.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .updatePlan(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            commitmentPlanName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            commitmentPlan,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updatePlanWithResponseAsync(
        String resourceGroupName, String commitmentPlanName, PatchResourceTagsAndSku commitmentPlan, 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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName 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 (commitmentPlan == null) {
            return Mono.error(new IllegalArgumentException("Parameter commitmentPlan is required and cannot be null."));
        } else {
            commitmentPlan.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .updatePlan(
                this.client.getEndpoint(),
                resourceGroupName,
                commitmentPlanName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                commitmentPlan,
                accept,
                context);
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CommitmentPlanInner>, CommitmentPlanInner> beginUpdatePlanAsync(
        String resourceGroupName, String commitmentPlanName, PatchResourceTagsAndSku commitmentPlan) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updatePlanWithResponseAsync(resourceGroupName, commitmentPlanName, commitmentPlan);
        return this
            .client
            .<CommitmentPlanInner, CommitmentPlanInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommitmentPlanInner.class,
                CommitmentPlanInner.class,
                this.client.getContext());
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CommitmentPlanInner>, CommitmentPlanInner> beginUpdatePlanAsync(
        String resourceGroupName, String commitmentPlanName, PatchResourceTagsAndSku commitmentPlan, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updatePlanWithResponseAsync(resourceGroupName, commitmentPlanName, commitmentPlan, context);
        return this
            .client
            .<CommitmentPlanInner, CommitmentPlanInner>getLroResult(
                mono, this.client.getHttpPipeline(), CommitmentPlanInner.class, CommitmentPlanInner.class, context);
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CommitmentPlanInner>, CommitmentPlanInner> beginUpdatePlan(
        String resourceGroupName, String commitmentPlanName, PatchResourceTagsAndSku commitmentPlan) {
        return this.beginUpdatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan).getSyncPoller();
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CommitmentPlanInner>, CommitmentPlanInner> beginUpdatePlan(
        String resourceGroupName, String commitmentPlanName, PatchResourceTagsAndSku commitmentPlan, Context context) {
        return this
            .beginUpdatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan, context)
            .getSyncPoller();
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommitmentPlanInner> updatePlanAsync(
        String resourceGroupName, String commitmentPlanName, PatchResourceTagsAndSku commitmentPlan) {
        return beginUpdatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommitmentPlanInner> updatePlanAsync(
        String resourceGroupName, String commitmentPlanName, PatchResourceTagsAndSku commitmentPlan, Context context) {
        return beginUpdatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommitmentPlanInner updatePlan(
        String resourceGroupName, String commitmentPlanName, PatchResourceTagsAndSku commitmentPlan) {
        return updatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan).block();
    }

    /**
     * Create Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlan The parameters to provide for the created commitment plan.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommitmentPlanInner updatePlan(
        String resourceGroupName, String commitmentPlanName, PatchResourceTagsAndSku commitmentPlan, Context context) {
        return updatePlanAsync(resourceGroupName, commitmentPlanName, commitmentPlan, context).block();
    }

    /**
     * Deletes a Cognitive Services commitment plan from the resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deletePlanWithResponseAsync(
        String resourceGroupName, String commitmentPlanName) {
        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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName 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
                        .deletePlan(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            commitmentPlanName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes a Cognitive Services commitment plan from the resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deletePlanWithResponseAsync(
        String resourceGroupName, String commitmentPlanName, 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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName 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
            .deletePlan(
                this.client.getEndpoint(),
                resourceGroupName,
                commitmentPlanName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                accept,
                context);
    }

    /**
     * Deletes a Cognitive Services commitment plan from the resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeletePlanAsync(
        String resourceGroupName, String commitmentPlanName) {
        Mono<Response<Flux<ByteBuffer>>> mono = deletePlanWithResponseAsync(resourceGroupName, commitmentPlanName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Deletes a Cognitive Services commitment plan from the resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeletePlanAsync(
        String resourceGroupName, String commitmentPlanName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deletePlanWithResponseAsync(resourceGroupName, commitmentPlanName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Deletes a Cognitive Services commitment plan from the resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDeletePlan(String resourceGroupName, String commitmentPlanName) {
        return this.beginDeletePlanAsync(resourceGroupName, commitmentPlanName).getSyncPoller();
    }

    /**
     * Deletes a Cognitive Services commitment plan from the resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDeletePlan(
        String resourceGroupName, String commitmentPlanName, Context context) {
        return this.beginDeletePlanAsync(resourceGroupName, commitmentPlanName, context).getSyncPoller();
    }

    /**
     * Deletes a Cognitive Services commitment plan from the resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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> deletePlanAsync(String resourceGroupName, String commitmentPlanName) {
        return beginDeletePlanAsync(resourceGroupName, commitmentPlanName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a Cognitive Services commitment plan from the resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deletePlanAsync(String resourceGroupName, String commitmentPlanName, Context context) {
        return beginDeletePlanAsync(resourceGroupName, commitmentPlanName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a Cognitive Services commitment plan from the resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 deletePlan(String resourceGroupName, String commitmentPlanName) {
        deletePlanAsync(resourceGroupName, commitmentPlanName).block();
    }

    /**
     * Deletes a Cognitive Services commitment plan from the resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void deletePlan(String resourceGroupName, String commitmentPlanName, Context context) {
        deletePlanAsync(resourceGroupName, commitmentPlanName, context).block();
    }

    /**
     * Returns a Cognitive Services commitment plan specified by the parameters.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 cognitive Services account commitment plan along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CommitmentPlanInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String commitmentPlanName) {
        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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName 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
                        .getByResourceGroup(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            commitmentPlanName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Returns a Cognitive Services commitment plan specified by the parameters.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 cognitive Services account commitment plan along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CommitmentPlanInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String commitmentPlanName, 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 (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName 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
            .getByResourceGroup(
                this.client.getEndpoint(),
                resourceGroupName,
                commitmentPlanName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                accept,
                context);
    }

    /**
     * Returns a Cognitive Services commitment plan specified by the parameters.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 cognitive Services account commitment plan on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommitmentPlanInner> getByResourceGroupAsync(String resourceGroupName, String commitmentPlanName) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, commitmentPlanName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Returns a Cognitive Services commitment plan specified by the parameters.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 cognitive Services account commitment plan along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CommitmentPlanInner> getByResourceGroupWithResponse(
        String resourceGroupName, String commitmentPlanName, Context context) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, commitmentPlanName, context).block();
    }

    /**
     * Returns a Cognitive Services commitment plan specified by the parameters.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 cognitive Services account commitment plan.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommitmentPlanInner getByResourceGroup(String resourceGroupName, String commitmentPlanName) {
        return getByResourceGroupWithResponse(resourceGroupName, commitmentPlanName, Context.NONE).getValue();
    }

    /**
     * Returns all the resources of a particular type belonging to a resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of cognitive services accounts operation response along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CommitmentPlanInner>> listByResourceGroupSinglePageAsync(String resourceGroupName) {
        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 (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
                        .listByResourceGroup(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<CommitmentPlanInner>>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()));
    }

    /**
     * Returns all the resources of a particular type belonging to a resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of cognitive services accounts operation response along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CommitmentPlanInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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
            .listByResourceGroup(
                this.client.getEndpoint(),
                resourceGroupName,
                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));
    }

    /**
     * Returns all the resources of a particular type belonging to a resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of cognitive services accounts operation response as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CommitmentPlanInner> listByResourceGroupAsync(String resourceGroupName) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName),
            nextLink -> listPlansByResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Returns all the resources of a particular type belonging to a resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of cognitive services accounts operation response as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CommitmentPlanInner> listByResourceGroupAsync(String resourceGroupName, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, context),
            nextLink -> listPlansByResourceGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * Returns all the resources of a particular type belonging to a resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of cognitive services accounts operation response as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CommitmentPlanInner> listByResourceGroup(String resourceGroupName) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName));
    }

    /**
     * Returns all the resources of a particular type belonging to a resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of cognitive services accounts operation response as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CommitmentPlanInner> listByResourceGroup(String resourceGroupName, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, context));
    }

    /**
     * Returns all the resources of a particular type belonging to a subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of cognitive services accounts operation response along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CommitmentPlanInner>> listPlansBySubscriptionSinglePageAsync() {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listPlansBySubscription(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            accept,
                            context))
            .<PagedResponse<CommitmentPlanInner>>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()));
    }

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

    /**
     * Returns all the resources of a particular type belonging to a subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of cognitive services accounts operation response as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CommitmentPlanInner> listPlansBySubscriptionAsync() {
        return new PagedFlux<>(
            () -> listPlansBySubscriptionSinglePageAsync(),
            nextLink -> listPlansBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Returns all the resources of a particular type belonging to a subscription.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of cognitive services accounts operation response as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CommitmentPlanInner> listPlansBySubscriptionAsync(Context context) {
        return new PagedFlux<>(
            () -> listPlansBySubscriptionSinglePageAsync(context),
            nextLink -> listPlansBySubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * Returns all the resources of a particular type belonging to a subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of cognitive services accounts operation response as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CommitmentPlanInner> listPlansBySubscription() {
        return new PagedIterable<>(listPlansBySubscriptionAsync());
    }

    /**
     * Returns all the resources of a particular type belonging to a subscription.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of cognitive services accounts operation response as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CommitmentPlanInner> listPlansBySubscription(Context context) {
        return new PagedIterable<>(listPlansBySubscriptionAsync(context));
    }

    /**
     * Gets the associations of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 associations of the Cognitive Services commitment plan along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CommitmentPlanAccountAssociationInner>> listAssociationsSinglePageAsync(
        String resourceGroupName, String commitmentPlanName) {
        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 (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listAssociations(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            commitmentPlanName,
                            accept,
                            context))
            .<PagedResponse<CommitmentPlanAccountAssociationInner>>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()));
    }

    /**
     * Gets the associations of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 associations of the Cognitive Services commitment plan along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CommitmentPlanAccountAssociationInner>> listAssociationsSinglePageAsync(
        String resourceGroupName, String commitmentPlanName, 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 (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listAssociations(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                commitmentPlanName,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Gets the associations of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 associations of the Cognitive Services commitment plan as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CommitmentPlanAccountAssociationInner> listAssociationsAsync(
        String resourceGroupName, String commitmentPlanName) {
        return new PagedFlux<>(
            () -> listAssociationsSinglePageAsync(resourceGroupName, commitmentPlanName),
            nextLink -> listAssociationsNextSinglePageAsync(nextLink));
    }

    /**
     * Gets the associations of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 associations of the Cognitive Services commitment plan as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<CommitmentPlanAccountAssociationInner> listAssociationsAsync(
        String resourceGroupName, String commitmentPlanName, Context context) {
        return new PagedFlux<>(
            () -> listAssociationsSinglePageAsync(resourceGroupName, commitmentPlanName, context),
            nextLink -> listAssociationsNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets the associations of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 associations of the Cognitive Services commitment plan as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CommitmentPlanAccountAssociationInner> listAssociations(
        String resourceGroupName, String commitmentPlanName) {
        return new PagedIterable<>(listAssociationsAsync(resourceGroupName, commitmentPlanName));
    }

    /**
     * Gets the associations of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @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 associations of the Cognitive Services commitment plan as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<CommitmentPlanAccountAssociationInner> listAssociations(
        String resourceGroupName, String commitmentPlanName, Context context) {
        return new PagedIterable<>(listAssociationsAsync(resourceGroupName, commitmentPlanName, context));
    }

    /**
     * Gets the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @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 association of the Cognitive Services commitment plan along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CommitmentPlanAccountAssociationInner>> getAssociationWithResponseAsync(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName) {
        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 (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        if (commitmentPlanAssociationName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter commitmentPlanAssociationName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getAssociation(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            commitmentPlanName,
                            commitmentPlanAssociationName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @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 association of the Cognitive Services commitment plan along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CommitmentPlanAccountAssociationInner>> getAssociationWithResponseAsync(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName, 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 (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        if (commitmentPlanAssociationName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter commitmentPlanAssociationName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getAssociation(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                commitmentPlanName,
                commitmentPlanAssociationName,
                accept,
                context);
    }

    /**
     * Gets the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @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 association of the Cognitive Services commitment plan on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommitmentPlanAccountAssociationInner> getAssociationAsync(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName) {
        return getAssociationWithResponseAsync(resourceGroupName, commitmentPlanName, commitmentPlanAssociationName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @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 association of the Cognitive Services commitment plan along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CommitmentPlanAccountAssociationInner> getAssociationWithResponse(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName, Context context) {
        return getAssociationWithResponseAsync(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, context)
            .block();
    }

    /**
     * Gets the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @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 association of the Cognitive Services commitment plan.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommitmentPlanAccountAssociationInner getAssociation(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName) {
        return getAssociationWithResponse(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, Context.NONE)
            .getValue();
    }

    /**
     * Create or update the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param association The commitmentPlan properties.
     * @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 commitment plan association along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateAssociationWithResponseAsync(
        String resourceGroupName,
        String commitmentPlanName,
        String commitmentPlanAssociationName,
        CommitmentPlanAccountAssociationInner association) {
        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 (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        if (commitmentPlanAssociationName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter commitmentPlanAssociationName is required and cannot be null."));
        }
        if (association == null) {
            return Mono.error(new IllegalArgumentException("Parameter association is required and cannot be null."));
        } else {
            association.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdateAssociation(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            commitmentPlanName,
                            commitmentPlanAssociationName,
                            association,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create or update the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param association The commitmentPlan properties.
     * @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 commitment plan association along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateAssociationWithResponseAsync(
        String resourceGroupName,
        String commitmentPlanName,
        String commitmentPlanAssociationName,
        CommitmentPlanAccountAssociationInner association,
        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 (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        if (commitmentPlanAssociationName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter commitmentPlanAssociationName is required and cannot be null."));
        }
        if (association == null) {
            return Mono.error(new IllegalArgumentException("Parameter association is required and cannot be null."));
        } else {
            association.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdateAssociation(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                commitmentPlanName,
                commitmentPlanAssociationName,
                association,
                accept,
                context);
    }

    /**
     * Create or update the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param association The commitmentPlan properties.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of the commitment plan association.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CommitmentPlanAccountAssociationInner>, CommitmentPlanAccountAssociationInner>
        beginCreateOrUpdateAssociationAsync(
            String resourceGroupName,
            String commitmentPlanName,
            String commitmentPlanAssociationName,
            CommitmentPlanAccountAssociationInner association) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateAssociationWithResponseAsync(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, association);
        return this
            .client
            .<CommitmentPlanAccountAssociationInner, CommitmentPlanAccountAssociationInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommitmentPlanAccountAssociationInner.class,
                CommitmentPlanAccountAssociationInner.class,
                this.client.getContext());
    }

    /**
     * Create or update the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param association The commitmentPlan properties.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of the commitment plan association.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<CommitmentPlanAccountAssociationInner>, CommitmentPlanAccountAssociationInner>
        beginCreateOrUpdateAssociationAsync(
            String resourceGroupName,
            String commitmentPlanName,
            String commitmentPlanAssociationName,
            CommitmentPlanAccountAssociationInner association,
            Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateAssociationWithResponseAsync(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, association, context);
        return this
            .client
            .<CommitmentPlanAccountAssociationInner, CommitmentPlanAccountAssociationInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                CommitmentPlanAccountAssociationInner.class,
                CommitmentPlanAccountAssociationInner.class,
                context);
    }

    /**
     * Create or update the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param association The commitmentPlan properties.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of the commitment plan association.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CommitmentPlanAccountAssociationInner>, CommitmentPlanAccountAssociationInner>
        beginCreateOrUpdateAssociation(
            String resourceGroupName,
            String commitmentPlanName,
            String commitmentPlanAssociationName,
            CommitmentPlanAccountAssociationInner association) {
        return this
            .beginCreateOrUpdateAssociationAsync(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, association)
            .getSyncPoller();
    }

    /**
     * Create or update the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param association The commitmentPlan properties.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of the commitment plan association.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<CommitmentPlanAccountAssociationInner>, CommitmentPlanAccountAssociationInner>
        beginCreateOrUpdateAssociation(
            String resourceGroupName,
            String commitmentPlanName,
            String commitmentPlanAssociationName,
            CommitmentPlanAccountAssociationInner association,
            Context context) {
        return this
            .beginCreateOrUpdateAssociationAsync(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, association, context)
            .getSyncPoller();
    }

    /**
     * Create or update the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param association The commitmentPlan properties.
     * @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 commitment plan association on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommitmentPlanAccountAssociationInner> createOrUpdateAssociationAsync(
        String resourceGroupName,
        String commitmentPlanName,
        String commitmentPlanAssociationName,
        CommitmentPlanAccountAssociationInner association) {
        return beginCreateOrUpdateAssociationAsync(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, association)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param association The commitmentPlan properties.
     * @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 commitment plan association on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CommitmentPlanAccountAssociationInner> createOrUpdateAssociationAsync(
        String resourceGroupName,
        String commitmentPlanName,
        String commitmentPlanAssociationName,
        CommitmentPlanAccountAssociationInner association,
        Context context) {
        return beginCreateOrUpdateAssociationAsync(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, association, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param association The commitmentPlan properties.
     * @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 commitment plan association.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommitmentPlanAccountAssociationInner createOrUpdateAssociation(
        String resourceGroupName,
        String commitmentPlanName,
        String commitmentPlanAssociationName,
        CommitmentPlanAccountAssociationInner association) {
        return createOrUpdateAssociationAsync(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, association)
            .block();
    }

    /**
     * Create or update the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param association The commitmentPlan properties.
     * @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 commitment plan association.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CommitmentPlanAccountAssociationInner createOrUpdateAssociation(
        String resourceGroupName,
        String commitmentPlanName,
        String commitmentPlanAssociationName,
        CommitmentPlanAccountAssociationInner association,
        Context context) {
        return createOrUpdateAssociationAsync(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, association, context)
            .block();
    }

    /**
     * Deletes the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteAssociationWithResponseAsync(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName) {
        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 (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        if (commitmentPlanAssociationName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter commitmentPlanAssociationName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .deleteAssociation(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            commitmentPlanName,
                            commitmentPlanAssociationName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteAssociationWithResponseAsync(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName, 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 (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (commitmentPlanName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter commitmentPlanName is required and cannot be null."));
        }
        if (commitmentPlanAssociationName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter commitmentPlanAssociationName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .deleteAssociation(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                commitmentPlanName,
                commitmentPlanAssociationName,
                accept,
                context);
    }

    /**
     * Deletes the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAssociationAsync(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteAssociationWithResponseAsync(resourceGroupName, commitmentPlanName, commitmentPlanAssociationName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Deletes the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAssociationAsync(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteAssociationWithResponseAsync(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Deletes the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDeleteAssociation(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName) {
        return this
            .beginDeleteAssociationAsync(resourceGroupName, commitmentPlanName, commitmentPlanAssociationName)
            .getSyncPoller();
    }

    /**
     * Deletes the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDeleteAssociation(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName, Context context) {
        return this
            .beginDeleteAssociationAsync(resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, context)
            .getSyncPoller();
    }

    /**
     * Deletes the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @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> deleteAssociationAsync(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName) {
        return beginDeleteAssociationAsync(resourceGroupName, commitmentPlanName, commitmentPlanAssociationName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAssociationAsync(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName, Context context) {
        return beginDeleteAssociationAsync(
                resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @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 deleteAssociation(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName) {
        deleteAssociationAsync(resourceGroupName, commitmentPlanName, commitmentPlanAssociationName).block();
    }

    /**
     * Deletes the association of the Cognitive Services commitment plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param commitmentPlanName The name of the commitmentPlan associated with the Cognitive Services Account.
     * @param commitmentPlanAssociationName The name of the commitment plan association with the Cognitive Services
     *     Account.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void deleteAssociation(
        String resourceGroupName, String commitmentPlanName, String commitmentPlanAssociationName, Context context) {
        deleteAssociationAsync(resourceGroupName, commitmentPlanName, commitmentPlanAssociationName, context).block();
    }

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

    /**
     * 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 list of cognitive services accounts operation response along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CommitmentPlanInner>> listPlansByResourceGroupNextSinglePageAsync(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.listPlansByResourceGroupNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<CommitmentPlanInner>>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 list of cognitive services accounts operation response along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<CommitmentPlanInner>> listPlansByResourceGroupNextSinglePageAsync(
        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
            .listPlansByResourceGroupNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

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

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