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

package com.azure.resourcemanager.billing.implementation;

import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.resourcemanager.billing.fluent.ReservationsClient;
import com.azure.resourcemanager.billing.fluent.models.ReservationInner;
import com.azure.resourcemanager.billing.models.ReservationsListResult;
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 BillingManagementClientImpl client;

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

    /**
     * The interface defining all the services for BillingManagementClientReservations to be used by the proxy service
     * to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "BillingManagementCli")
    public interface ReservationsService {
        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/reservations")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ReservationsListResult>> listByBillingAccount(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("billingAccountName") String billingAccountName,
            @QueryParam("$filter") String filter,
            @QueryParam("$orderby") String orderby,
            @QueryParam("refreshSummary") String refreshSummary,
            @QueryParam("selectedState") String selectedState,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}"
                + "/reservations")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ReservationsListResult>> listByBillingProfile(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("billingProfileName") String billingProfileName,
            @QueryParam("$filter") String filter,
            @QueryParam("$orderby") String orderby,
            @QueryParam("refreshSummary") String refreshSummary,
            @QueryParam("selectedState") String selectedState,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Lists the reservations for a billing account and the roll up counts of reservations group by provisioning states.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @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'.
     * @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 selectedState The selected provisioning state.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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<ReservationInner>> listByBillingAccountSinglePageAsync(
        String billingAccountName, String filter, String orderby, String refreshSummary, String selectedState) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (billingAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter billingAccountName is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByBillingAccount(
                            this.client.getEndpoint(),
                            apiVersion,
                            billingAccountName,
                            filter,
                            orderby,
                            refreshSummary,
                            selectedState,
                            accept,
                            context))
            .<PagedResponse<ReservationInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Lists the reservations for a billing account and the roll up counts of reservations group by provisioning states.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @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'.
     * @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 selectedState The selected provisioning state.
     * @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<ReservationInner>> listByBillingAccountSinglePageAsync(
        String billingAccountName,
        String filter,
        String orderby,
        String refreshSummary,
        String selectedState,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (billingAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter billingAccountName is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByBillingAccount(
                this.client.getEndpoint(),
                apiVersion,
                billingAccountName,
                filter,
                orderby,
                refreshSummary,
                selectedState,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Lists the reservations for a billing account and the roll up counts of reservations group by provisioning states.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @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'.
     * @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 selectedState The selected provisioning state.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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<ReservationInner> listByBillingAccountAsync(
        String billingAccountName, String filter, String orderby, String refreshSummary, String selectedState) {
        return new PagedFlux<>(
            () ->
                listByBillingAccountSinglePageAsync(billingAccountName, filter, orderby, refreshSummary, selectedState),
            nextLink -> listByBillingAccountNextSinglePageAsync(nextLink));
    }

    /**
     * Lists the reservations for a billing account and the roll up counts of reservations group by provisioning states.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the 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<ReservationInner> listByBillingAccountAsync(String billingAccountName) {
        final String filter = null;
        final String orderby = null;
        final String refreshSummary = null;
        final String selectedState = null;
        return new PagedFlux<>(
            () ->
                listByBillingAccountSinglePageAsync(billingAccountName, filter, orderby, refreshSummary, selectedState),
            nextLink -> listByBillingAccountNextSinglePageAsync(nextLink));
    }

    /**
     * Lists the reservations for a billing account and the roll up counts of reservations group by provisioning states.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @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'.
     * @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 selectedState The selected provisioning state.
     * @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<ReservationInner> listByBillingAccountAsync(
        String billingAccountName,
        String filter,
        String orderby,
        String refreshSummary,
        String selectedState,
        Context context) {
        return new PagedFlux<>(
            () ->
                listByBillingAccountSinglePageAsync(
                    billingAccountName, filter, orderby, refreshSummary, selectedState, context),
            nextLink -> listByBillingAccountNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists the reservations for a billing account and the roll up counts of reservations group by provisioning states.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the 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<ReservationInner> listByBillingAccount(String billingAccountName) {
        final String filter = null;
        final String orderby = null;
        final String refreshSummary = null;
        final String selectedState = null;
        return new PagedIterable<>(
            listByBillingAccountAsync(billingAccountName, filter, orderby, refreshSummary, selectedState));
    }

    /**
     * Lists the reservations for a billing account and the roll up counts of reservations group by provisioning states.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @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'.
     * @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 selectedState The selected provisioning state.
     * @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<ReservationInner> listByBillingAccount(
        String billingAccountName,
        String filter,
        String orderby,
        String refreshSummary,
        String selectedState,
        Context context) {
        return new PagedIterable<>(
            listByBillingAccountAsync(billingAccountName, filter, orderby, refreshSummary, selectedState, context));
    }

    /**
     * Lists the reservations for a billing profile and the roll up counts of reservations group by provisioning state.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @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'.
     * @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
     *     state.
     * @param selectedState The selected provisioning state.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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<ReservationInner>> listByBillingProfileSinglePageAsync(
        String billingAccountName,
        String billingProfileName,
        String filter,
        String orderby,
        String refreshSummary,
        String selectedState) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (billingAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter billingAccountName is required and cannot be null."));
        }
        if (billingProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter billingProfileName is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByBillingProfile(
                            this.client.getEndpoint(),
                            apiVersion,
                            billingAccountName,
                            billingProfileName,
                            filter,
                            orderby,
                            refreshSummary,
                            selectedState,
                            accept,
                            context))
            .<PagedResponse<ReservationInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Lists the reservations for a billing profile and the roll up counts of reservations group by provisioning state.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @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'.
     * @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
     *     state.
     * @param selectedState The selected provisioning state.
     * @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<ReservationInner>> listByBillingProfileSinglePageAsync(
        String billingAccountName,
        String billingProfileName,
        String filter,
        String orderby,
        String refreshSummary,
        String selectedState,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (billingAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter billingAccountName is required and cannot be null."));
        }
        if (billingProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter billingProfileName is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByBillingProfile(
                this.client.getEndpoint(),
                apiVersion,
                billingAccountName,
                billingProfileName,
                filter,
                orderby,
                refreshSummary,
                selectedState,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Lists the reservations for a billing profile and the roll up counts of reservations group by provisioning state.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @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'.
     * @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
     *     state.
     * @param selectedState The selected provisioning state.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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<ReservationInner> listByBillingProfileAsync(
        String billingAccountName,
        String billingProfileName,
        String filter,
        String orderby,
        String refreshSummary,
        String selectedState) {
        return new PagedFlux<>(
            () ->
                listByBillingProfileSinglePageAsync(
                    billingAccountName, billingProfileName, filter, orderby, refreshSummary, selectedState),
            nextLink -> listByBillingProfileNextSinglePageAsync(nextLink));
    }

    /**
     * Lists the reservations for a billing profile and the roll up counts of reservations group by provisioning state.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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<ReservationInner> listByBillingProfileAsync(
        String billingAccountName, String billingProfileName) {
        final String filter = null;
        final String orderby = null;
        final String refreshSummary = null;
        final String selectedState = null;
        return new PagedFlux<>(
            () ->
                listByBillingProfileSinglePageAsync(
                    billingAccountName, billingProfileName, filter, orderby, refreshSummary, selectedState),
            nextLink -> listByBillingProfileNextSinglePageAsync(nextLink));
    }

    /**
     * Lists the reservations for a billing profile and the roll up counts of reservations group by provisioning state.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @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'.
     * @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
     *     state.
     * @param selectedState The selected provisioning state.
     * @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<ReservationInner> listByBillingProfileAsync(
        String billingAccountName,
        String billingProfileName,
        String filter,
        String orderby,
        String refreshSummary,
        String selectedState,
        Context context) {
        return new PagedFlux<>(
            () ->
                listByBillingProfileSinglePageAsync(
                    billingAccountName, billingProfileName, filter, orderby, refreshSummary, selectedState, context),
            nextLink -> listByBillingProfileNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists the reservations for a billing profile and the roll up counts of reservations group by provisioning state.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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<ReservationInner> listByBillingProfile(String billingAccountName, String billingProfileName) {
        final String filter = null;
        final String orderby = null;
        final String refreshSummary = null;
        final String selectedState = null;
        return new PagedIterable<>(
            listByBillingProfileAsync(
                billingAccountName, billingProfileName, filter, orderby, refreshSummary, selectedState));
    }

    /**
     * Lists the reservations for a billing profile and the roll up counts of reservations group by provisioning state.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @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'.
     * @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
     *     state.
     * @param selectedState The selected provisioning state.
     * @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<ReservationInner> listByBillingProfile(
        String billingAccountName,
        String billingProfileName,
        String filter,
        String orderby,
        String refreshSummary,
        String selectedState,
        Context context) {
        return new PagedIterable<>(
            listByBillingProfileAsync(
                billingAccountName, billingProfileName, filter, orderby, refreshSummary, selectedState, context));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the 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<ReservationInner>> listByBillingAccountNextSinglePageAsync(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.listByBillingAccountNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ReservationInner>>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<ReservationInner>> listByBillingAccountNextSinglePageAsync(
        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
            .listByBillingAccountNext(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<ReservationInner>> listByBillingProfileNextSinglePageAsync(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.listByBillingProfileNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ReservationInner>>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<ReservationInner>> listByBillingProfileNextSinglePageAsync(
        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
            .listByBillingProfileNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
