// 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.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.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.resourcemanager.education.fluent.JoinRequestsClient;
import com.azure.resourcemanager.education.fluent.models.JoinRequestDetailsInner;
import com.azure.resourcemanager.education.models.JoinRequestList;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for EducationManagementClientJoinRequests to be used by the proxy service
     * to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "EducationManagementC")
    private interface JoinRequestsService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/providers/Microsoft.Billing/billingAccounts/{billingAccountName}/billingProfiles/{billingProfileName}"
                + "/invoiceSections/{invoiceSectionName}/providers/Microsoft.Education/labs/default/joinRequests")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<JoinRequestList>> list(
            @HostParam("$host") String endpoint,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("billingProfileName") String billingProfileName,
            @PathParam("invoiceSectionName") String invoiceSectionName,
            @QueryParam("includeDenied") Boolean includeDenied,
            @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/joinRequests"
                + "/{joinRequestName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<JoinRequestDetailsInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("billingProfileName") String billingProfileName,
            @PathParam("invoiceSectionName") String invoiceSectionName,
            @PathParam("joinRequestName") String joinRequestName,
            @QueryParam("api-version") String apiVersion,
            @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/joinRequests"
                + "/{joinRequestName}/approve")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> approve(
            @HostParam("$host") String endpoint,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("billingProfileName") String billingProfileName,
            @PathParam("invoiceSectionName") String invoiceSectionName,
            @PathParam("joinRequestName") String joinRequestName,
            @QueryParam("api-version") String apiVersion,
            @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/joinRequests"
                + "/{joinRequestName}/deny")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> deny(
            @HostParam("$host") String endpoint,
            @PathParam("billingAccountName") String billingAccountName,
            @PathParam("billingProfileName") String billingProfileName,
            @PathParam("invoiceSectionName") String invoiceSectionName,
            @PathParam("joinRequestName") String joinRequestName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * get student join requests.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeDenied Include denied.
     * @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 student join requests along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<JoinRequestDetailsInner>> listSinglePageAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, Boolean includeDenied) {
        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,
                            includeDenied,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<JoinRequestDetailsInner>>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 student join requests.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeDenied Include denied.
     * @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 student join requests along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<JoinRequestDetailsInner>> listSinglePageAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        Boolean includeDenied,
        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,
                includeDenied,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * get student join requests.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeDenied Include denied.
     * @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 student join requests as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<JoinRequestDetailsInner> listAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, Boolean includeDenied) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(billingAccountName, billingProfileName, invoiceSectionName, includeDenied),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * get student join requests.
     *
     * @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 student join requests as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<JoinRequestDetailsInner> listAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName) {
        final Boolean includeDenied = null;
        return new PagedFlux<>(
            () -> listSinglePageAsync(billingAccountName, billingProfileName, invoiceSectionName, includeDenied),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * get student join requests.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeDenied Include denied.
     * @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 student join requests as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<JoinRequestDetailsInner> listAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        Boolean includeDenied,
        Context context) {
        return new PagedFlux<>(
            () ->
                listSinglePageAsync(billingAccountName, billingProfileName, invoiceSectionName, includeDenied, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * get student join requests.
     *
     * @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 student join requests as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<JoinRequestDetailsInner> list(
        String billingAccountName, String billingProfileName, String invoiceSectionName) {
        final Boolean includeDenied = null;
        return new PagedIterable<>(
            listAsync(billingAccountName, billingProfileName, invoiceSectionName, includeDenied));
    }

    /**
     * get student join requests.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param includeDenied Include denied.
     * @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 student join requests as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<JoinRequestDetailsInner> list(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        Boolean includeDenied,
        Context context) {
        return new PagedIterable<>(
            listAsync(billingAccountName, billingProfileName, invoiceSectionName, includeDenied, context));
    }

    /**
     * get student join requests.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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 student join requests along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JoinRequestDetailsInner>> getWithResponseAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, String joinRequestName) {
        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 (joinRequestName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter joinRequestName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            billingAccountName,
                            billingProfileName,
                            invoiceSectionName,
                            joinRequestName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * get student join requests.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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 student join requests along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JoinRequestDetailsInner>> getWithResponseAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        String joinRequestName,
        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 (joinRequestName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter joinRequestName 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,
                joinRequestName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * get student join requests.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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 student join requests on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<JoinRequestDetailsInner> getAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, String joinRequestName) {
        return getWithResponseAsync(billingAccountName, billingProfileName, invoiceSectionName, joinRequestName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * get student join requests.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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 student join requests along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<JoinRequestDetailsInner> getWithResponse(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        String joinRequestName,
        Context context) {
        return getWithResponseAsync(
                billingAccountName, billingProfileName, invoiceSectionName, joinRequestName, context)
            .block();
    }

    /**
     * get student join requests.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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 student join requests.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public JoinRequestDetailsInner get(
        String billingAccountName, String billingProfileName, String invoiceSectionName, String joinRequestName) {
        return getWithResponse(
                billingAccountName, billingProfileName, invoiceSectionName, joinRequestName, Context.NONE)
            .getValue();
    }

    /**
     * Approve student joining the redeemable lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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>> approveWithResponseAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, String joinRequestName) {
        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 (joinRequestName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter joinRequestName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .approve(
                            this.client.getEndpoint(),
                            billingAccountName,
                            billingProfileName,
                            invoiceSectionName,
                            joinRequestName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Approve student joining the redeemable lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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>> approveWithResponseAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        String joinRequestName,
        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 (joinRequestName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter joinRequestName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .approve(
                this.client.getEndpoint(),
                billingAccountName,
                billingProfileName,
                invoiceSectionName,
                joinRequestName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Approve student joining the redeemable lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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> approveAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, String joinRequestName) {
        return approveWithResponseAsync(billingAccountName, billingProfileName, invoiceSectionName, joinRequestName)
            .flatMap(ignored -> Mono.empty());
    }

    /**
     * Approve student joining the redeemable lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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> approveWithResponse(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        String joinRequestName,
        Context context) {
        return approveWithResponseAsync(
                billingAccountName, billingProfileName, invoiceSectionName, joinRequestName, context)
            .block();
    }

    /**
     * Approve student joining the redeemable lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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 approve(
        String billingAccountName, String billingProfileName, String invoiceSectionName, String joinRequestName) {
        approveWithResponse(billingAccountName, billingProfileName, invoiceSectionName, joinRequestName, Context.NONE);
    }

    /**
     * Deny student joining the redeemable lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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>> denyWithResponseAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, String joinRequestName) {
        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 (joinRequestName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter joinRequestName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .deny(
                            this.client.getEndpoint(),
                            billingAccountName,
                            billingProfileName,
                            invoiceSectionName,
                            joinRequestName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deny student joining the redeemable lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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>> denyWithResponseAsync(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        String joinRequestName,
        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 (joinRequestName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter joinRequestName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .deny(
                this.client.getEndpoint(),
                billingAccountName,
                billingProfileName,
                invoiceSectionName,
                joinRequestName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Deny student joining the redeemable lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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> denyAsync(
        String billingAccountName, String billingProfileName, String invoiceSectionName, String joinRequestName) {
        return denyWithResponseAsync(billingAccountName, billingProfileName, invoiceSectionName, joinRequestName)
            .flatMap(ignored -> Mono.empty());
    }

    /**
     * Deny student joining the redeemable lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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> denyWithResponse(
        String billingAccountName,
        String billingProfileName,
        String invoiceSectionName,
        String joinRequestName,
        Context context) {
        return denyWithResponseAsync(
                billingAccountName, billingProfileName, invoiceSectionName, joinRequestName, context)
            .block();
    }

    /**
     * Deny student joining the redeemable lab.
     *
     * @param billingAccountName Billing account name.
     * @param billingProfileName Billing profile name.
     * @param invoiceSectionName Invoice section name.
     * @param joinRequestName Join 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 deny(
        String billingAccountName, String billingProfileName, String invoiceSectionName, String joinRequestName) {
        denyWithResponse(billingAccountName, billingProfileName, invoiceSectionName, joinRequestName, Context.NONE);
    }

    /**
     * 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 join requests along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<JoinRequestDetailsInner>> 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<JoinRequestDetailsInner>>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 join requests along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<JoinRequestDetailsInner>> 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));
    }
}
