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

package com.azure.resourcemanager.reservations.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.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.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.reservations.fluent.ReservationsClient;
import com.azure.resourcemanager.reservations.fluent.models.AvailableScopePropertiesInner;
import com.azure.resourcemanager.reservations.fluent.models.ReservationResponseInner;
import com.azure.resourcemanager.reservations.models.AvailableScopeRequest;
import com.azure.resourcemanager.reservations.models.MergeRequest;
import com.azure.resourcemanager.reservations.models.PatchModel;
import com.azure.resourcemanager.reservations.models.ReservationList;
import com.azure.resourcemanager.reservations.models.ReservationsListResult;
import com.azure.resourcemanager.reservations.models.SplitRequest;
import com.fasterxml.jackson.core.type.TypeReference;
import java.nio.ByteBuffer;
import java.util.List;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for AzureReservationApiReservations to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "AzureReservationApiR")
    public interface ReservationsService {
        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId}/availableScopes")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> availableScopes(
            @HostParam("$host") String endpoint,
            @PathParam("reservationOrderId") String reservationOrderId,
            @PathParam("reservationId") String reservationId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") AvailableScopeRequest body,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/split")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> split(
            @HostParam("$host") String endpoint,
            @PathParam("reservationOrderId") String reservationOrderId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") SplitRequest body,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/merge")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> merge(
            @HostParam("$host") String endpoint,
            @PathParam("reservationOrderId") String reservationOrderId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") MergeRequest body,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ReservationList>> list(
            @HostParam("$host") String endpoint,
            @PathParam("reservationOrderId") String reservationOrderId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ReservationResponseInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("reservationOrderId") String reservationOrderId,
            @PathParam("reservationId") String reservationId,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$expand") String expand,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch("/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> update(
            @HostParam("$host") String endpoint,
            @PathParam("reservationOrderId") String reservationOrderId,
            @PathParam("reservationId") String reservationId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") PatchModel parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId}/archive")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> archive(
            @HostParam("$host") String endpoint,
            @PathParam("reservationOrderId") String reservationOrderId,
            @PathParam("reservationId") String reservationId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId}/unarchive")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> unarchive(
            @HostParam("$host") String endpoint,
            @PathParam("reservationOrderId") String reservationOrderId,
            @PathParam("reservationId") String reservationId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/providers/Microsoft.Capacity/reservationOrders/{reservationOrderId}/reservations/{reservationId}/revisions")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ReservationList>> listRevisions(
            @HostParam("$host") String endpoint,
            @PathParam("reservationOrderId") String reservationOrderId,
            @PathParam("reservationId") String reservationId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Get Available Scopes for `Reservation`.
     *
     * <p>Check whether the scopes from request is valid for `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param body Scopes to be checked for eligibility.
     * @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 of available scope api containing scopes and their eligibilities along with {@link Response}
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> availableScopesWithResponseAsync(
        String reservationOrderId, String reservationId, AvailableScopeRequest body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId 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 apiVersion = "2022-11-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .availableScopes(
                            this.client.getEndpoint(),
                            reservationOrderId,
                            reservationId,
                            apiVersion,
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get Available Scopes for `Reservation`.
     *
     * <p>Check whether the scopes from request is valid for `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param body Scopes to be checked for eligibility.
     * @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 of available scope api containing scopes and their eligibilities along with {@link Response}
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> availableScopesWithResponseAsync(
        String reservationOrderId, String reservationId, AvailableScopeRequest body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId 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 apiVersion = "2022-11-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .availableScopes(
                this.client.getEndpoint(), reservationOrderId, reservationId, apiVersion, body, accept, context);
    }

    /**
     * Get Available Scopes for `Reservation`.
     *
     * <p>Check whether the scopes from request is valid for `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param body Scopes to be checked for eligibility.
     * @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 response of available scope api containing scopes and their
     *     eligibilities.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<AvailableScopePropertiesInner>, AvailableScopePropertiesInner>
        beginAvailableScopesAsync(String reservationOrderId, String reservationId, AvailableScopeRequest body) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            availableScopesWithResponseAsync(reservationOrderId, reservationId, body);
        return this
            .client
            .<AvailableScopePropertiesInner, AvailableScopePropertiesInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                AvailableScopePropertiesInner.class,
                AvailableScopePropertiesInner.class,
                this.client.getContext());
    }

    /**
     * Get Available Scopes for `Reservation`.
     *
     * <p>Check whether the scopes from request is valid for `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param body Scopes to be checked for eligibility.
     * @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 response of available scope api containing scopes and their
     *     eligibilities.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<AvailableScopePropertiesInner>, AvailableScopePropertiesInner>
        beginAvailableScopesAsync(
            String reservationOrderId, String reservationId, AvailableScopeRequest body, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            availableScopesWithResponseAsync(reservationOrderId, reservationId, body, context);
        return this
            .client
            .<AvailableScopePropertiesInner, AvailableScopePropertiesInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                AvailableScopePropertiesInner.class,
                AvailableScopePropertiesInner.class,
                context);
    }

    /**
     * Get Available Scopes for `Reservation`.
     *
     * <p>Check whether the scopes from request is valid for `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param body Scopes to be checked for eligibility.
     * @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 response of available scope api containing scopes and their
     *     eligibilities.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<AvailableScopePropertiesInner>, AvailableScopePropertiesInner> beginAvailableScopes(
        String reservationOrderId, String reservationId, AvailableScopeRequest body) {
        return this.beginAvailableScopesAsync(reservationOrderId, reservationId, body).getSyncPoller();
    }

    /**
     * Get Available Scopes for `Reservation`.
     *
     * <p>Check whether the scopes from request is valid for `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param body Scopes to be checked for eligibility.
     * @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 response of available scope api containing scopes and their
     *     eligibilities.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<AvailableScopePropertiesInner>, AvailableScopePropertiesInner> beginAvailableScopes(
        String reservationOrderId, String reservationId, AvailableScopeRequest body, Context context) {
        return this.beginAvailableScopesAsync(reservationOrderId, reservationId, body, context).getSyncPoller();
    }

    /**
     * Get Available Scopes for `Reservation`.
     *
     * <p>Check whether the scopes from request is valid for `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param body Scopes to be checked for eligibility.
     * @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 of available scope api containing scopes and their eligibilities on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AvailableScopePropertiesInner> availableScopesAsync(
        String reservationOrderId, String reservationId, AvailableScopeRequest body) {
        return beginAvailableScopesAsync(reservationOrderId, reservationId, body)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Get Available Scopes for `Reservation`.
     *
     * <p>Check whether the scopes from request is valid for `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param body Scopes to be checked for eligibility.
     * @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 of available scope api containing scopes and their eligibilities on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AvailableScopePropertiesInner> availableScopesAsync(
        String reservationOrderId, String reservationId, AvailableScopeRequest body, Context context) {
        return beginAvailableScopesAsync(reservationOrderId, reservationId, body, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Get Available Scopes for `Reservation`.
     *
     * <p>Check whether the scopes from request is valid for `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param body Scopes to be checked for eligibility.
     * @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 of available scope api containing scopes and their eligibilities.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AvailableScopePropertiesInner availableScopes(
        String reservationOrderId, String reservationId, AvailableScopeRequest body) {
        return availableScopesAsync(reservationOrderId, reservationId, body).block();
    }

    /**
     * Get Available Scopes for `Reservation`.
     *
     * <p>Check whether the scopes from request is valid for `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param body Scopes to be checked for eligibility.
     * @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 of available scope api containing scopes and their eligibilities.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AvailableScopePropertiesInner availableScopes(
        String reservationOrderId, String reservationId, AvailableScopeRequest body, Context context) {
        return availableScopesAsync(reservationOrderId, reservationId, body, context).block();
    }

    /**
     * Split the `Reservation`.
     *
     * <p>Split a `Reservation` into two `Reservation`s with specified quantity distribution.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed to Split a reservation item.
     * @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 array of ReservationResponse along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> splitWithResponseAsync(String reservationOrderId, SplitRequest body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId 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 apiVersion = "2022-11-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service.split(this.client.getEndpoint(), reservationOrderId, apiVersion, body, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Split the `Reservation`.
     *
     * <p>Split a `Reservation` into two `Reservation`s with specified quantity distribution.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed to Split a reservation item.
     * @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 array of ReservationResponse along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> splitWithResponseAsync(
        String reservationOrderId, SplitRequest body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId 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 apiVersion = "2022-11-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.split(this.client.getEndpoint(), reservationOrderId, apiVersion, body, accept, context);
    }

    /**
     * Split the `Reservation`.
     *
     * <p>Split a `Reservation` into two `Reservation`s with specified quantity distribution.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed to Split a reservation item.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<List<ReservationResponseInner>>, List<ReservationResponseInner>> beginSplitAsync(
        String reservationOrderId, SplitRequest body) {
        Mono<Response<Flux<ByteBuffer>>> mono = splitWithResponseAsync(reservationOrderId, body);
        return this
            .client
            .<List<ReservationResponseInner>, List<ReservationResponseInner>>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                new TypeReference<List<ReservationResponseInner>>() {
                }.getType(),
                new TypeReference<List<ReservationResponseInner>>() {
                }.getType(),
                this.client.getContext());
    }

    /**
     * Split the `Reservation`.
     *
     * <p>Split a `Reservation` into two `Reservation`s with specified quantity distribution.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed to Split a reservation item.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<List<ReservationResponseInner>>, List<ReservationResponseInner>> beginSplitAsync(
        String reservationOrderId, SplitRequest body, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = splitWithResponseAsync(reservationOrderId, body, context);
        return this
            .client
            .<List<ReservationResponseInner>, List<ReservationResponseInner>>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                new TypeReference<List<ReservationResponseInner>>() {
                }.getType(),
                new TypeReference<List<ReservationResponseInner>>() {
                }.getType(),
                context);
    }

    /**
     * Split the `Reservation`.
     *
     * <p>Split a `Reservation` into two `Reservation`s with specified quantity distribution.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed to Split a reservation item.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<List<ReservationResponseInner>>, List<ReservationResponseInner>> beginSplit(
        String reservationOrderId, SplitRequest body) {
        return this.beginSplitAsync(reservationOrderId, body).getSyncPoller();
    }

    /**
     * Split the `Reservation`.
     *
     * <p>Split a `Reservation` into two `Reservation`s with specified quantity distribution.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed to Split a reservation item.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<List<ReservationResponseInner>>, List<ReservationResponseInner>> beginSplit(
        String reservationOrderId, SplitRequest body, Context context) {
        return this.beginSplitAsync(reservationOrderId, body, context).getSyncPoller();
    }

    /**
     * Split the `Reservation`.
     *
     * <p>Split a `Reservation` into two `Reservation`s with specified quantity distribution.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed to Split a reservation item.
     * @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 array of ReservationResponse on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<List<ReservationResponseInner>> splitAsync(String reservationOrderId, SplitRequest body) {
        return beginSplitAsync(reservationOrderId, body).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Split the `Reservation`.
     *
     * <p>Split a `Reservation` into two `Reservation`s with specified quantity distribution.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed to Split a reservation item.
     * @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 array of ReservationResponse on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<List<ReservationResponseInner>> splitAsync(
        String reservationOrderId, SplitRequest body, Context context) {
        return beginSplitAsync(reservationOrderId, body, context).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Split the `Reservation`.
     *
     * <p>Split a `Reservation` into two `Reservation`s with specified quantity distribution.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed to Split a reservation item.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public List<ReservationResponseInner> split(String reservationOrderId, SplitRequest body) {
        return splitAsync(reservationOrderId, body).block();
    }

    /**
     * Split the `Reservation`.
     *
     * <p>Split a `Reservation` into two `Reservation`s with specified quantity distribution.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed to Split a reservation item.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public List<ReservationResponseInner> split(String reservationOrderId, SplitRequest body, Context context) {
        return splitAsync(reservationOrderId, body, context).block();
    }

    /**
     * Merges two `Reservation`s.
     *
     * <p>Merge the specified `Reservation`s into a new `Reservation`. The two `Reservation`s being merged must have
     * same properties.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed for commercial request for a reservation.
     * @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 array of ReservationResponse along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> mergeWithResponseAsync(String reservationOrderId, MergeRequest body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId 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 apiVersion = "2022-11-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service.merge(this.client.getEndpoint(), reservationOrderId, apiVersion, body, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Merges two `Reservation`s.
     *
     * <p>Merge the specified `Reservation`s into a new `Reservation`. The two `Reservation`s being merged must have
     * same properties.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed for commercial request for a reservation.
     * @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 array of ReservationResponse along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> mergeWithResponseAsync(
        String reservationOrderId, MergeRequest body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId 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 apiVersion = "2022-11-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.merge(this.client.getEndpoint(), reservationOrderId, apiVersion, body, accept, context);
    }

    /**
     * Merges two `Reservation`s.
     *
     * <p>Merge the specified `Reservation`s into a new `Reservation`. The two `Reservation`s being merged must have
     * same properties.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed for commercial request for a reservation.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<List<ReservationResponseInner>>, List<ReservationResponseInner>> beginMergeAsync(
        String reservationOrderId, MergeRequest body) {
        Mono<Response<Flux<ByteBuffer>>> mono = mergeWithResponseAsync(reservationOrderId, body);
        return this
            .client
            .<List<ReservationResponseInner>, List<ReservationResponseInner>>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                new TypeReference<List<ReservationResponseInner>>() {
                }.getType(),
                new TypeReference<List<ReservationResponseInner>>() {
                }.getType(),
                this.client.getContext());
    }

    /**
     * Merges two `Reservation`s.
     *
     * <p>Merge the specified `Reservation`s into a new `Reservation`. The two `Reservation`s being merged must have
     * same properties.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed for commercial request for a reservation.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<List<ReservationResponseInner>>, List<ReservationResponseInner>> beginMergeAsync(
        String reservationOrderId, MergeRequest body, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = mergeWithResponseAsync(reservationOrderId, body, context);
        return this
            .client
            .<List<ReservationResponseInner>, List<ReservationResponseInner>>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                new TypeReference<List<ReservationResponseInner>>() {
                }.getType(),
                new TypeReference<List<ReservationResponseInner>>() {
                }.getType(),
                context);
    }

    /**
     * Merges two `Reservation`s.
     *
     * <p>Merge the specified `Reservation`s into a new `Reservation`. The two `Reservation`s being merged must have
     * same properties.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed for commercial request for a reservation.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<List<ReservationResponseInner>>, List<ReservationResponseInner>> beginMerge(
        String reservationOrderId, MergeRequest body) {
        return this.beginMergeAsync(reservationOrderId, body).getSyncPoller();
    }

    /**
     * Merges two `Reservation`s.
     *
     * <p>Merge the specified `Reservation`s into a new `Reservation`. The two `Reservation`s being merged must have
     * same properties.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed for commercial request for a reservation.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<List<ReservationResponseInner>>, List<ReservationResponseInner>> beginMerge(
        String reservationOrderId, MergeRequest body, Context context) {
        return this.beginMergeAsync(reservationOrderId, body, context).getSyncPoller();
    }

    /**
     * Merges two `Reservation`s.
     *
     * <p>Merge the specified `Reservation`s into a new `Reservation`. The two `Reservation`s being merged must have
     * same properties.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed for commercial request for a reservation.
     * @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 array of ReservationResponse on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<List<ReservationResponseInner>> mergeAsync(String reservationOrderId, MergeRequest body) {
        return beginMergeAsync(reservationOrderId, body).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Merges two `Reservation`s.
     *
     * <p>Merge the specified `Reservation`s into a new `Reservation`. The two `Reservation`s being merged must have
     * same properties.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed for commercial request for a reservation.
     * @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 array of ReservationResponse on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<List<ReservationResponseInner>> mergeAsync(
        String reservationOrderId, MergeRequest body, Context context) {
        return beginMergeAsync(reservationOrderId, body, context).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Merges two `Reservation`s.
     *
     * <p>Merge the specified `Reservation`s into a new `Reservation`. The two `Reservation`s being merged must have
     * same properties.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed for commercial request for a reservation.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public List<ReservationResponseInner> merge(String reservationOrderId, MergeRequest body) {
        return mergeAsync(reservationOrderId, body).block();
    }

    /**
     * Merges two `Reservation`s.
     *
     * <p>Merge the specified `Reservation`s into a new `Reservation`. The two `Reservation`s being merged must have
     * same properties.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param body Information needed for commercial request for a reservation.
     * @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 array of ReservationResponse.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public List<ReservationResponseInner> merge(String reservationOrderId, MergeRequest body, Context context) {
        return mergeAsync(reservationOrderId, body, context).block();
    }

    /**
     * Get `Reservation`s in a given reservation Order
     *
     * <p>List `Reservation`s within a single `ReservationOrder`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @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 list of `Reservation`s along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> listSinglePageAsync(String reservationOrderId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context -> service.list(this.client.getEndpoint(), reservationOrderId, apiVersion, accept, context))
            .<PagedResponse<ReservationResponseInner>>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 `Reservation`s in a given reservation Order
     *
     * <p>List `Reservation`s within a single `ReservationOrder`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @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 list of `Reservation`s along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> listSinglePageAsync(
        String reservationOrderId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(this.client.getEndpoint(), reservationOrderId, apiVersion, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get `Reservation`s in a given reservation Order
     *
     * <p>List `Reservation`s within a single `ReservationOrder`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @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 list of `Reservation`s as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ReservationResponseInner> listAsync(String reservationOrderId) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(reservationOrderId), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Get `Reservation`s in a given reservation Order
     *
     * <p>List `Reservation`s within a single `ReservationOrder`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @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 list of `Reservation`s as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ReservationResponseInner> listAsync(String reservationOrderId, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(reservationOrderId, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Get `Reservation`s in a given reservation Order
     *
     * <p>List `Reservation`s within a single `ReservationOrder`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @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 list of `Reservation`s as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ReservationResponseInner> list(String reservationOrderId) {
        return new PagedIterable<>(listAsync(reservationOrderId));
    }

    /**
     * Get `Reservation`s in a given reservation Order
     *
     * <p>List `Reservation`s within a single `ReservationOrder`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @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 list of `Reservation`s as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ReservationResponseInner> list(String reservationOrderId, Context context) {
        return new PagedIterable<>(listAsync(reservationOrderId, context));
    }

    /**
     * Get `Reservation` details.
     *
     * <p>Get specific `Reservation` details.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param expand Supported value of this query is renewProperties.
     * @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 specific `Reservation` details along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ReservationResponseInner>> getWithResponseAsync(
        String reservationOrderId, String reservationId, String expand) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId is required and cannot be null."));
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            reservationOrderId,
                            reservationId,
                            apiVersion,
                            expand,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get `Reservation` details.
     *
     * <p>Get specific `Reservation` details.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param expand Supported value of this query is renewProperties.
     * @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 specific `Reservation` details along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ReservationResponseInner>> getWithResponseAsync(
        String reservationOrderId, String reservationId, 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 (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId is required and cannot be null."));
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(this.client.getEndpoint(), reservationOrderId, reservationId, apiVersion, expand, accept, context);
    }

    /**
     * Get `Reservation` details.
     *
     * <p>Get specific `Reservation` details.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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 specific `Reservation` details on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ReservationResponseInner> getAsync(String reservationOrderId, String reservationId) {
        final String expand = null;
        return getWithResponseAsync(reservationOrderId, reservationId, expand)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get `Reservation` details.
     *
     * <p>Get specific `Reservation` details.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param expand Supported value of this query is renewProperties.
     * @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 specific `Reservation` details along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ReservationResponseInner> getWithResponse(
        String reservationOrderId, String reservationId, String expand, Context context) {
        return getWithResponseAsync(reservationOrderId, reservationId, expand, context).block();
    }

    /**
     * Get `Reservation` details.
     *
     * <p>Get specific `Reservation` details.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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 specific `Reservation` details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ReservationResponseInner get(String reservationOrderId, String reservationId) {
        final String expand = null;
        return getWithResponse(reservationOrderId, reservationId, expand, Context.NONE).getValue();
    }

    /**
     * Updates a `Reservation`.
     *
     * <p>Updates the applied scopes of the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param parameters Information needed to patch a reservation item.
     * @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 definition of the reservation along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String reservationOrderId, String reservationId, PatchModel parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            reservationOrderId,
                            reservationId,
                            apiVersion,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Updates a `Reservation`.
     *
     * <p>Updates the applied scopes of the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param parameters Information needed to patch a reservation item.
     * @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 definition of the reservation along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String reservationOrderId, String reservationId, PatchModel parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(), reservationOrderId, reservationId, apiVersion, parameters, accept, context);
    }

    /**
     * Updates a `Reservation`.
     *
     * <p>Updates the applied scopes of the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param parameters Information needed to patch a reservation item.
     * @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 definition of the reservation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ReservationResponseInner>, ReservationResponseInner> beginUpdateAsync(
        String reservationOrderId, String reservationId, PatchModel parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono = updateWithResponseAsync(reservationOrderId, reservationId, parameters);
        return this
            .client
            .<ReservationResponseInner, ReservationResponseInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ReservationResponseInner.class,
                ReservationResponseInner.class,
                this.client.getContext());
    }

    /**
     * Updates a `Reservation`.
     *
     * <p>Updates the applied scopes of the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param parameters Information needed to patch a reservation item.
     * @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 definition of the reservation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ReservationResponseInner>, ReservationResponseInner> beginUpdateAsync(
        String reservationOrderId, String reservationId, PatchModel parameters, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(reservationOrderId, reservationId, parameters, context);
        return this
            .client
            .<ReservationResponseInner, ReservationResponseInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ReservationResponseInner.class,
                ReservationResponseInner.class,
                context);
    }

    /**
     * Updates a `Reservation`.
     *
     * <p>Updates the applied scopes of the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param parameters Information needed to patch a reservation item.
     * @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 definition of the reservation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ReservationResponseInner>, ReservationResponseInner> beginUpdate(
        String reservationOrderId, String reservationId, PatchModel parameters) {
        return this.beginUpdateAsync(reservationOrderId, reservationId, parameters).getSyncPoller();
    }

    /**
     * Updates a `Reservation`.
     *
     * <p>Updates the applied scopes of the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param parameters Information needed to patch a reservation item.
     * @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 definition of the reservation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ReservationResponseInner>, ReservationResponseInner> beginUpdate(
        String reservationOrderId, String reservationId, PatchModel parameters, Context context) {
        return this.beginUpdateAsync(reservationOrderId, reservationId, parameters, context).getSyncPoller();
    }

    /**
     * Updates a `Reservation`.
     *
     * <p>Updates the applied scopes of the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param parameters Information needed to patch a reservation item.
     * @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 definition of the reservation on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ReservationResponseInner> updateAsync(
        String reservationOrderId, String reservationId, PatchModel parameters) {
        return beginUpdateAsync(reservationOrderId, reservationId, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates a `Reservation`.
     *
     * <p>Updates the applied scopes of the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param parameters Information needed to patch a reservation item.
     * @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 definition of the reservation on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ReservationResponseInner> updateAsync(
        String reservationOrderId, String reservationId, PatchModel parameters, Context context) {
        return beginUpdateAsync(reservationOrderId, reservationId, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates a `Reservation`.
     *
     * <p>Updates the applied scopes of the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param parameters Information needed to patch a reservation item.
     * @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 definition of the reservation.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ReservationResponseInner update(String reservationOrderId, String reservationId, PatchModel parameters) {
        return updateAsync(reservationOrderId, reservationId, parameters).block();
    }

    /**
     * Updates a `Reservation`.
     *
     * <p>Updates the applied scopes of the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param parameters Information needed to patch a reservation item.
     * @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 definition of the reservation.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ReservationResponseInner update(
        String reservationOrderId, String reservationId, PatchModel parameters, Context context) {
        return updateAsync(reservationOrderId, reservationId, parameters, context).block();
    }

    /**
     * Archive a `Reservation`.
     *
     * <p>Archiving a `Reservation` moves it to `Archived` state.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> archiveWithResponseAsync(String reservationOrderId, String reservationId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId is required and cannot be null."));
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .archive(
                            this.client.getEndpoint(), reservationOrderId, reservationId, apiVersion, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Archive a `Reservation`.
     *
     * <p>Archiving a `Reservation` moves it to `Archived` state.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> archiveWithResponseAsync(
        String reservationOrderId, String reservationId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId is required and cannot be null."));
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .archive(this.client.getEndpoint(), reservationOrderId, reservationId, apiVersion, accept, context);
    }

    /**
     * Archive a `Reservation`.
     *
     * <p>Archiving a `Reservation` moves it to `Archived` state.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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> archiveAsync(String reservationOrderId, String reservationId) {
        return archiveWithResponseAsync(reservationOrderId, reservationId).flatMap(ignored -> Mono.empty());
    }

    /**
     * Archive a `Reservation`.
     *
     * <p>Archiving a `Reservation` moves it to `Archived` state.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> archiveWithResponse(String reservationOrderId, String reservationId, Context context) {
        return archiveWithResponseAsync(reservationOrderId, reservationId, context).block();
    }

    /**
     * Archive a `Reservation`.
     *
     * <p>Archiving a `Reservation` moves it to `Archived` state.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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 archive(String reservationOrderId, String reservationId) {
        archiveWithResponse(reservationOrderId, reservationId, Context.NONE);
    }

    /**
     * Unarchive a `Reservation`.
     *
     * <p>Restores a `Reservation` to the state it was before archiving.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> unarchiveWithResponseAsync(String reservationOrderId, String reservationId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId is required and cannot be null."));
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .unarchive(
                            this.client.getEndpoint(), reservationOrderId, reservationId, apiVersion, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Unarchive a `Reservation`.
     *
     * <p>Restores a `Reservation` to the state it was before archiving.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> unarchiveWithResponseAsync(
        String reservationOrderId, String reservationId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId is required and cannot be null."));
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .unarchive(this.client.getEndpoint(), reservationOrderId, reservationId, apiVersion, accept, context);
    }

    /**
     * Unarchive a `Reservation`.
     *
     * <p>Restores a `Reservation` to the state it was before archiving.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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> unarchiveAsync(String reservationOrderId, String reservationId) {
        return unarchiveWithResponseAsync(reservationOrderId, reservationId).flatMap(ignored -> Mono.empty());
    }

    /**
     * Unarchive a `Reservation`.
     *
     * <p>Restores a `Reservation` to the state it was before archiving.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> unarchiveWithResponse(String reservationOrderId, String reservationId, Context context) {
        return unarchiveWithResponseAsync(reservationOrderId, reservationId, context).block();
    }

    /**
     * Unarchive a `Reservation`.
     *
     * <p>Restores a `Reservation` to the state it was before archiving.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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 unarchive(String reservationOrderId, String reservationId) {
        unarchiveWithResponse(reservationOrderId, reservationId, Context.NONE);
    }

    /**
     * Get `Reservation` revisions.
     *
     * <p>List of all the revisions for the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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 list of `Reservation`s along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> listRevisionsSinglePageAsync(
        String reservationOrderId, String reservationId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId is required and cannot be null."));
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listRevisions(
                            this.client.getEndpoint(), reservationOrderId, reservationId, apiVersion, accept, context))
            .<PagedResponse<ReservationResponseInner>>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 `Reservation` revisions.
     *
     * <p>List of all the revisions for the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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 list of `Reservation`s along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> listRevisionsSinglePageAsync(
        String reservationOrderId, String reservationId, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (reservationOrderId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter reservationOrderId is required and cannot be null."));
        }
        if (reservationId == null) {
            return Mono.error(new IllegalArgumentException("Parameter reservationId is required and cannot be null."));
        }
        final String apiVersion = "2022-11-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listRevisions(this.client.getEndpoint(), reservationOrderId, reservationId, apiVersion, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get `Reservation` revisions.
     *
     * <p>List of all the revisions for the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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 list of `Reservation`s as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ReservationResponseInner> listRevisionsAsync(String reservationOrderId, String reservationId) {
        return new PagedFlux<>(
            () -> listRevisionsSinglePageAsync(reservationOrderId, reservationId),
            nextLink -> listRevisionsNextSinglePageAsync(nextLink));
    }

    /**
     * Get `Reservation` revisions.
     *
     * <p>List of all the revisions for the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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 list of `Reservation`s as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ReservationResponseInner> listRevisionsAsync(
        String reservationOrderId, String reservationId, Context context) {
        return new PagedFlux<>(
            () -> listRevisionsSinglePageAsync(reservationOrderId, reservationId, context),
            nextLink -> listRevisionsNextSinglePageAsync(nextLink, context));
    }

    /**
     * Get `Reservation` revisions.
     *
     * <p>List of all the revisions for the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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 list of `Reservation`s as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ReservationResponseInner> listRevisions(String reservationOrderId, String reservationId) {
        return new PagedIterable<>(listRevisionsAsync(reservationOrderId, reservationId));
    }

    /**
     * Get `Reservation` revisions.
     *
     * <p>List of all the revisions for the `Reservation`.
     *
     * @param reservationOrderId Order Id of the reservation.
     * @param reservationId Id of the reservation item.
     * @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 list of `Reservation`s as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ReservationResponseInner> listRevisions(
        String reservationOrderId, String reservationId, Context context) {
        return new PagedIterable<>(listRevisionsAsync(reservationOrderId, reservationId, context));
    }

    /**
     * List the reservations and the roll up counts of reservations group by provisioning states that the user has
     * access to in the current tenant.
     *
     * @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,
     *     expiryDateTime, 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 reservations group by provisioning
     *     states.
     * @param skiptoken The number of reservations to skip from the list before returning results.
     * @param selectedState The selected provisioning state.
     * @param take To number of reservations 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 list of reservations and summary of roll out count of reservations in each state along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> 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 apiVersion = "2022-11-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listAll(
                            this.client.getEndpoint(),
                            apiVersion,
                            filter,
                            orderby,
                            refreshSummary,
                            skiptoken,
                            selectedState,
                            take,
                            accept,
                            context))
            .<PagedResponse<ReservationResponseInner>>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 the reservations and the roll up counts of reservations group by provisioning states that the user has
     * access to in the current tenant.
     *
     * @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,
     *     expiryDateTime, 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 reservations group by provisioning
     *     states.
     * @param skiptoken The number of reservations to skip from the list before returning results.
     * @param selectedState The selected provisioning state.
     * @param take To number of reservations 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 list of reservations and summary of roll out count of reservations in each state along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> 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 apiVersion = "2022-11-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listAll(
                this.client.getEndpoint(),
                apiVersion,
                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 the reservations and the roll up counts of reservations group by provisioning states that the user has
     * access to in the current tenant.
     *
     * @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,
     *     expiryDateTime, 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 reservations group by provisioning
     *     states.
     * @param skiptoken The number of reservations to skip from the list before returning results.
     * @param selectedState The selected provisioning state.
     * @param take To number of reservations 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 list of reservations and summary of roll out count of reservations in each state as paginated
     *     response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ReservationResponseInner> 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 the reservations and the roll up counts of reservations group by provisioning states that the user has
     * access to in the current tenant.
     *
     * @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 reservations and summary of roll out count of reservations in each state as paginated
     *     response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ReservationResponseInner> 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 the reservations and the roll up counts of reservations group by provisioning states that the user has
     * access to in the current tenant.
     *
     * @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,
     *     expiryDateTime, 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 reservations group by provisioning
     *     states.
     * @param skiptoken The number of reservations to skip from the list before returning results.
     * @param selectedState The selected provisioning state.
     * @param take To number of reservations 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 list of reservations and summary of roll out count of reservations in each state as paginated
     *     response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ReservationResponseInner> 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 the reservations and the roll up counts of reservations group by provisioning states that the user has
     * access to in the current tenant.
     *
     * @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 reservations and summary of roll out count of reservations in each state as paginated
     *     response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ReservationResponseInner> 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 the reservations and the roll up counts of reservations group by provisioning states that the user has
     * access to in the current tenant.
     *
     * @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,
     *     expiryDateTime, 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 reservations group by provisioning
     *     states.
     * @param skiptoken The number of reservations to skip from the list before returning results.
     * @param selectedState The selected provisioning state.
     * @param take To number of reservations 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 list of reservations and summary of roll out count of reservations in each state as paginated
     *     response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ReservationResponseInner> 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 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 list of `Reservation`s along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> 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<ReservationResponseInner>>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 list of `Reservation`s along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> 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 list of `Reservation`s along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> listRevisionsNextSinglePageAsync(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.listRevisionsNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ReservationResponseInner>>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 list of `Reservation`s along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> listRevisionsNextSinglePageAsync(
        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
            .listRevisionsNext(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 reservations and summary of roll out count of reservations in each state along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> 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<ReservationResponseInner>>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 reservations and summary of roll out count of reservations in each state along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ReservationResponseInner>> 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));
    }
}
