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

package com.azure.resourcemanager.billingbenefits.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Post;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.resourcemanager.billingbenefits.fluent.SavingsPlansClient;
import com.azure.resourcemanager.billingbenefits.fluent.models.SavingsPlanModelInner;
import com.azure.resourcemanager.billingbenefits.fluent.models.SavingsPlanValidateResponseInner;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlanModelList;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlanModelListResult;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlanUpdateRequest;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlanUpdateValidateRequest;
import com.azure.resourcemanager.billingbenefits.models.SavingsPlansUpdateResponse;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for BillingBenefitsRPSavingsPlans to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "BillingBenefitsRPSav")
    public interface SavingsPlansService {
        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.BillingBenefits/savingsPlanOrders/{savingsPlanOrderId}/savingsPlans")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SavingsPlanModelList>> list(
            @HostParam("$host") String endpoint,
            @PathParam("savingsPlanOrderId") String savingsPlanOrderId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.BillingBenefits/savingsPlans")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SavingsPlanModelListResult>> listAll(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$filter") String filter,
            @QueryParam("$orderby") String orderby,
            @QueryParam("refreshSummary") String refreshSummary,
            @QueryParam("$skiptoken") Float skiptoken,
            @QueryParam("selectedState") String selectedState,
            @QueryParam("take") Float take,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.BillingBenefits/savingsPlanOrders/{savingsPlanOrderId}/savingsPlans/{savingsPlanId}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SavingsPlanModelInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("savingsPlanOrderId") String savingsPlanOrderId,
            @PathParam("savingsPlanId") String savingsPlanId,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$expand") String expand,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/providers/Microsoft.BillingBenefits/savingsPlanOrders/{savingsPlanOrderId}/savingsPlans/{savingsPlanId}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<SavingsPlansUpdateResponse> update(
            @HostParam("$host") String endpoint,
            @PathParam("savingsPlanOrderId") String savingsPlanOrderId,
            @PathParam("savingsPlanId") String savingsPlanId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") SavingsPlanUpdateRequest body,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/Microsoft.BillingBenefits/savingsPlanOrders/{savingsPlanOrderId}/savingsPlans/{savingsPlanId}"
                + "/validate")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SavingsPlanValidateResponseInner>> validateUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("savingsPlanOrderId") String savingsPlanOrderId,
            @PathParam("savingsPlanId") String savingsPlanId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") SavingsPlanUpdateValidateRequest body,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * List savings plans in an order.
     *
     * @param savingsPlanOrderId Order ID of the savings 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 response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SavingsPlanModelInner>> listSinglePageAsync(String savingsPlanOrderId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (savingsPlanOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter savingsPlanOrderId is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            savingsPlanOrderId,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<SavingsPlanModelInner>>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()));
    }

    /**
     * List savings plans in an order.
     *
     * @param savingsPlanOrderId Order ID of the savings 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 response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SavingsPlanModelInner>> listSinglePageAsync(String savingsPlanOrderId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (savingsPlanOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter savingsPlanOrderId is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(this.client.getEndpoint(), savingsPlanOrderId, this.client.getApiVersion(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List savings plans in an order.
     *
     * @param savingsPlanOrderId Order ID of the savings 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 paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SavingsPlanModelInner> listAsync(String savingsPlanOrderId) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(savingsPlanOrderId), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * List savings plans in an order.
     *
     * @param savingsPlanOrderId Order ID of the savings 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 paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SavingsPlanModelInner> listAsync(String savingsPlanOrderId, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(savingsPlanOrderId, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * List savings plans in an order.
     *
     * @param savingsPlanOrderId Order ID of the savings 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 paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SavingsPlanModelInner> list(String savingsPlanOrderId) {
        return new PagedIterable<>(listAsync(savingsPlanOrderId));
    }

    /**
     * List savings plans in an order.
     *
     * @param savingsPlanOrderId Order ID of the savings 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 paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SavingsPlanModelInner> list(String savingsPlanOrderId, Context context) {
        return new PagedIterable<>(listAsync(savingsPlanOrderId, context));
    }

    /**
     * List savings plans.
     *
     * @param filter May be used to filter by reservation properties. The filter supports 'eq', 'or', and 'and'. It does
     *     not currently support 'ne', 'gt', 'le', 'ge', or 'not'. Reservation properties include sku/name,
     *     properties/{appliedScopeType, archived, displayName, displayProvisioningState, effectiveDateTime, expiryDate,
     *     provisioningState, quantity, renew, reservedResourceType, term, userFriendlyAppliedScopeType,
     *     userFriendlyRenewState}.
     * @param orderby May be used to sort order by reservation properties.
     * @param refreshSummary To indicate whether to refresh the roll up counts of the savings plans group by
     *     provisioning states.
     * @param skiptoken The number of savings plans to skip from the list before returning results.
     * @param selectedState The selected provisioning state.
     * @param take To number of savings plans to return.
     * @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 response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SavingsPlanModelInner>> listAllSinglePageAsync(
        String filter, String orderby, String refreshSummary, Float skiptoken, String selectedState, Float take) {
        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
                        .listAll(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            filter,
                            orderby,
                            refreshSummary,
                            skiptoken,
                            selectedState,
                            take,
                            accept,
                            context))
            .<PagedResponse<SavingsPlanModelInner>>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()));
    }

    /**
     * List savings plans.
     *
     * @param filter May be used to filter by reservation properties. The filter supports 'eq', 'or', and 'and'. It does
     *     not currently support 'ne', 'gt', 'le', 'ge', or 'not'. Reservation properties include sku/name,
     *     properties/{appliedScopeType, archived, displayName, displayProvisioningState, effectiveDateTime, expiryDate,
     *     provisioningState, quantity, renew, reservedResourceType, term, userFriendlyAppliedScopeType,
     *     userFriendlyRenewState}.
     * @param orderby May be used to sort order by reservation properties.
     * @param refreshSummary To indicate whether to refresh the roll up counts of the savings plans group by
     *     provisioning states.
     * @param skiptoken The number of savings plans to skip from the list before returning results.
     * @param selectedState The selected provisioning state.
     * @param take To number of savings plans to return.
     * @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 response body along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<SavingsPlanModelInner>> listAllSinglePageAsync(
        String filter,
        String orderby,
        String refreshSummary,
        Float skiptoken,
        String selectedState,
        Float take,
        Context context) {
        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
            .listAll(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                filter,
                orderby,
                refreshSummary,
                skiptoken,
                selectedState,
                take,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List savings plans.
     *
     * @param filter May be used to filter by reservation properties. The filter supports 'eq', 'or', and 'and'. It does
     *     not currently support 'ne', 'gt', 'le', 'ge', or 'not'. Reservation properties include sku/name,
     *     properties/{appliedScopeType, archived, displayName, displayProvisioningState, effectiveDateTime, expiryDate,
     *     provisioningState, quantity, renew, reservedResourceType, term, userFriendlyAppliedScopeType,
     *     userFriendlyRenewState}.
     * @param orderby May be used to sort order by reservation properties.
     * @param refreshSummary To indicate whether to refresh the roll up counts of the savings plans group by
     *     provisioning states.
     * @param skiptoken The number of savings plans to skip from the list before returning results.
     * @param selectedState The selected provisioning state.
     * @param take To number of savings plans to return.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SavingsPlanModelInner> listAllAsync(
        String filter, String orderby, String refreshSummary, Float skiptoken, String selectedState, Float take) {
        return new PagedFlux<>(
            () -> listAllSinglePageAsync(filter, orderby, refreshSummary, skiptoken, selectedState, take),
            nextLink -> listAllNextSinglePageAsync(nextLink));
    }

    /**
     * List savings plans.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SavingsPlanModelInner> listAllAsync() {
        final String filter = null;
        final String orderby = null;
        final String refreshSummary = null;
        final Float skiptoken = null;
        final String selectedState = null;
        final Float take = null;
        return new PagedFlux<>(
            () -> listAllSinglePageAsync(filter, orderby, refreshSummary, skiptoken, selectedState, take),
            nextLink -> listAllNextSinglePageAsync(nextLink));
    }

    /**
     * List savings plans.
     *
     * @param filter May be used to filter by reservation properties. The filter supports 'eq', 'or', and 'and'. It does
     *     not currently support 'ne', 'gt', 'le', 'ge', or 'not'. Reservation properties include sku/name,
     *     properties/{appliedScopeType, archived, displayName, displayProvisioningState, effectiveDateTime, expiryDate,
     *     provisioningState, quantity, renew, reservedResourceType, term, userFriendlyAppliedScopeType,
     *     userFriendlyRenewState}.
     * @param orderby May be used to sort order by reservation properties.
     * @param refreshSummary To indicate whether to refresh the roll up counts of the savings plans group by
     *     provisioning states.
     * @param skiptoken The number of savings plans to skip from the list before returning results.
     * @param selectedState The selected provisioning state.
     * @param take To number of savings plans to return.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<SavingsPlanModelInner> listAllAsync(
        String filter,
        String orderby,
        String refreshSummary,
        Float skiptoken,
        String selectedState,
        Float take,
        Context context) {
        return new PagedFlux<>(
            () -> listAllSinglePageAsync(filter, orderby, refreshSummary, skiptoken, selectedState, take, context),
            nextLink -> listAllNextSinglePageAsync(nextLink, context));
    }

    /**
     * List savings plans.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SavingsPlanModelInner> listAll() {
        final String filter = null;
        final String orderby = null;
        final String refreshSummary = null;
        final Float skiptoken = null;
        final String selectedState = null;
        final Float take = null;
        return new PagedIterable<>(listAllAsync(filter, orderby, refreshSummary, skiptoken, selectedState, take));
    }

    /**
     * List savings plans.
     *
     * @param filter May be used to filter by reservation properties. The filter supports 'eq', 'or', and 'and'. It does
     *     not currently support 'ne', 'gt', 'le', 'ge', or 'not'. Reservation properties include sku/name,
     *     properties/{appliedScopeType, archived, displayName, displayProvisioningState, effectiveDateTime, expiryDate,
     *     provisioningState, quantity, renew, reservedResourceType, term, userFriendlyAppliedScopeType,
     *     userFriendlyRenewState}.
     * @param orderby May be used to sort order by reservation properties.
     * @param refreshSummary To indicate whether to refresh the roll up counts of the savings plans group by
     *     provisioning states.
     * @param skiptoken The number of savings plans to skip from the list before returning results.
     * @param selectedState The selected provisioning state.
     * @param take To number of savings plans to return.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<SavingsPlanModelInner> listAll(
        String filter,
        String orderby,
        String refreshSummary,
        Float skiptoken,
        String selectedState,
        Float take,
        Context context) {
        return new PagedIterable<>(
            listAllAsync(filter, orderby, refreshSummary, skiptoken, selectedState, take, context));
    }

    /**
     * Get savings plan.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param expand May be used to expand the detail information of some 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 savings plan along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SavingsPlanModelInner>> getWithResponseAsync(
        String savingsPlanOrderId, String savingsPlanId, String expand) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (savingsPlanOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter savingsPlanOrderId is required and cannot be null."));
        }
        if (savingsPlanId == null) {
            return Mono.error(new IllegalArgumentException("Parameter savingsPlanId is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            savingsPlanOrderId,
                            savingsPlanId,
                            this.client.getApiVersion(),
                            expand,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get savings plan.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param expand May be used to expand the detail information of some 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 savings plan along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SavingsPlanModelInner>> getWithResponseAsync(
        String savingsPlanOrderId, String savingsPlanId, String expand, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (savingsPlanOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter savingsPlanOrderId is required and cannot be null."));
        }
        if (savingsPlanId == null) {
            return Mono.error(new IllegalArgumentException("Parameter savingsPlanId is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                savingsPlanOrderId,
                savingsPlanId,
                this.client.getApiVersion(),
                expand,
                accept,
                context);
    }

    /**
     * Get savings plan.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings 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 savings plan on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SavingsPlanModelInner> getAsync(String savingsPlanOrderId, String savingsPlanId) {
        final String expand = null;
        return getWithResponseAsync(savingsPlanOrderId, savingsPlanId, expand)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get savings plan.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param expand May be used to expand the detail information of some 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 savings plan along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SavingsPlanModelInner> getWithResponse(
        String savingsPlanOrderId, String savingsPlanId, String expand, Context context) {
        return getWithResponseAsync(savingsPlanOrderId, savingsPlanId, expand, context).block();
    }

    /**
     * Get savings plan.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings 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 savings plan.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SavingsPlanModelInner get(String savingsPlanOrderId, String savingsPlanId) {
        final String expand = null;
        return getWithResponse(savingsPlanOrderId, savingsPlanId, expand, Context.NONE).getValue();
    }

    /**
     * Update savings plan.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param body Request body for patching a savings plan order alias.
     * @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 savings plan on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SavingsPlansUpdateResponse> updateWithResponseAsync(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateRequest body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (savingsPlanOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter savingsPlanOrderId is required and cannot be null."));
        }
        if (savingsPlanId == null) {
            return Mono.error(new IllegalArgumentException("Parameter savingsPlanId is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            savingsPlanOrderId,
                            savingsPlanId,
                            this.client.getApiVersion(),
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Update savings plan.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param body Request body for patching a savings plan order alias.
     * @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 savings plan on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SavingsPlansUpdateResponse> updateWithResponseAsync(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateRequest body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (savingsPlanOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter savingsPlanOrderId is required and cannot be null."));
        }
        if (savingsPlanId == null) {
            return Mono.error(new IllegalArgumentException("Parameter savingsPlanId is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                savingsPlanOrderId,
                savingsPlanId,
                this.client.getApiVersion(),
                body,
                accept,
                context);
    }

    /**
     * Update savings plan.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param body Request body for patching a savings plan order alias.
     * @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 savings plan on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SavingsPlanModelInner> updateAsync(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateRequest body) {
        return updateWithResponseAsync(savingsPlanOrderId, savingsPlanId, body)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Update savings plan.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param body Request body for patching a savings plan order alias.
     * @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 savings plan.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SavingsPlansUpdateResponse updateWithResponse(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateRequest body, Context context) {
        return updateWithResponseAsync(savingsPlanOrderId, savingsPlanId, body, context).block();
    }

    /**
     * Update savings plan.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param body Request body for patching a savings plan order alias.
     * @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 savings plan.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SavingsPlanModelInner update(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateRequest body) {
        return updateWithResponse(savingsPlanOrderId, savingsPlanId, body, Context.NONE).getValue();
    }

    /**
     * Validate savings plan patch.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param body Request body for validating a savings plan patch request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SavingsPlanValidateResponseInner>> validateUpdateWithResponseAsync(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateValidateRequest body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (savingsPlanOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter savingsPlanOrderId is required and cannot be null."));
        }
        if (savingsPlanId == null) {
            return Mono.error(new IllegalArgumentException("Parameter savingsPlanId is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .validateUpdate(
                            this.client.getEndpoint(),
                            savingsPlanOrderId,
                            savingsPlanId,
                            this.client.getApiVersion(),
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Validate savings plan patch.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param body Request body for validating a savings plan patch request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SavingsPlanValidateResponseInner>> validateUpdateWithResponseAsync(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateValidateRequest body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (savingsPlanOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter savingsPlanOrderId is required and cannot be null."));
        }
        if (savingsPlanId == null) {
            return Mono.error(new IllegalArgumentException("Parameter savingsPlanId is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .validateUpdate(
                this.client.getEndpoint(),
                savingsPlanOrderId,
                savingsPlanId,
                this.client.getApiVersion(),
                body,
                accept,
                context);
    }

    /**
     * Validate savings plan patch.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param body Request body for validating a savings plan patch request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SavingsPlanValidateResponseInner> validateUpdateAsync(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateValidateRequest body) {
        return validateUpdateWithResponseAsync(savingsPlanOrderId, savingsPlanId, body)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Validate savings plan patch.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param body Request body for validating a savings plan patch request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SavingsPlanValidateResponseInner> validateUpdateWithResponse(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateValidateRequest body, Context context) {
        return validateUpdateWithResponseAsync(savingsPlanOrderId, savingsPlanId, body, context).block();
    }

    /**
     * Validate savings plan patch.
     *
     * @param savingsPlanOrderId Order ID of the savings plan.
     * @param savingsPlanId ID of the savings plan.
     * @param body Request body for validating a savings plan patch request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SavingsPlanValidateResponseInner validateUpdate(
        String savingsPlanOrderId, String savingsPlanId, SavingsPlanUpdateValidateRequest body) {
        return validateUpdateWithResponse(savingsPlanOrderId, savingsPlanId, body, Context.NONE).getValue();
    }

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