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

package com.azure.resourcemanager.labservices.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.Patch;
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.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.labservices.fluent.LabPlansClient;
import com.azure.resourcemanager.labservices.fluent.models.LabPlanInner;
import com.azure.resourcemanager.labservices.models.LabPlanUpdate;
import com.azure.resourcemanager.labservices.models.PagedLabPlans;
import com.azure.resourcemanager.labservices.models.SaveImageBody;
import java.nio.ByteBuffer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for LabServicesClientLabPlans to be used by the proxy service to perform
     * REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "LabServicesClientLab")
    private interface LabPlansService {
        @Headers({"Content-Type: application/json"})
        @Get("/subscriptions/{subscriptionId}/providers/Microsoft.LabServices/labPlans")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PagedLabPlans>> list(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("$filter") String filter,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.LabServices"
                + "/labPlans")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PagedLabPlans>> listByResourceGroup(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.LabServices"
                + "/labPlans/{labPlanName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<LabPlanInner>> getByResourceGroup(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("labPlanName") String labPlanName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.LabServices"
                + "/labPlans/{labPlanName}")
        @ExpectedResponses({200, 201, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("labPlanName") String labPlanName,
            @BodyParam("application/json") LabPlanInner body,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.LabServices"
                + "/labPlans/{labPlanName}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> update(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("labPlanName") String labPlanName,
            @BodyParam("application/json") LabPlanUpdate body,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.LabServices"
                + "/labPlans/{labPlanName}")
        @ExpectedResponses({200, 202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> delete(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("labPlanName") String labPlanName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.LabServices"
                + "/labPlans/{labPlanName}/saveImage")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> saveImage(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("labPlanName") String labPlanName,
            @BodyParam("application/json") SaveImageBody body,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Get all lab plans for a subscription.
     *
     * <p>Returns a list of all lab plans within a subscription.
     *
     * @param filter The filter to apply to the 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 paged list of lab plans along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabPlanInner>> listSinglePageAsync(String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            filter,
                            accept,
                            context))
            .<PagedResponse<LabPlanInner>>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 all lab plans for a subscription.
     *
     * <p>Returns a list of all lab plans within a subscription.
     *
     * @param filter The filter to apply to the operation.
     * @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 paged list of lab plans along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabPlanInner>> listSinglePageAsync(String filter, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                filter,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get all lab plans for a subscription.
     *
     * <p>Returns a list of all lab plans within a subscription.
     *
     * @param filter The filter to apply to the 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 paged list of lab plans as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<LabPlanInner> listAsync(String filter) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(filter), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Get all lab plans for a subscription.
     *
     * <p>Returns a list of all lab plans within a subscription.
     *
     * @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 paged list of lab plans as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<LabPlanInner> listAsync() {
        final String filter = null;
        return new PagedFlux<>(
            () -> listSinglePageAsync(filter), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Get all lab plans for a subscription.
     *
     * <p>Returns a list of all lab plans within a subscription.
     *
     * @param filter The filter to apply to the operation.
     * @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 paged list of lab plans as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<LabPlanInner> listAsync(String filter, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(filter, context),
            nextLink -> listBySubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * Get all lab plans for a subscription.
     *
     * <p>Returns a list of all lab plans within a subscription.
     *
     * @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 paged list of lab plans as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<LabPlanInner> list() {
        final String filter = null;
        return new PagedIterable<>(listAsync(filter));
    }

    /**
     * Get all lab plans for a subscription.
     *
     * <p>Returns a list of all lab plans within a subscription.
     *
     * @param filter The filter to apply to the operation.
     * @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 paged list of lab plans as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<LabPlanInner> list(String filter, Context context) {
        return new PagedIterable<>(listAsync(filter, context));
    }

    /**
     * Get all lab plans for a subscription and resource group.
     *
     * <p>Returns a list of all lab plans for a subscription and resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 paged list of lab plans along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabPlanInner>> listByResourceGroupSinglePageAsync(String resourceGroupName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            accept,
                            context))
            .<PagedResponse<LabPlanInner>>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 all lab plans for a subscription and resource group.
     *
     * <p>Returns a list of all lab plans for a subscription and resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 paged list of lab plans along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabPlanInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByResourceGroup(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get all lab plans for a subscription and resource group.
     *
     * <p>Returns a list of all lab plans for a subscription and resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 paged list of lab plans as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<LabPlanInner> listByResourceGroupAsync(String resourceGroupName) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Get all lab plans for a subscription and resource group.
     *
     * <p>Returns a list of all lab plans for a subscription and resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 paged list of lab plans as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<LabPlanInner> listByResourceGroupAsync(String resourceGroupName, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, context),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * Get all lab plans for a subscription and resource group.
     *
     * <p>Returns a list of all lab plans for a subscription and resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 paged list of lab plans as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<LabPlanInner> listByResourceGroup(String resourceGroupName) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName));
    }

    /**
     * Get all lab plans for a subscription and resource group.
     *
     * <p>Returns a list of all lab plans for a subscription and resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @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 paged list of lab plans as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<LabPlanInner> listByResourceGroup(String resourceGroupName, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, context));
    }

    /**
     * Retrieves a Lab Plan resource.
     *
     * <p>Retrieves the properties of a Lab Plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @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 Plans act as a permission container for creating labs via labs.azure.com along with {@link Response}
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<LabPlanInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String labPlanName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (labPlanName == null) {
            return Mono.error(new IllegalArgumentException("Parameter labPlanName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            labPlanName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Retrieves a Lab Plan resource.
     *
     * <p>Retrieves the properties of a Lab Plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @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 Plans act as a permission container for creating labs via labs.azure.com along with {@link Response}
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<LabPlanInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String labPlanName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (labPlanName == null) {
            return Mono.error(new IllegalArgumentException("Parameter labPlanName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getByResourceGroup(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                labPlanName,
                accept,
                context);
    }

    /**
     * Retrieves a Lab Plan resource.
     *
     * <p>Retrieves the properties of a Lab Plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @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 Plans act as a permission container for creating labs via labs.azure.com on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<LabPlanInner> getByResourceGroupAsync(String resourceGroupName, String labPlanName) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, labPlanName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Retrieves a Lab Plan resource.
     *
     * <p>Retrieves the properties of a Lab Plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @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 Plans act as a permission container for creating labs via labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public LabPlanInner getByResourceGroup(String resourceGroupName, String labPlanName) {
        return getByResourceGroupAsync(resourceGroupName, labPlanName).block();
    }

    /**
     * Retrieves a Lab Plan resource.
     *
     * <p>Retrieves the properties of a Lab Plan.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @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 Plans act as a permission container for creating labs via labs.azure.com along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<LabPlanInner> getByResourceGroupWithResponse(
        String resourceGroupName, String labPlanName, Context context) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, labPlanName, context).block();
    }

    /**
     * Updates or creates a Lab Plan resource.
     *
     * <p>Operation to create or update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com along with {@link Response}
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String labPlanName, LabPlanInner body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (labPlanName == null) {
            return Mono.error(new IllegalArgumentException("Parameter labPlanName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            labPlanName,
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Updates or creates a Lab Plan resource.
     *
     * <p>Operation to create or update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com along with {@link Response}
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String labPlanName, LabPlanInner body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (labPlanName == null) {
            return Mono.error(new IllegalArgumentException("Parameter labPlanName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                labPlanName,
                body,
                accept,
                context);
    }

    /**
     * Updates or creates a Lab Plan resource.
     *
     * <p>Operation to create or update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of lab Plans act as a permission container for creating labs via
     *     labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<LabPlanInner>, LabPlanInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String labPlanName, LabPlanInner body) {
        Mono<Response<Flux<ByteBuffer>>> mono = createOrUpdateWithResponseAsync(resourceGroupName, labPlanName, body);
        return this
            .client
            .<LabPlanInner, LabPlanInner>getLroResult(
                mono, this.client.getHttpPipeline(), LabPlanInner.class, LabPlanInner.class, this.client.getContext());
    }

    /**
     * Updates or creates a Lab Plan resource.
     *
     * <p>Operation to create or update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of lab Plans act as a permission container for creating labs via
     *     labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<LabPlanInner>, LabPlanInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String labPlanName, LabPlanInner body, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, labPlanName, body, context);
        return this
            .client
            .<LabPlanInner, LabPlanInner>getLroResult(
                mono, this.client.getHttpPipeline(), LabPlanInner.class, LabPlanInner.class, context);
    }

    /**
     * Updates or creates a Lab Plan resource.
     *
     * <p>Operation to create or update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of lab Plans act as a permission container for creating labs via
     *     labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<LabPlanInner>, LabPlanInner> beginCreateOrUpdate(
        String resourceGroupName, String labPlanName, LabPlanInner body) {
        return beginCreateOrUpdateAsync(resourceGroupName, labPlanName, body).getSyncPoller();
    }

    /**
     * Updates or creates a Lab Plan resource.
     *
     * <p>Operation to create or update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of lab Plans act as a permission container for creating labs via
     *     labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<LabPlanInner>, LabPlanInner> beginCreateOrUpdate(
        String resourceGroupName, String labPlanName, LabPlanInner body, Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, labPlanName, body, context).getSyncPoller();
    }

    /**
     * Updates or creates a Lab Plan resource.
     *
     * <p>Operation to create or update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<LabPlanInner> createOrUpdateAsync(String resourceGroupName, String labPlanName, LabPlanInner body) {
        return beginCreateOrUpdateAsync(resourceGroupName, labPlanName, body)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates or creates a Lab Plan resource.
     *
     * <p>Operation to create or update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<LabPlanInner> createOrUpdateAsync(
        String resourceGroupName, String labPlanName, LabPlanInner body, Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, labPlanName, body, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates or creates a Lab Plan resource.
     *
     * <p>Operation to create or update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public LabPlanInner createOrUpdate(String resourceGroupName, String labPlanName, LabPlanInner body) {
        return createOrUpdateAsync(resourceGroupName, labPlanName, body).block();
    }

    /**
     * Updates or creates a Lab Plan resource.
     *
     * <p>Operation to create or update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public LabPlanInner createOrUpdate(
        String resourceGroupName, String labPlanName, LabPlanInner body, Context context) {
        return createOrUpdateAsync(resourceGroupName, labPlanName, body, context).block();
    }

    /**
     * Updates a Lab Plan resource.
     *
     * <p>Operation to update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com along with {@link Response}
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName, String labPlanName, LabPlanUpdate body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (labPlanName == null) {
            return Mono.error(new IllegalArgumentException("Parameter labPlanName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            labPlanName,
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Updates a Lab Plan resource.
     *
     * <p>Operation to update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com along with {@link Response}
     *     on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName, String labPlanName, LabPlanUpdate body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (labPlanName == null) {
            return Mono.error(new IllegalArgumentException("Parameter labPlanName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                labPlanName,
                body,
                accept,
                context);
    }

    /**
     * Updates a Lab Plan resource.
     *
     * <p>Operation to update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of lab Plans act as a permission container for creating labs via
     *     labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<LabPlanInner>, LabPlanInner> beginUpdateAsync(
        String resourceGroupName, String labPlanName, LabPlanUpdate body) {
        Mono<Response<Flux<ByteBuffer>>> mono = updateWithResponseAsync(resourceGroupName, labPlanName, body);
        return this
            .client
            .<LabPlanInner, LabPlanInner>getLroResult(
                mono, this.client.getHttpPipeline(), LabPlanInner.class, LabPlanInner.class, this.client.getContext());
    }

    /**
     * Updates a Lab Plan resource.
     *
     * <p>Operation to update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of lab Plans act as a permission container for creating labs via
     *     labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<LabPlanInner>, LabPlanInner> beginUpdateAsync(
        String resourceGroupName, String labPlanName, LabPlanUpdate body, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = updateWithResponseAsync(resourceGroupName, labPlanName, body, context);
        return this
            .client
            .<LabPlanInner, LabPlanInner>getLroResult(
                mono, this.client.getHttpPipeline(), LabPlanInner.class, LabPlanInner.class, context);
    }

    /**
     * Updates a Lab Plan resource.
     *
     * <p>Operation to update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of lab Plans act as a permission container for creating labs via
     *     labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<LabPlanInner>, LabPlanInner> beginUpdate(
        String resourceGroupName, String labPlanName, LabPlanUpdate body) {
        return beginUpdateAsync(resourceGroupName, labPlanName, body).getSyncPoller();
    }

    /**
     * Updates a Lab Plan resource.
     *
     * <p>Operation to update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of lab Plans act as a permission container for creating labs via
     *     labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<LabPlanInner>, LabPlanInner> beginUpdate(
        String resourceGroupName, String labPlanName, LabPlanUpdate body, Context context) {
        return beginUpdateAsync(resourceGroupName, labPlanName, body, context).getSyncPoller();
    }

    /**
     * Updates a Lab Plan resource.
     *
     * <p>Operation to update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<LabPlanInner> updateAsync(String resourceGroupName, String labPlanName, LabPlanUpdate body) {
        return beginUpdateAsync(resourceGroupName, labPlanName, body)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates a Lab Plan resource.
     *
     * <p>Operation to update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<LabPlanInner> updateAsync(
        String resourceGroupName, String labPlanName, LabPlanUpdate body, Context context) {
        return beginUpdateAsync(resourceGroupName, labPlanName, body, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates a Lab Plan resource.
     *
     * <p>Operation to update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public LabPlanInner update(String resourceGroupName, String labPlanName, LabPlanUpdate body) {
        return updateAsync(resourceGroupName, labPlanName, body).block();
    }

    /**
     * Updates a Lab Plan resource.
     *
     * <p>Operation to update a Lab Plan resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 Plans act as a permission container for creating labs via labs.azure.com.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public LabPlanInner update(String resourceGroupName, String labPlanName, LabPlanUpdate body, Context context) {
        return updateAsync(resourceGroupName, labPlanName, body, context).block();
    }

    /**
     * Deletes a Lab Plan resource.
     *
     * <p>Operation to delete a Lab Plan resource. Deleting a lab plan does not delete labs associated with a lab plan,
     * nor does it delete shared images added to a gallery via the lab plan permission container.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @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<Flux<ByteBuffer>>> deleteWithResponseAsync(String resourceGroupName, String labPlanName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (labPlanName == null) {
            return Mono.error(new IllegalArgumentException("Parameter labPlanName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            labPlanName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes a Lab Plan resource.
     *
     * <p>Operation to delete a Lab Plan resource. Deleting a lab plan does not delete labs associated with a lab plan,
     * nor does it delete shared images added to a gallery via the lab plan permission container.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @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<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String labPlanName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (labPlanName == null) {
            return Mono.error(new IllegalArgumentException("Parameter labPlanName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                labPlanName,
                accept,
                context);
    }

    /**
     * Deletes a Lab Plan resource.
     *
     * <p>Operation to delete a Lab Plan resource. Deleting a lab plan does not delete labs associated with a lab plan,
     * nor does it delete shared images added to a gallery via the lab plan permission container.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(String resourceGroupName, String labPlanName) {
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(resourceGroupName, labPlanName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Deletes a Lab Plan resource.
     *
     * <p>Operation to delete a Lab Plan resource. Deleting a lab plan does not delete labs associated with a lab plan,
     * nor does it delete shared images added to a gallery via the lab plan permission container.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String labPlanName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(resourceGroupName, labPlanName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Deletes a Lab Plan resource.
     *
     * <p>Operation to delete a Lab Plan resource. Deleting a lab plan does not delete labs associated with a lab plan,
     * nor does it delete shared images added to a gallery via the lab plan permission container.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(String resourceGroupName, String labPlanName) {
        return beginDeleteAsync(resourceGroupName, labPlanName).getSyncPoller();
    }

    /**
     * Deletes a Lab Plan resource.
     *
     * <p>Operation to delete a Lab Plan resource. Deleting a lab plan does not delete labs associated with a lab plan,
     * nor does it delete shared images added to a gallery via the lab plan permission container.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String labPlanName, Context context) {
        return beginDeleteAsync(resourceGroupName, labPlanName, context).getSyncPoller();
    }

    /**
     * Deletes a Lab Plan resource.
     *
     * <p>Operation to delete a Lab Plan resource. Deleting a lab plan does not delete labs associated with a lab plan,
     * nor does it delete shared images added to a gallery via the lab plan permission container.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @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 resourceGroupName, String labPlanName) {
        return beginDeleteAsync(resourceGroupName, labPlanName).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a Lab Plan resource.
     *
     * <p>Operation to delete a Lab Plan resource. Deleting a lab plan does not delete labs associated with a lab plan,
     * nor does it delete shared images added to a gallery via the lab plan permission container.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @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 {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String labPlanName, Context context) {
        return beginDeleteAsync(resourceGroupName, labPlanName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a Lab Plan resource.
     *
     * <p>Operation to delete a Lab Plan resource. Deleting a lab plan does not delete labs associated with a lab plan,
     * nor does it delete shared images added to a gallery via the lab plan permission container.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @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 resourceGroupName, String labPlanName) {
        deleteAsync(resourceGroupName, labPlanName).block();
    }

    /**
     * Deletes a Lab Plan resource.
     *
     * <p>Operation to delete a Lab Plan resource. Deleting a lab plan does not delete labs associated with a lab plan,
     * nor does it delete shared images added to a gallery via the lab plan permission container.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String labPlanName, Context context) {
        deleteAsync(resourceGroupName, labPlanName, context).block();
    }

    /**
     * Save an image from a lab VM to the attached shared image gallery.
     *
     * <p>Saves an image from a lab VM to the attached shared image gallery.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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<Flux<ByteBuffer>>> saveImageWithResponseAsync(
        String resourceGroupName, String labPlanName, SaveImageBody body) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (labPlanName == null) {
            return Mono.error(new IllegalArgumentException("Parameter labPlanName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .saveImage(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            labPlanName,
                            body,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Save an image from a lab VM to the attached shared image gallery.
     *
     * <p>Saves an image from a lab VM to the attached shared image gallery.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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<Flux<ByteBuffer>>> saveImageWithResponseAsync(
        String resourceGroupName, String labPlanName, SaveImageBody body, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (labPlanName == null) {
            return Mono.error(new IllegalArgumentException("Parameter labPlanName is required and cannot be null."));
        }
        if (body == null) {
            return Mono.error(new IllegalArgumentException("Parameter body is required and cannot be null."));
        } else {
            body.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .saveImage(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                labPlanName,
                body,
                accept,
                context);
    }

    /**
     * Save an image from a lab VM to the attached shared image gallery.
     *
     * <p>Saves an image from a lab VM to the attached shared image gallery.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginSaveImageAsync(
        String resourceGroupName, String labPlanName, SaveImageBody body) {
        Mono<Response<Flux<ByteBuffer>>> mono = saveImageWithResponseAsync(resourceGroupName, labPlanName, body);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Save an image from a lab VM to the attached shared image gallery.
     *
     * <p>Saves an image from a lab VM to the attached shared image gallery.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginSaveImageAsync(
        String resourceGroupName, String labPlanName, SaveImageBody body, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            saveImageWithResponseAsync(resourceGroupName, labPlanName, body, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Save an image from a lab VM to the attached shared image gallery.
     *
     * <p>Saves an image from a lab VM to the attached shared image gallery.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginSaveImage(
        String resourceGroupName, String labPlanName, SaveImageBody body) {
        return beginSaveImageAsync(resourceGroupName, labPlanName, body).getSyncPoller();
    }

    /**
     * Save an image from a lab VM to the attached shared image gallery.
     *
     * <p>Saves an image from a lab VM to the attached shared image gallery.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginSaveImage(
        String resourceGroupName, String labPlanName, SaveImageBody body, Context context) {
        return beginSaveImageAsync(resourceGroupName, labPlanName, body, context).getSyncPoller();
    }

    /**
     * Save an image from a lab VM to the attached shared image gallery.
     *
     * <p>Saves an image from a lab VM to the attached shared image gallery.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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> saveImageAsync(String resourceGroupName, String labPlanName, SaveImageBody body) {
        return beginSaveImageAsync(resourceGroupName, labPlanName, body)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Save an image from a lab VM to the attached shared image gallery.
     *
     * <p>Saves an image from a lab VM to the attached shared image gallery.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> saveImageAsync(
        String resourceGroupName, String labPlanName, SaveImageBody body, Context context) {
        return beginSaveImageAsync(resourceGroupName, labPlanName, body, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Save an image from a lab VM to the attached shared image gallery.
     *
     * <p>Saves an image from a lab VM to the attached shared image gallery.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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 saveImage(String resourceGroupName, String labPlanName, SaveImageBody body) {
        saveImageAsync(resourceGroupName, labPlanName, body).block();
    }

    /**
     * Save an image from a lab VM to the attached shared image gallery.
     *
     * <p>Saves an image from a lab VM to the attached shared image gallery.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param labPlanName The name of the lab plan that uniquely identifies it within containing resource group. Used in
     *     resource URIs and in UI.
     * @param body The request body.
     * @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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void saveImage(String resourceGroupName, String labPlanName, SaveImageBody body, Context context) {
        saveImageAsync(resourceGroupName, labPlanName, body, context).block();
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return paged list of lab plans along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabPlanInner>> listBySubscriptionNextSinglePageAsync(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.listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<LabPlanInner>>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 paged list of lab plans along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabPlanInner>> listBySubscriptionNextSinglePageAsync(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
            .listBySubscriptionNext(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 paged list of lab plans along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabPlanInner>> listByResourceGroupNextSinglePageAsync(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.listByResourceGroupNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<LabPlanInner>>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 paged list of lab plans along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<LabPlanInner>> listByResourceGroupNextSinglePageAsync(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
            .listByResourceGroupNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
