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

package com.azure.resourcemanager.education.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Post;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.resourcemanager.education.fluent.LabsClient;
import com.azure.resourcemanager.education.fluent.models.LabDetailsInner;
import com.azure.resourcemanager.education.models.InviteCodeGenerateRequest;
import com.azure.resourcemanager.education.models.LabListResult;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for EducationManagementClientLabs to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "EducationManagementC")
    private interface LabsService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}"
                + "/providers/Microsoft.Education/labs")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<LabListResult>> listAll(
            @HostParam("$host") String endpoint,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("billingProfileName") String billingProfileName,
            @QueryParam("includeBudget") Boolean includeBudget,
            @QueryParam("includeDeleted") Boolean includeDeleted,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}"
                + "/invoiceSections/{invoiceSectionName}/providers/Microsoft.Education/labs")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<LabListResult>> list(
            @HostParam("$host") String endpoint,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("billingProfileName") String billingProfileName,
            @PathParam("invoiceSectionName") String invoiceSectionName,
            @QueryParam("includeBudget") Boolean includeBudget,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}"
                + "/invoiceSections/{invoiceSectionName}/providers/Microsoft.Education/labs/default")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<LabDetailsInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("billingProfileName") String billingProfileName,
            @PathParam("invoiceSectionName") String invoiceSectionName,
            @QueryParam("includeBudget") Boolean includeBudget,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}"
                + "/invoiceSections/{invoiceSectionName}/providers/Microsoft.Education/labs/default")
        @ExpectedResponses({200, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> delete(
            @HostParam("$host") String endpoint,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("billingProfileName") String billingProfileName,
            @PathParam("invoiceSectionName") String invoiceSectionName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}"
                + "/invoiceSections/{invoiceSectionName}/providers/Microsoft.Education/labs/default")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<LabDetailsInner>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("billingProfileName") String billingProfileName,
            @PathParam("invoiceSectionName") String invoiceSectionName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") LabDetailsInner parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}"
                + "/invoiceSections/{invoiceSectionName}/providers/Microsoft.Education/labs/default/generateInviteCode")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<LabDetailsInner>> generateInviteCode(
            @HostParam("$host") String endpoint,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("billingProfileName") String billingProfileName,
            @PathParam("invoiceSectionName") String invoiceSectionName,
            @QueryParam("onlyUpdateStudentCountParameter") Boolean onlyUpdateStudentCountParameter,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") InviteCodeGenerateRequest parameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Get a list of labs associated with the provided billing account name and billing profile name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param includeBudget May be used to include budget information.
     * @param includeDeleted May be used to show deleted items.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 list of labs associated with the provided billing account name and billing profile name along with
     *     {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabDetailsInner>> listAllSinglePageAsync(
        String billingAccountName, String billingProfileName, Boolean includeBudget, Boolean includeDeleted) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (billingAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter billingAccountName is required and cannot be null."));
        }
        if (billingProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter billingProfileName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listAll(
                            this.client.getEndpoint(),
                            billingAccountName,
                            billingProfileName,
                            includeBudget,
                            includeDeleted,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<LabDetailsInner>>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 a list of labs associated with the provided billing account name and billing profile name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param includeBudget May be used to include budget information.
     * @param includeDeleted May be used to show deleted items.
     * @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 list of labs associated with the provided billing account name and billing profile name along with
     *     {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabDetailsInner>> listAllSinglePageAsync(
        String billingAccountName,
        String billingProfileName,
        Boolean includeBudget,
        Boolean includeDeleted,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (billingAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter billingAccountName is required and cannot be null."));
        }
        if (billingProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter billingProfileName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listAll(
                this.client.getEndpoint(),
                billingAccountName,
                billingProfileName,
                includeBudget,
                includeDeleted,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get a list of labs associated with the provided billing account name and billing profile name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param includeBudget May be used to include budget information.
     * @param includeDeleted May be used to show deleted items.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 list of labs associated with the provided billing account name and billing profile name as paginated
     *     response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<LabDetailsInner> listAllAsync(
        String billingAccountName, String billingProfileName, Boolean includeBudget, Boolean includeDeleted) {
        return new PagedFlux<>(
            () -> listAllSinglePageAsync(billingAccountName, billingProfileName, includeBudget, includeDeleted),
            nextLink -> listAllNextSinglePageAsync(nextLink));
    }

    /**
     * Get a list of labs associated with the provided billing account name and billing profile name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 list of labs associated with the provided billing account name and billing profile name as paginated
     *     response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<LabDetailsInner> listAllAsync(String billingAccountName, String billingProfileName) {
        final Boolean includeBudget = null;
        final Boolean includeDeleted = null;
        return new PagedFlux<>(
            () -> listAllSinglePageAsync(billingAccountName, billingProfileName, includeBudget, includeDeleted),
            nextLink -> listAllNextSinglePageAsync(nextLink));
    }

    /**
     * Get a list of labs associated with the provided billing account name and billing profile name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param includeBudget May be used to include budget information.
     * @param includeDeleted May be used to show deleted items.
     * @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 list of labs associated with the provided billing account name and billing profile name as paginated
     *     response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<LabDetailsInner> listAllAsync(
        String billingAccountName,
        String billingProfileName,
        Boolean includeBudget,
        Boolean includeDeleted,
        Context context) {
        return new PagedFlux<>(
            () ->
                listAllSinglePageAsync(billingAccountName, billingProfileName, includeBudget, includeDeleted, context),
            nextLink -> listAllNextSinglePageAsync(nextLink, context));
    }

    /**
     * Get a list of labs associated with the provided billing account name and billing profile name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 list of labs associated with the provided billing account name and billing profile name as paginated
     *     response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<LabDetailsInner> listAll(String billingAccountName, String billingProfileName) {
        final Boolean includeBudget = null;
        final Boolean includeDeleted = null;
        return new PagedIterable<>(listAllAsync(billingAccountName, billingProfileName, includeBudget, includeDeleted));
    }

    /**
     * Get a list of labs associated with the provided billing account name and billing profile name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param includeBudget May be used to include budget information.
     * @param includeDeleted May be used to show deleted items.
     * @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 list of labs associated with the provided billing account name and billing profile name as paginated
     *     response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<LabDetailsInner> listAll(
        String billingAccountName,
        String billingProfileName,
        Boolean includeBudget,
        Boolean includeDeleted,
        Context context) {
        return new PagedIterable<>(
            listAllAsync(billingAccountName, billingProfileName, includeBudget, includeDeleted, context));
    }

    /**
     * Get the details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeBudget May be used to include budget information.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabDetailsInner>> listSinglePageAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, Boolean includeBudget) {
        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 (invoiceSectionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter invoiceSectionName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            billingAccountName,
                            billingProfileName,
                            invoiceSectionName,
                            includeBudget,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<LabDetailsInner>>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 details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeBudget May be used to include budget information.
     * @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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabDetailsInner>> listSinglePageAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        Boolean includeBudget,
        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 (invoiceSectionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter invoiceSectionName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                billingAccountName,
                billingProfileName,
                invoiceSectionName,
                includeBudget,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get the details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeBudget May be used to include budget information.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<LabDetailsInner> listAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, Boolean includeBudget) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(billingAccountName, billingProfileName, invoiceSectionName, includeBudget),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Get the details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<LabDetailsInner> listAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName) {
        final Boolean includeBudget = null;
        return new PagedFlux<>(
            () -> listSinglePageAsync(billingAccountName, billingProfileName, invoiceSectionName, includeBudget),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Get the details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeBudget May be used to include budget information.
     * @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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<LabDetailsInner> listAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        Boolean includeBudget,
        Context context) {
        return new PagedFlux<>(
            () ->
                listSinglePageAsync(billingAccountName, billingProfileName, invoiceSectionName, includeBudget, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Get the details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<LabDetailsInner> list(
        String billingAccountName, String billingProfileName, String invoiceSectionName) {
        final Boolean includeBudget = null;
        return new PagedIterable<>(
            listAsync(billingAccountName, billingProfileName, invoiceSectionName, includeBudget));
    }

    /**
     * Get the details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeBudget May be used to include budget information.
     * @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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<LabDetailsInner> list(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        Boolean includeBudget,
        Context context) {
        return new PagedIterable<>(
            listAsync(billingAccountName, billingProfileName, invoiceSectionName, includeBudget, context));
    }

    /**
     * Get the details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeBudget May be used to include budget information.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<LabDetailsInner>> getWithResponseAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, Boolean includeBudget) {
        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 (invoiceSectionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter invoiceSectionName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            billingAccountName,
                            billingProfileName,
                            invoiceSectionName,
                            includeBudget,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeBudget May be used to include budget information.
     * @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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<LabDetailsInner>> getWithResponseAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        Boolean includeBudget,
        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 (invoiceSectionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter invoiceSectionName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                billingAccountName,
                billingProfileName,
                invoiceSectionName,
                includeBudget,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Get the details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<LabDetailsInner> getAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName) {
        final Boolean includeBudget = null;
        return getWithResponseAsync(billingAccountName, billingProfileName, invoiceSectionName, includeBudget)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get the details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeBudget May be used to include budget information.
     * @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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<LabDetailsInner> getWithResponse(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        Boolean includeBudget,
        Context context) {
        return getWithResponseAsync(billingAccountName, billingProfileName, invoiceSectionName, includeBudget, context)
            .block();
    }

    /**
     * Get the details for a specific lab associated with the provided billing account name, billing profile name, and
     * invoice section name.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 details for a specific lab associated with the provided billing account name, billing profile name,
     *     and invoice section name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public LabDetailsInner get(String billingAccountName, String billingProfileName, String invoiceSectionName) {
        final Boolean includeBudget = null;
        return getWithResponse(billingAccountName, billingProfileName, invoiceSectionName, includeBudget, Context.NONE)
            .getValue();
    }

    /**
     * Delete a specific lab associated with the provided billing account name, billing profile name, and invoice
     * section name. Note all students must be removed from the lab in order to delete the lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName) {
        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 (invoiceSectionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter invoiceSectionName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            billingAccountName,
                            billingProfileName,
                            invoiceSectionName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a specific lab associated with the provided billing account name, billing profile name, and invoice
     * section name. Note all students must be removed from the lab in order to delete the lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, 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 (invoiceSectionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter invoiceSectionName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                billingAccountName,
                billingProfileName,
                invoiceSectionName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Delete a specific lab associated with the provided billing account name, billing profile name, and invoice
     * section name. Note all students must be removed from the lab in order to delete the lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String billingAccountName, String billingProfileName, String invoiceSectionName) {
        return deleteWithResponseAsync(billingAccountName, billingProfileName, invoiceSectionName)
            .flatMap(ignored -> Mono.empty());
    }

    /**
     * Delete a specific lab associated with the provided billing account name, billing profile name, and invoice
     * section name. Note all students must be removed from the lab in order to delete the lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(
        String billingAccountName, String billingProfileName, String invoiceSectionName, Context context) {
        return deleteWithResponseAsync(billingAccountName, billingProfileName, invoiceSectionName, context).block();
    }

    /**
     * Delete a specific lab associated with the provided billing account name, billing profile name, and invoice
     * section name. Note all students must be removed from the lab in order to delete the lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String billingAccountName, String billingProfileName, String invoiceSectionName) {
        deleteWithResponse(billingAccountName, billingProfileName, invoiceSectionName, Context.NONE);
    }

    /**
     * Create a new lab or update a previously created lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param parameters Request parameters that are provided to create lab resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return lab details along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<LabDetailsInner>> createOrUpdateWithResponseAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, LabDetailsInner parameters) {
        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 (invoiceSectionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter invoiceSectionName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            billingAccountName,
                            billingProfileName,
                            invoiceSectionName,
                            this.client.getApiVersion(),
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create a new lab or update a previously created lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param parameters Request parameters that are provided to create lab resource.
     * @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 lab details along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<LabDetailsInner>> createOrUpdateWithResponseAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        LabDetailsInner parameters,
        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 (invoiceSectionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter invoiceSectionName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                billingAccountName,
                billingProfileName,
                invoiceSectionName,
                this.client.getApiVersion(),
                parameters,
                accept,
                context);
    }

    /**
     * Create a new lab or update a previously created lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param parameters Request parameters that are provided to create lab resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return lab details on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<LabDetailsInner> createOrUpdateAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, LabDetailsInner parameters) {
        return createOrUpdateWithResponseAsync(billingAccountName, billingProfileName, invoiceSectionName, parameters)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Create a new lab or update a previously created lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param parameters Request parameters that are provided to create lab resource.
     * @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 lab details along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<LabDetailsInner> createOrUpdateWithResponse(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        LabDetailsInner parameters,
        Context context) {
        return createOrUpdateWithResponseAsync(
                billingAccountName, billingProfileName, invoiceSectionName, parameters, context)
            .block();
    }

    /**
     * Create a new lab or update a previously created lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param parameters Request parameters that are provided to create lab resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return lab details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public LabDetailsInner createOrUpdate(
        String billingAccountName, String billingProfileName, String invoiceSectionName, LabDetailsInner parameters) {
        return createOrUpdateWithResponse(
                billingAccountName, billingProfileName, invoiceSectionName, parameters, Context.NONE)
            .getValue();
    }

    /**
     * Generate invite code for a lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param parameters Request parameters that are provided to generate invite code.
     * @param onlyUpdateStudentCountParameter set this flag to true if you want to update student count without
     *     generating a new invite code.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return lab details along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<LabDetailsInner>> generateInviteCodeWithResponseAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        InviteCodeGenerateRequest parameters,
        Boolean onlyUpdateStudentCountParameter) {
        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 (invoiceSectionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter invoiceSectionName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .generateInviteCode(
                            this.client.getEndpoint(),
                            billingAccountName,
                            billingProfileName,
                            invoiceSectionName,
                            onlyUpdateStudentCountParameter,
                            this.client.getApiVersion(),
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Generate invite code for a lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param parameters Request parameters that are provided to generate invite code.
     * @param onlyUpdateStudentCountParameter set this flag to true if you want to update student count without
     *     generating a new invite code.
     * @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 lab details along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<LabDetailsInner>> generateInviteCodeWithResponseAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        InviteCodeGenerateRequest parameters,
        Boolean onlyUpdateStudentCountParameter,
        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 (invoiceSectionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter invoiceSectionName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .generateInviteCode(
                this.client.getEndpoint(),
                billingAccountName,
                billingProfileName,
                invoiceSectionName,
                onlyUpdateStudentCountParameter,
                this.client.getApiVersion(),
                parameters,
                accept,
                context);
    }

    /**
     * Generate invite code for a lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param parameters Request parameters that are provided to generate invite code.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return lab details on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<LabDetailsInner> generateInviteCodeAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        InviteCodeGenerateRequest parameters) {
        final Boolean onlyUpdateStudentCountParameter = null;
        return generateInviteCodeWithResponseAsync(
                billingAccountName, billingProfileName, invoiceSectionName, parameters, onlyUpdateStudentCountParameter)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Generate invite code for a lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param parameters Request parameters that are provided to generate invite code.
     * @param onlyUpdateStudentCountParameter set this flag to true if you want to update student count without
     *     generating a new invite code.
     * @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 lab details along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<LabDetailsInner> generateInviteCodeWithResponse(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        InviteCodeGenerateRequest parameters,
        Boolean onlyUpdateStudentCountParameter,
        Context context) {
        return generateInviteCodeWithResponseAsync(
                billingAccountName,
                billingProfileName,
                invoiceSectionName,
                parameters,
                onlyUpdateStudentCountParameter,
                context)
            .block();
    }

    /**
     * Generate invite code for a lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param parameters Request parameters that are provided to generate invite code.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return lab details.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public LabDetailsInner generateInviteCode(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        InviteCodeGenerateRequest parameters) {
        final Boolean onlyUpdateStudentCountParameter = null;
        return generateInviteCodeWithResponse(
                billingAccountName,
                billingProfileName,
                invoiceSectionName,
                parameters,
                onlyUpdateStudentCountParameter,
                Context.NONE)
            .getValue();
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of labs along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabDetailsInner>> listAllNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listAllNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<LabDetailsInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of labs along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabDetailsInner>> listAllNextSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listAllNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of labs along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabDetailsInner>> listNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<LabDetailsInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of labs along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabDetailsInner>> listNextSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
