// 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.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.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.billing.fluent.InvoicesClient;
import com.azure.resourcemanager.billing.fluent.models.DownloadUrlInner;
import com.azure.resourcemanager.billing.fluent.models.InvoiceInner;
import com.azure.resourcemanager.billing.models.InvoiceListResult;
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 InvoicesClient. */
public final class InvoicesClientImpl implements InvoicesClient {
    /** The proxy service used to perform REST calls. */
    private final InvoicesService service;

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

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

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

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

        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/invoices/{invoiceName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<InvoiceInner>> get(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("invoiceName") String invoiceName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.Billing/billingAccounts/default/invoices/{invoiceName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<InvoiceInner>> getById(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("invoiceName") String invoiceName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/invoices/{invoiceName}/download")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> downloadInvoice(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("invoiceName") String invoiceName,
            @QueryParam("downloadToken") String downloadToken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/downloadDocuments")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> downloadMultipleBillingProfileInvoices(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("billingAccountName") String billingAccountName,
            @BodyParam("application/json") List<String> downloadUrls,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.Billing/billingAccounts/default/billingSubscriptions/{subscriptionId}/invoices")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<InvoiceListResult>> listByBillingSubscription(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("periodStartDate") String periodStartDate,
            @QueryParam("periodEndDate") String periodEndDate,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/providers/Microsoft.Billing/billingAccounts/default/billingSubscriptions/{subscriptionId}/invoices"
                + "/{invoiceName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<InvoiceInner>> getBySubscriptionAndInvoiceId(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("invoiceName") String invoiceName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/Microsoft.Billing/billingAccounts/default/billingSubscriptions/{subscriptionId}/invoices"
                + "/{invoiceName}/download")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> downloadBillingSubscriptionInvoice(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("invoiceName") String invoiceName,
            @QueryParam("downloadToken") String downloadToken,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/Microsoft.Billing/billingAccounts/default/billingSubscriptions/{subscriptionId}"
                + "/downloadDocuments")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> downloadMultipleBillingSubscriptionInvoices(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @BodyParam("application/json") List<String> downloadUrls,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Lists the invoices for a billing account for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 invoices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InvoiceInner>> listByBillingAccountSinglePageAsync(
        String billingAccountName, String periodStartDate, String periodEndDate) {
        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 (periodStartDate == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter periodStartDate is required and cannot be null."));
        }
        if (periodEndDate == null) {
            return Mono.error(new IllegalArgumentException("Parameter periodEndDate 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,
                            periodStartDate,
                            periodEndDate,
                            accept,
                            context))
            .<PagedResponse<InvoiceInner>>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 invoices for a billing account for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @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 invoices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InvoiceInner>> listByBillingAccountSinglePageAsync(
        String billingAccountName, String periodStartDate, String periodEndDate, 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 (periodStartDate == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter periodStartDate is required and cannot be null."));
        }
        if (periodEndDate == null) {
            return Mono.error(new IllegalArgumentException("Parameter periodEndDate 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,
                periodStartDate,
                periodEndDate,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Lists the invoices for a billing account for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 invoices as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<InvoiceInner> listByBillingAccountAsync(
        String billingAccountName, String periodStartDate, String periodEndDate) {
        return new PagedFlux<>(
            () -> listByBillingAccountSinglePageAsync(billingAccountName, periodStartDate, periodEndDate),
            nextLink -> listByBillingAccountNextSinglePageAsync(nextLink));
    }

    /**
     * Lists the invoices for a billing account for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @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 invoices as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<InvoiceInner> listByBillingAccountAsync(
        String billingAccountName, String periodStartDate, String periodEndDate, Context context) {
        return new PagedFlux<>(
            () -> listByBillingAccountSinglePageAsync(billingAccountName, periodStartDate, periodEndDate, context),
            nextLink -> listByBillingAccountNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists the invoices for a billing account for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 invoices as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<InvoiceInner> listByBillingAccount(
        String billingAccountName, String periodStartDate, String periodEndDate) {
        return new PagedIterable<>(listByBillingAccountAsync(billingAccountName, periodStartDate, periodEndDate));
    }

    /**
     * Lists the invoices for a billing account for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @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 invoices as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<InvoiceInner> listByBillingAccount(
        String billingAccountName, String periodStartDate, String periodEndDate, Context context) {
        return new PagedIterable<>(
            listByBillingAccountAsync(billingAccountName, periodStartDate, periodEndDate, context));
    }

    /**
     * Lists the invoices for a billing profile for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 invoices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InvoiceInner>> listByBillingProfileSinglePageAsync(
        String billingAccountName, String billingProfileName, String periodStartDate, String periodEndDate) {
        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."));
        }
        if (periodStartDate == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter periodStartDate is required and cannot be null."));
        }
        if (periodEndDate == null) {
            return Mono.error(new IllegalArgumentException("Parameter periodEndDate 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,
                            periodStartDate,
                            periodEndDate,
                            accept,
                            context))
            .<PagedResponse<InvoiceInner>>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 invoices for a billing profile for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @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 invoices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InvoiceInner>> listByBillingProfileSinglePageAsync(
        String billingAccountName,
        String billingProfileName,
        String periodStartDate,
        String periodEndDate,
        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."));
        }
        if (periodStartDate == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter periodStartDate is required and cannot be null."));
        }
        if (periodEndDate == null) {
            return Mono.error(new IllegalArgumentException("Parameter periodEndDate 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,
                periodStartDate,
                periodEndDate,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Lists the invoices for a billing profile for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 invoices as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<InvoiceInner> listByBillingProfileAsync(
        String billingAccountName, String billingProfileName, String periodStartDate, String periodEndDate) {
        return new PagedFlux<>(
            () ->
                listByBillingProfileSinglePageAsync(
                    billingAccountName, billingProfileName, periodStartDate, periodEndDate),
            nextLink -> listByBillingProfileNextSinglePageAsync(nextLink));
    }

    /**
     * Lists the invoices for a billing profile for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @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 invoices as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<InvoiceInner> listByBillingProfileAsync(
        String billingAccountName,
        String billingProfileName,
        String periodStartDate,
        String periodEndDate,
        Context context) {
        return new PagedFlux<>(
            () ->
                listByBillingProfileSinglePageAsync(
                    billingAccountName, billingProfileName, periodStartDate, periodEndDate, context),
            nextLink -> listByBillingProfileNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists the invoices for a billing profile for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 invoices as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<InvoiceInner> listByBillingProfile(
        String billingAccountName, String billingProfileName, String periodStartDate, String periodEndDate) {
        return new PagedIterable<>(
            listByBillingProfileAsync(billingAccountName, billingProfileName, periodStartDate, periodEndDate));
    }

    /**
     * Lists the invoices for a billing profile for a given start date and end date. The operation is supported for
     * billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param billingProfileName The ID that uniquely identifies a billing profile.
     * @param periodStartDate The start date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @param periodEndDate The end date to fetch the invoices. The date should be specified in MM-DD-YYYY format.
     * @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 invoices as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<InvoiceInner> listByBillingProfile(
        String billingAccountName,
        String billingProfileName,
        String periodStartDate,
        String periodEndDate,
        Context context) {
        return new PagedIterable<>(
            listByBillingProfileAsync(billingAccountName, billingProfileName, periodStartDate, periodEndDate, context));
    }

    /**
     * Gets an invoice by billing account name and ID. The operation is supported for billing accounts with agreement
     * type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an invoice by billing account name and ID along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<InvoiceInner>> getWithResponseAsync(String billingAccountName, String invoiceName) {
        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 (invoiceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter invoiceName is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(this.client.getEndpoint(), apiVersion, billingAccountName, invoiceName, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets an invoice by billing account name and ID. The operation is supported for billing accounts with agreement
     * type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @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 an invoice by billing account name and ID along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<InvoiceInner>> getWithResponseAsync(
        String billingAccountName, String invoiceName, 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 (invoiceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter invoiceName is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.get(this.client.getEndpoint(), apiVersion, billingAccountName, invoiceName, accept, context);
    }

    /**
     * Gets an invoice by billing account name and ID. The operation is supported for billing accounts with agreement
     * type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an invoice by billing account name and ID on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<InvoiceInner> getAsync(String billingAccountName, String invoiceName) {
        return getWithResponseAsync(billingAccountName, invoiceName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets an invoice by billing account name and ID. The operation is supported for billing accounts with agreement
     * type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @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 an invoice by billing account name and ID along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<InvoiceInner> getWithResponse(String billingAccountName, String invoiceName, Context context) {
        return getWithResponseAsync(billingAccountName, invoiceName, context).block();
    }

    /**
     * Gets an invoice by billing account name and ID. The operation is supported for billing accounts with agreement
     * type Microsoft Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an invoice by billing account name and ID.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public InvoiceInner get(String billingAccountName, String invoiceName) {
        return getWithResponse(billingAccountName, invoiceName, Context.NONE).getValue();
    }

    /**
     * Gets an invoice by ID. The operation is supported for billing accounts with agreement type Microsoft Partner
     * Agreement or Microsoft Customer Agreement.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an invoice by ID along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<InvoiceInner>> getByIdWithResponseAsync(String invoiceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (invoiceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter invoiceName is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context -> service.getById(this.client.getEndpoint(), apiVersion, invoiceName, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets an invoice by ID. The operation is supported for billing accounts with agreement type Microsoft Partner
     * Agreement or Microsoft Customer Agreement.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @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 an invoice by ID along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<InvoiceInner>> getByIdWithResponseAsync(String invoiceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (invoiceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter invoiceName is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.getById(this.client.getEndpoint(), apiVersion, invoiceName, accept, context);
    }

    /**
     * Gets an invoice by ID. The operation is supported for billing accounts with agreement type Microsoft Partner
     * Agreement or Microsoft Customer Agreement.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an invoice by ID on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<InvoiceInner> getByIdAsync(String invoiceName) {
        return getByIdWithResponseAsync(invoiceName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets an invoice by ID. The operation is supported for billing accounts with agreement type Microsoft Partner
     * Agreement or Microsoft Customer Agreement.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @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 an invoice by ID along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<InvoiceInner> getByIdWithResponse(String invoiceName, Context context) {
        return getByIdWithResponseAsync(invoiceName, context).block();
    }

    /**
     * Gets an invoice by ID. The operation is supported for billing accounts with agreement type Microsoft Partner
     * Agreement or Microsoft Customer Agreement.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an invoice by ID.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public InvoiceInner getById(String invoiceName) {
        return getByIdWithResponse(invoiceName, Context.NONE).getValue();
    }

    /**
     * Gets a URL to download an invoice. The operation is supported for billing accounts with agreement type Microsoft
     * Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download an invoice along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> downloadInvoiceWithResponseAsync(
        String billingAccountName, String invoiceName, String downloadToken) {
        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 (invoiceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter invoiceName is required and cannot be null."));
        }
        if (downloadToken == null) {
            return Mono.error(new IllegalArgumentException("Parameter downloadToken is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .downloadInvoice(
                            this.client.getEndpoint(),
                            apiVersion,
                            billingAccountName,
                            invoiceName,
                            downloadToken,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets a URL to download an invoice. The operation is supported for billing accounts with agreement type Microsoft
     * Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download an invoice along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> downloadInvoiceWithResponseAsync(
        String billingAccountName, String invoiceName, String downloadToken, 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 (invoiceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter invoiceName is required and cannot be null."));
        }
        if (downloadToken == null) {
            return Mono.error(new IllegalArgumentException("Parameter downloadToken is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .downloadInvoice(
                this.client.getEndpoint(), apiVersion, billingAccountName, invoiceName, downloadToken, accept, context);
    }

    /**
     * Gets a URL to download an invoice. The operation is supported for billing accounts with agreement type Microsoft
     * Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 a URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadInvoiceAsync(
        String billingAccountName, String invoiceName, String downloadToken) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            downloadInvoiceWithResponseAsync(billingAccountName, invoiceName, downloadToken);
        return this
            .client
            .<DownloadUrlInner, DownloadUrlInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DownloadUrlInner.class,
                DownloadUrlInner.class,
                this.client.getContext());
    }

    /**
     * Gets a URL to download an invoice. The operation is supported for billing accounts with agreement type Microsoft
     * Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @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 a URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadInvoiceAsync(
        String billingAccountName, String invoiceName, String downloadToken, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            downloadInvoiceWithResponseAsync(billingAccountName, invoiceName, downloadToken, context);
        return this
            .client
            .<DownloadUrlInner, DownloadUrlInner>getLroResult(
                mono, this.client.getHttpPipeline(), DownloadUrlInner.class, DownloadUrlInner.class, context);
    }

    /**
     * Gets a URL to download an invoice. The operation is supported for billing accounts with agreement type Microsoft
     * Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 a URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadInvoice(
        String billingAccountName, String invoiceName, String downloadToken) {
        return this.beginDownloadInvoiceAsync(billingAccountName, invoiceName, downloadToken).getSyncPoller();
    }

    /**
     * Gets a URL to download an invoice. The operation is supported for billing accounts with agreement type Microsoft
     * Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @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 a URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadInvoice(
        String billingAccountName, String invoiceName, String downloadToken, Context context) {
        return this.beginDownloadInvoiceAsync(billingAccountName, invoiceName, downloadToken, context).getSyncPoller();
    }

    /**
     * Gets a URL to download an invoice. The operation is supported for billing accounts with agreement type Microsoft
     * Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download an invoice on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DownloadUrlInner> downloadInvoiceAsync(
        String billingAccountName, String invoiceName, String downloadToken) {
        return beginDownloadInvoiceAsync(billingAccountName, invoiceName, downloadToken)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Gets a URL to download an invoice. The operation is supported for billing accounts with agreement type Microsoft
     * Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download an invoice on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DownloadUrlInner> downloadInvoiceAsync(
        String billingAccountName, String invoiceName, String downloadToken, Context context) {
        return beginDownloadInvoiceAsync(billingAccountName, invoiceName, downloadToken, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Gets a URL to download an invoice. The operation is supported for billing accounts with agreement type Microsoft
     * Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DownloadUrlInner downloadInvoice(String billingAccountName, String invoiceName, String downloadToken) {
        return downloadInvoiceAsync(billingAccountName, invoiceName, downloadToken).block();
    }

    /**
     * Gets a URL to download an invoice. The operation is supported for billing accounts with agreement type Microsoft
     * Partner Agreement or Microsoft Customer Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DownloadUrlInner downloadInvoice(
        String billingAccountName, String invoiceName, String downloadToken, Context context) {
        return downloadInvoiceAsync(billingAccountName, invoiceName, downloadToken, context).block();
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file. The
     * operation is supported for billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer
     * Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param downloadUrls An array of download urls for individual documents.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file
     *     along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> downloadMultipleBillingProfileInvoicesWithResponseAsync(
        String billingAccountName, List<String> downloadUrls) {
        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 (downloadUrls == null) {
            return Mono.error(new IllegalArgumentException("Parameter downloadUrls is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .downloadMultipleBillingProfileInvoices(
                            this.client.getEndpoint(), apiVersion, billingAccountName, downloadUrls, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file. The
     * operation is supported for billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer
     * Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param downloadUrls An array of download urls for individual documents.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file
     *     along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> downloadMultipleBillingProfileInvoicesWithResponseAsync(
        String billingAccountName, List<String> downloadUrls, 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 (downloadUrls == null) {
            return Mono.error(new IllegalArgumentException("Parameter downloadUrls is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .downloadMultipleBillingProfileInvoices(
                this.client.getEndpoint(), apiVersion, billingAccountName, downloadUrls, accept, context);
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file. The
     * operation is supported for billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer
     * Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param downloadUrls An array of download urls for individual documents.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 a URL to download multiple invoice documents (invoice pdf, tax
     *     receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadMultipleBillingProfileInvoicesAsync(
        String billingAccountName, List<String> downloadUrls) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            downloadMultipleBillingProfileInvoicesWithResponseAsync(billingAccountName, downloadUrls);
        return this
            .client
            .<DownloadUrlInner, DownloadUrlInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DownloadUrlInner.class,
                DownloadUrlInner.class,
                this.client.getContext());
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file. The
     * operation is supported for billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer
     * Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param downloadUrls An array of download urls for individual documents.
     * @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 a URL to download multiple invoice documents (invoice pdf, tax
     *     receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadMultipleBillingProfileInvoicesAsync(
        String billingAccountName, List<String> downloadUrls, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            downloadMultipleBillingProfileInvoicesWithResponseAsync(billingAccountName, downloadUrls, context);
        return this
            .client
            .<DownloadUrlInner, DownloadUrlInner>getLroResult(
                mono, this.client.getHttpPipeline(), DownloadUrlInner.class, DownloadUrlInner.class, context);
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file. The
     * operation is supported for billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer
     * Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param downloadUrls An array of download urls for individual documents.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 a URL to download multiple invoice documents (invoice pdf, tax
     *     receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadMultipleBillingProfileInvoices(
        String billingAccountName, List<String> downloadUrls) {
        return this.beginDownloadMultipleBillingProfileInvoicesAsync(billingAccountName, downloadUrls).getSyncPoller();
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file. The
     * operation is supported for billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer
     * Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param downloadUrls An array of download urls for individual documents.
     * @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 a URL to download multiple invoice documents (invoice pdf, tax
     *     receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadMultipleBillingProfileInvoices(
        String billingAccountName, List<String> downloadUrls, Context context) {
        return this
            .beginDownloadMultipleBillingProfileInvoicesAsync(billingAccountName, downloadUrls, context)
            .getSyncPoller();
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file. The
     * operation is supported for billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer
     * Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param downloadUrls An array of download urls for individual documents.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DownloadUrlInner> downloadMultipleBillingProfileInvoicesAsync(
        String billingAccountName, List<String> downloadUrls) {
        return beginDownloadMultipleBillingProfileInvoicesAsync(billingAccountName, downloadUrls)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file. The
     * operation is supported for billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer
     * Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param downloadUrls An array of download urls for individual documents.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DownloadUrlInner> downloadMultipleBillingProfileInvoicesAsync(
        String billingAccountName, List<String> downloadUrls, Context context) {
        return beginDownloadMultipleBillingProfileInvoicesAsync(billingAccountName, downloadUrls, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file. The
     * operation is supported for billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer
     * Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param downloadUrls An array of download urls for individual documents.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DownloadUrlInner downloadMultipleBillingProfileInvoices(
        String billingAccountName, List<String> downloadUrls) {
        return downloadMultipleBillingProfileInvoicesAsync(billingAccountName, downloadUrls).block();
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file. The
     * operation is supported for billing accounts with agreement type Microsoft Partner Agreement or Microsoft Customer
     * Agreement.
     *
     * @param billingAccountName The ID that uniquely identifies a billing account.
     * @param downloadUrls An array of download urls for individual documents.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DownloadUrlInner downloadMultipleBillingProfileInvoices(
        String billingAccountName, List<String> downloadUrls, Context context) {
        return downloadMultipleBillingProfileInvoicesAsync(billingAccountName, downloadUrls, context).block();
    }

    /**
     * Lists the invoices for a subscription.
     *
     * @param periodStartDate Invoice period start date.
     * @param periodEndDate Invoice period end date.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 invoices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InvoiceInner>> listByBillingSubscriptionSinglePageAsync(
        String periodStartDate, String periodEndDate) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (periodStartDate == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter periodStartDate is required and cannot be null."));
        }
        if (periodEndDate == null) {
            return Mono.error(new IllegalArgumentException("Parameter periodEndDate is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByBillingSubscription(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            periodStartDate,
                            periodEndDate,
                            apiVersion,
                            accept,
                            context))
            .<PagedResponse<InvoiceInner>>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 invoices for a subscription.
     *
     * @param periodStartDate Invoice period start date.
     * @param periodEndDate Invoice period end date.
     * @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 invoices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InvoiceInner>> listByBillingSubscriptionSinglePageAsync(
        String periodStartDate, String periodEndDate, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (periodStartDate == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter periodStartDate is required and cannot be null."));
        }
        if (periodEndDate == null) {
            return Mono.error(new IllegalArgumentException("Parameter periodEndDate is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByBillingSubscription(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                periodStartDate,
                periodEndDate,
                apiVersion,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Lists the invoices for a subscription.
     *
     * @param periodStartDate Invoice period start date.
     * @param periodEndDate Invoice period end date.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 invoices as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<InvoiceInner> listByBillingSubscriptionAsync(String periodStartDate, String periodEndDate) {
        return new PagedFlux<>(
            () -> listByBillingSubscriptionSinglePageAsync(periodStartDate, periodEndDate),
            nextLink -> listByBillingSubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Lists the invoices for a subscription.
     *
     * @param periodStartDate Invoice period start date.
     * @param periodEndDate Invoice period end date.
     * @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 invoices as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<InvoiceInner> listByBillingSubscriptionAsync(
        String periodStartDate, String periodEndDate, Context context) {
        return new PagedFlux<>(
            () -> listByBillingSubscriptionSinglePageAsync(periodStartDate, periodEndDate, context),
            nextLink -> listByBillingSubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists the invoices for a subscription.
     *
     * @param periodStartDate Invoice period start date.
     * @param periodEndDate Invoice period end date.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 invoices as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<InvoiceInner> listByBillingSubscription(String periodStartDate, String periodEndDate) {
        return new PagedIterable<>(listByBillingSubscriptionAsync(periodStartDate, periodEndDate));
    }

    /**
     * Lists the invoices for a subscription.
     *
     * @param periodStartDate Invoice period start date.
     * @param periodEndDate Invoice period end date.
     * @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 invoices as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<InvoiceInner> listByBillingSubscription(
        String periodStartDate, String periodEndDate, Context context) {
        return new PagedIterable<>(listByBillingSubscriptionAsync(periodStartDate, periodEndDate, context));
    }

    /**
     * Gets an invoice by subscription ID and invoice ID.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an invoice by subscription ID and invoice ID along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<InvoiceInner>> getBySubscriptionAndInvoiceIdWithResponseAsync(String invoiceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (invoiceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter invoiceName is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getBySubscriptionAndInvoiceId(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            invoiceName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets an invoice by subscription ID and invoice ID.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @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 an invoice by subscription ID and invoice ID along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<InvoiceInner>> getBySubscriptionAndInvoiceIdWithResponseAsync(
        String invoiceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (invoiceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter invoiceName is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getBySubscriptionAndInvoiceId(
                this.client.getEndpoint(), this.client.getSubscriptionId(), invoiceName, apiVersion, accept, context);
    }

    /**
     * Gets an invoice by subscription ID and invoice ID.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an invoice by subscription ID and invoice ID on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<InvoiceInner> getBySubscriptionAndInvoiceIdAsync(String invoiceName) {
        return getBySubscriptionAndInvoiceIdWithResponseAsync(invoiceName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets an invoice by subscription ID and invoice ID.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @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 an invoice by subscription ID and invoice ID along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<InvoiceInner> getBySubscriptionAndInvoiceIdWithResponse(String invoiceName, Context context) {
        return getBySubscriptionAndInvoiceIdWithResponseAsync(invoiceName, context).block();
    }

    /**
     * Gets an invoice by subscription ID and invoice ID.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an invoice by subscription ID and invoice ID.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public InvoiceInner getBySubscriptionAndInvoiceId(String invoiceName) {
        return getBySubscriptionAndInvoiceIdWithResponse(invoiceName, Context.NONE).getValue();
    }

    /**
     * Gets a URL to download an invoice.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download an invoice along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> downloadBillingSubscriptionInvoiceWithResponseAsync(
        String invoiceName, String downloadToken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (invoiceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter invoiceName is required and cannot be null."));
        }
        if (downloadToken == null) {
            return Mono.error(new IllegalArgumentException("Parameter downloadToken is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .downloadBillingSubscriptionInvoice(
                            this.client.getEndpoint(),
                            apiVersion,
                            this.client.getSubscriptionId(),
                            invoiceName,
                            downloadToken,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets a URL to download an invoice.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download an invoice along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> downloadBillingSubscriptionInvoiceWithResponseAsync(
        String invoiceName, String downloadToken, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (invoiceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter invoiceName is required and cannot be null."));
        }
        if (downloadToken == null) {
            return Mono.error(new IllegalArgumentException("Parameter downloadToken is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .downloadBillingSubscriptionInvoice(
                this.client.getEndpoint(),
                apiVersion,
                this.client.getSubscriptionId(),
                invoiceName,
                downloadToken,
                accept,
                context);
    }

    /**
     * Gets a URL to download an invoice.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 a URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadBillingSubscriptionInvoiceAsync(
        String invoiceName, String downloadToken) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            downloadBillingSubscriptionInvoiceWithResponseAsync(invoiceName, downloadToken);
        return this
            .client
            .<DownloadUrlInner, DownloadUrlInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DownloadUrlInner.class,
                DownloadUrlInner.class,
                this.client.getContext());
    }

    /**
     * Gets a URL to download an invoice.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @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 a URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadBillingSubscriptionInvoiceAsync(
        String invoiceName, String downloadToken, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            downloadBillingSubscriptionInvoiceWithResponseAsync(invoiceName, downloadToken, context);
        return this
            .client
            .<DownloadUrlInner, DownloadUrlInner>getLroResult(
                mono, this.client.getHttpPipeline(), DownloadUrlInner.class, DownloadUrlInner.class, context);
    }

    /**
     * Gets a URL to download an invoice.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 a URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadBillingSubscriptionInvoice(
        String invoiceName, String downloadToken) {
        return this.beginDownloadBillingSubscriptionInvoiceAsync(invoiceName, downloadToken).getSyncPoller();
    }

    /**
     * Gets a URL to download an invoice.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @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 a URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadBillingSubscriptionInvoice(
        String invoiceName, String downloadToken, Context context) {
        return this.beginDownloadBillingSubscriptionInvoiceAsync(invoiceName, downloadToken, context).getSyncPoller();
    }

    /**
     * Gets a URL to download an invoice.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download an invoice on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DownloadUrlInner> downloadBillingSubscriptionInvoiceAsync(String invoiceName, String downloadToken) {
        return beginDownloadBillingSubscriptionInvoiceAsync(invoiceName, downloadToken)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Gets a URL to download an invoice.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download an invoice on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DownloadUrlInner> downloadBillingSubscriptionInvoiceAsync(
        String invoiceName, String downloadToken, Context context) {
        return beginDownloadBillingSubscriptionInvoiceAsync(invoiceName, downloadToken, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Gets a URL to download an invoice.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DownloadUrlInner downloadBillingSubscriptionInvoice(String invoiceName, String downloadToken) {
        return downloadBillingSubscriptionInvoiceAsync(invoiceName, downloadToken).block();
    }

    /**
     * Gets a URL to download an invoice.
     *
     * @param invoiceName The ID that uniquely identifies an invoice.
     * @param downloadToken Download token with document source and document ID.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download an invoice.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DownloadUrlInner downloadBillingSubscriptionInvoice(
        String invoiceName, String downloadToken, Context context) {
        return downloadBillingSubscriptionInvoiceAsync(invoiceName, downloadToken, context).block();
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     *
     * @param downloadUrls An array of download urls for individual documents.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file
     *     along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> downloadMultipleBillingSubscriptionInvoicesWithResponseAsync(
        List<String> downloadUrls) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (downloadUrls == null) {
            return Mono.error(new IllegalArgumentException("Parameter downloadUrls is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .downloadMultipleBillingSubscriptionInvoices(
                            this.client.getEndpoint(),
                            apiVersion,
                            this.client.getSubscriptionId(),
                            downloadUrls,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     *
     * @param downloadUrls An array of download urls for individual documents.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file
     *     along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> downloadMultipleBillingSubscriptionInvoicesWithResponseAsync(
        List<String> downloadUrls, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (downloadUrls == null) {
            return Mono.error(new IllegalArgumentException("Parameter downloadUrls is required and cannot be null."));
        }
        final String apiVersion = "2020-05-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .downloadMultipleBillingSubscriptionInvoices(
                this.client.getEndpoint(), apiVersion, this.client.getSubscriptionId(), downloadUrls, accept, context);
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     *
     * @param downloadUrls An array of download urls for individual documents.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 a URL to download multiple invoice documents (invoice pdf, tax
     *     receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DownloadUrlInner>, DownloadUrlInner>
        beginDownloadMultipleBillingSubscriptionInvoicesAsync(List<String> downloadUrls) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            downloadMultipleBillingSubscriptionInvoicesWithResponseAsync(downloadUrls);
        return this
            .client
            .<DownloadUrlInner, DownloadUrlInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DownloadUrlInner.class,
                DownloadUrlInner.class,
                this.client.getContext());
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     *
     * @param downloadUrls An array of download urls for individual documents.
     * @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 a URL to download multiple invoice documents (invoice pdf, tax
     *     receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DownloadUrlInner>, DownloadUrlInner>
        beginDownloadMultipleBillingSubscriptionInvoicesAsync(List<String> downloadUrls, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            downloadMultipleBillingSubscriptionInvoicesWithResponseAsync(downloadUrls, context);
        return this
            .client
            .<DownloadUrlInner, DownloadUrlInner>getLroResult(
                mono, this.client.getHttpPipeline(), DownloadUrlInner.class, DownloadUrlInner.class, context);
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     *
     * @param downloadUrls An array of download urls for individual documents.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 a URL to download multiple invoice documents (invoice pdf, tax
     *     receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadMultipleBillingSubscriptionInvoices(
        List<String> downloadUrls) {
        return this.beginDownloadMultipleBillingSubscriptionInvoicesAsync(downloadUrls).getSyncPoller();
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     *
     * @param downloadUrls An array of download urls for individual documents.
     * @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 a URL to download multiple invoice documents (invoice pdf, tax
     *     receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DownloadUrlInner>, DownloadUrlInner> beginDownloadMultipleBillingSubscriptionInvoices(
        List<String> downloadUrls, Context context) {
        return this.beginDownloadMultipleBillingSubscriptionInvoicesAsync(downloadUrls, context).getSyncPoller();
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     *
     * @param downloadUrls An array of download urls for individual documents.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DownloadUrlInner> downloadMultipleBillingSubscriptionInvoicesAsync(List<String> downloadUrls) {
        return beginDownloadMultipleBillingSubscriptionInvoicesAsync(downloadUrls)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     *
     * @param downloadUrls An array of download urls for individual documents.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DownloadUrlInner> downloadMultipleBillingSubscriptionInvoicesAsync(
        List<String> downloadUrls, Context context) {
        return beginDownloadMultipleBillingSubscriptionInvoicesAsync(downloadUrls, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     *
     * @param downloadUrls An array of download urls for individual documents.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DownloadUrlInner downloadMultipleBillingSubscriptionInvoices(List<String> downloadUrls) {
        return downloadMultipleBillingSubscriptionInvoicesAsync(downloadUrls).block();
    }

    /**
     * Gets a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     *
     * @param downloadUrls An array of download urls for individual documents.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a URL to download multiple invoice documents (invoice pdf, tax receipts, credit notes) as a zip file.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DownloadUrlInner downloadMultipleBillingSubscriptionInvoices(List<String> downloadUrls, Context context) {
        return downloadMultipleBillingSubscriptionInvoicesAsync(downloadUrls, context).block();
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of invoices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InvoiceInner>> 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<InvoiceInner>>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 invoices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InvoiceInner>> 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 invoices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InvoiceInner>> 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<InvoiceInner>>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 invoices along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<InvoiceInner>> 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));
    }

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