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

package com.azure.resourcemanager.networkcloud.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.networkcloud.fluent.BareMetalMachinesClient;
import com.azure.resourcemanager.networkcloud.fluent.models.BareMetalMachineInner;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineCordonParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineList;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachinePatchParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachinePowerOffParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineReplaceParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineRunCommandParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineRunDataExtractsParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineRunReadCommandsParameters;
import com.azure.resourcemanager.networkcloud.models.BareMetalMachineValidateHardwareParameters;
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 BareMetalMachinesClient. */
public final class BareMetalMachinesClientImpl implements BareMetalMachinesClient {
    /** The proxy service used to perform REST calls. */
    private final BareMetalMachinesService service;

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

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

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

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/bareMetalMachines")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<BareMetalMachineList>> 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.NetworkCloud/bareMetalMachines/{bareMetalMachineName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<BareMetalMachineInner>> getByResourceGroup(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("bareMetalMachineName") String bareMetalMachineName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/bareMetalMachines/{bareMetalMachineName}")
        @ExpectedResponses({200, 201})
        @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("bareMetalMachineName") String bareMetalMachineName,
            @BodyParam("application/json") BareMetalMachineInner bareMetalMachineParameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/bareMetalMachines/{bareMetalMachineName}")
        @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("bareMetalMachineName") String bareMetalMachineName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/bareMetalMachines/{bareMetalMachineName}")
        @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("bareMetalMachineName") String bareMetalMachineName,
            @BodyParam("application/json") BareMetalMachinePatchParameters bareMetalMachineUpdateParameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/bareMetalMachines/{bareMetalMachineName}/cordon")
        @ExpectedResponses({202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> cordon(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("bareMetalMachineName") String bareMetalMachineName,
            @BodyParam("application/json") BareMetalMachineCordonParameters bareMetalMachineCordonParameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/bareMetalMachines/{bareMetalMachineName}/powerOff")
        @ExpectedResponses({202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> powerOff(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("bareMetalMachineName") String bareMetalMachineName,
            @BodyParam("application/json") BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/bareMetalMachines/{bareMetalMachineName}/replace")
        @ExpectedResponses({202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> replace(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("bareMetalMachineName") String bareMetalMachineName,
            @BodyParam("application/json") BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/bareMetalMachines/{bareMetalMachineName}/runCommand")
        @ExpectedResponses({202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> runCommand(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("bareMetalMachineName") String bareMetalMachineName,
            @BodyParam("application/json") BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/bareMetalMachines/{bareMetalMachineName}/runDataExtracts")
        @ExpectedResponses({202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> runDataExtracts(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("bareMetalMachineName") String bareMetalMachineName,
            @BodyParam("application/json")
                BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/bareMetalMachines/{bareMetalMachineName}/runReadCommands")
        @ExpectedResponses({202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> runReadCommands(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("bareMetalMachineName") String bareMetalMachineName,
            @BodyParam("application/json")
                BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.NetworkCloud/bareMetalMachines/{bareMetalMachineName}/validateHardware")
        @ExpectedResponses({202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> validateHardware(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("bareMetalMachineName") String bareMetalMachineName,
            @BodyParam("application/json")
                BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * List bare metal machines in the subscription.
     *
     * <p>Get a list of bare metal machines in the provided 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 a list of bare metal machines in the provided subscription along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BareMetalMachineInner>> listSinglePageAsync() {
        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(),
                            accept,
                            context))
            .<PagedResponse<BareMetalMachineInner>>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()));
    }

    /**
     * List bare metal machines in the subscription.
     *
     * <p>Get a list of bare metal machines in the provided subscription.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of bare metal machines in the provided subscription along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BareMetalMachineInner>> listSinglePageAsync(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(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List bare metal machines in the subscription.
     *
     * <p>Get a list of bare metal machines in the provided 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 a list of bare metal machines in the provided subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<BareMetalMachineInner> listAsync() {
        return new PagedFlux<>(
            () -> listSinglePageAsync(), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * List bare metal machines in the subscription.
     *
     * <p>Get a list of bare metal machines in the provided subscription.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of bare metal machines in the provided subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<BareMetalMachineInner> listAsync(Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(context), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * List bare metal machines in the subscription.
     *
     * <p>Get a list of bare metal machines in the provided 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 a list of bare metal machines in the provided subscription as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<BareMetalMachineInner> list() {
        return new PagedIterable<>(listAsync());
    }

    /**
     * List bare metal machines in the subscription.
     *
     * <p>Get a list of bare metal machines in the provided subscription.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of bare metal machines in the provided subscription as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<BareMetalMachineInner> list(Context context) {
        return new PagedIterable<>(listAsync(context));
    }

    /**
     * List bare metal machines in the resource group.
     *
     * <p>Get a list of bare metal machines in the provided 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 a list of bare metal machines in the provided resource group along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BareMetalMachineInner>> 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<BareMetalMachineInner>>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()));
    }

    /**
     * List bare metal machines in the resource group.
     *
     * <p>Get a list of bare metal machines in the provided 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 a list of bare metal machines in the provided resource group along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BareMetalMachineInner>> 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));
    }

    /**
     * List bare metal machines in the resource group.
     *
     * <p>Get a list of bare metal machines in the provided 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 a list of bare metal machines in the provided resource group as paginated response with {@link
     *     PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<BareMetalMachineInner> listByResourceGroupAsync(String resourceGroupName) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * List bare metal machines in the resource group.
     *
     * <p>Get a list of bare metal machines in the provided 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 a list of bare metal machines in the provided resource group as paginated response with {@link
     *     PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<BareMetalMachineInner> listByResourceGroupAsync(String resourceGroupName, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, context),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * List bare metal machines in the resource group.
     *
     * <p>Get a list of bare metal machines in the provided 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 a list of bare metal machines in the provided resource group as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<BareMetalMachineInner> listByResourceGroup(String resourceGroupName) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName));
    }

    /**
     * List bare metal machines in the resource group.
     *
     * <p>Get a list of bare metal machines in the provided 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 a list of bare metal machines in the provided resource group as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<BareMetalMachineInner> listByResourceGroup(String resourceGroupName, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, context));
    }

    /**
     * Retrieve the bare metal machine.
     *
     * <p>Get properties of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 properties of the provided bare metal machine along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<BareMetalMachineInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String bareMetalMachineName) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName 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,
                            bareMetalMachineName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Retrieve the bare metal machine.
     *
     * <p>Get properties of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 properties of the provided bare metal machine along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<BareMetalMachineInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String bareMetalMachineName, 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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName 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,
                bareMetalMachineName,
                accept,
                context);
    }

    /**
     * Retrieve the bare metal machine.
     *
     * <p>Get properties of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 properties of the provided bare metal machine on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BareMetalMachineInner> getByResourceGroupAsync(String resourceGroupName, String bareMetalMachineName) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, bareMetalMachineName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Retrieve the bare metal machine.
     *
     * <p>Get properties of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 properties of the provided bare metal machine along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<BareMetalMachineInner> getByResourceGroupWithResponse(
        String resourceGroupName, String bareMetalMachineName, Context context) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, bareMetalMachineName, context).block();
    }

    /**
     * Retrieve the bare metal machine.
     *
     * <p>Get properties of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 properties of the provided bare metal machine.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public BareMetalMachineInner getByResourceGroup(String resourceGroupName, String bareMetalMachineName) {
        return getByResourceGroupWithResponse(resourceGroupName, bareMetalMachineName, Context.NONE).getValue();
    }

    /**
     * Create or update the bare metal machine.
     *
     * <p>Create a new bare metal machine or update the properties of the existing one. All customer initiated requests
     * will be rejected as the life cycle of this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineParameters 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 bareMetalMachine represents the physical machine in the rack along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String bareMetalMachineName, BareMetalMachineInner bareMetalMachineParameters) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter bareMetalMachineParameters is required and cannot be null."));
        } else {
            bareMetalMachineParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            bareMetalMachineParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create or update the bare metal machine.
     *
     * <p>Create a new bare metal machine or update the properties of the existing one. All customer initiated requests
     * will be rejected as the life cycle of this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineParameters 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 bareMetalMachine represents the physical machine in the rack along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineInner bareMetalMachineParameters,
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter bareMetalMachineParameters is required and cannot be null."));
        } else {
            bareMetalMachineParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                bareMetalMachineParameters,
                accept,
                context);
    }

    /**
     * Create or update the bare metal machine.
     *
     * <p>Create a new bare metal machine or update the properties of the existing one. All customer initiated requests
     * will be rejected as the life cycle of this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineParameters 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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<BareMetalMachineInner>, BareMetalMachineInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String bareMetalMachineName, BareMetalMachineInner bareMetalMachineParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineParameters);
        return this
            .client
            .<BareMetalMachineInner, BareMetalMachineInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                BareMetalMachineInner.class,
                BareMetalMachineInner.class,
                this.client.getContext());
    }

    /**
     * Create or update the bare metal machine.
     *
     * <p>Create a new bare metal machine or update the properties of the existing one. All customer initiated requests
     * will be rejected as the life cycle of this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineParameters 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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<BareMetalMachineInner>, BareMetalMachineInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineInner bareMetalMachineParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineParameters, context);
        return this
            .client
            .<BareMetalMachineInner, BareMetalMachineInner>getLroResult(
                mono, this.client.getHttpPipeline(), BareMetalMachineInner.class, BareMetalMachineInner.class, context);
    }

    /**
     * Create or update the bare metal machine.
     *
     * <p>Create a new bare metal machine or update the properties of the existing one. All customer initiated requests
     * will be rejected as the life cycle of this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineParameters 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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<BareMetalMachineInner>, BareMetalMachineInner> beginCreateOrUpdate(
        String resourceGroupName, String bareMetalMachineName, BareMetalMachineInner bareMetalMachineParameters) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineParameters)
            .getSyncPoller();
    }

    /**
     * Create or update the bare metal machine.
     *
     * <p>Create a new bare metal machine or update the properties of the existing one. All customer initiated requests
     * will be rejected as the life cycle of this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineParameters 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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<BareMetalMachineInner>, BareMetalMachineInner> beginCreateOrUpdate(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineInner bareMetalMachineParameters,
        Context context) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineParameters, context)
            .getSyncPoller();
    }

    /**
     * Create or update the bare metal machine.
     *
     * <p>Create a new bare metal machine or update the properties of the existing one. All customer initiated requests
     * will be rejected as the life cycle of this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineParameters 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 bareMetalMachine represents the physical machine in the rack on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BareMetalMachineInner> createOrUpdateAsync(
        String resourceGroupName, String bareMetalMachineName, BareMetalMachineInner bareMetalMachineParameters) {
        return beginCreateOrUpdateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update the bare metal machine.
     *
     * <p>Create a new bare metal machine or update the properties of the existing one. All customer initiated requests
     * will be rejected as the life cycle of this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineParameters 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 bareMetalMachine represents the physical machine in the rack on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BareMetalMachineInner> createOrUpdateAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineInner bareMetalMachineParameters,
        Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update the bare metal machine.
     *
     * <p>Create a new bare metal machine or update the properties of the existing one. All customer initiated requests
     * will be rejected as the life cycle of this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineParameters 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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public BareMetalMachineInner createOrUpdate(
        String resourceGroupName, String bareMetalMachineName, BareMetalMachineInner bareMetalMachineParameters) {
        return createOrUpdateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineParameters).block();
    }

    /**
     * Create or update the bare metal machine.
     *
     * <p>Create a new bare metal machine or update the properties of the existing one. All customer initiated requests
     * will be rejected as the life cycle of this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineParameters 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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public BareMetalMachineInner createOrUpdate(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineInner bareMetalMachineParameters,
        Context context) {
        return createOrUpdateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineParameters, context)
            .block();
    }

    /**
     * Delete the bare metal machine.
     *
     * <p>Delete the provided bare metal machine. All customer initiated requests will be rejected as the life cycle of
     * this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachineName) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName 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,
                            bareMetalMachineName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete the bare metal machine.
     *
     * <p>Delete the provided bare metal machine. All customer initiated requests will be rejected as the life cycle of
     * this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachineName, 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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName 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,
                bareMetalMachineName,
                accept,
                context);
    }

    /**
     * Delete the bare metal machine.
     *
     * <p>Delete the provided bare metal machine. All customer initiated requests will be rejected as the life cycle of
     * this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachineName) {
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(resourceGroupName, bareMetalMachineName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Delete the bare metal machine.
     *
     * <p>Delete the provided bare metal machine. All customer initiated requests will be rejected as the life cycle of
     * this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachineName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, bareMetalMachineName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Delete the bare metal machine.
     *
     * <p>Delete the provided bare metal machine. All customer initiated requests will be rejected as the life cycle of
     * this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachineName) {
        return this.beginDeleteAsync(resourceGroupName, bareMetalMachineName).getSyncPoller();
    }

    /**
     * Delete the bare metal machine.
     *
     * <p>Delete the provided bare metal machine. All customer initiated requests will be rejected as the life cycle of
     * this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachineName, Context context) {
        return this.beginDeleteAsync(resourceGroupName, bareMetalMachineName, context).getSyncPoller();
    }

    /**
     * Delete the bare metal machine.
     *
     * <p>Delete the provided bare metal machine. All customer initiated requests will be rejected as the life cycle of
     * this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachineName) {
        return beginDeleteAsync(resourceGroupName, bareMetalMachineName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete the bare metal machine.
     *
     * <p>Delete the provided bare metal machine. All customer initiated requests will be rejected as the life cycle of
     * this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachineName, Context context) {
        return beginDeleteAsync(resourceGroupName, bareMetalMachineName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete the bare metal machine.
     *
     * <p>Delete the provided bare metal machine. All customer initiated requests will be rejected as the life cycle of
     * this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachineName) {
        deleteAsync(resourceGroupName, bareMetalMachineName).block();
    }

    /**
     * Delete the bare metal machine.
     *
     * <p>Delete the provided bare metal machine. All customer initiated requests will be rejected as the life cycle of
     * this resource is managed by the system.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachineName, Context context) {
        deleteAsync(resourceGroupName, bareMetalMachineName, context).block();
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineUpdateParameters 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 bareMetalMachine represents the physical machine in the rack along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePatchParameters bareMetalMachineUpdateParameters) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineUpdateParameters != null) {
            bareMetalMachineUpdateParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            bareMetalMachineUpdateParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineUpdateParameters 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 bareMetalMachine represents the physical machine in the rack along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePatchParameters bareMetalMachineUpdateParameters,
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineUpdateParameters != null) {
            bareMetalMachineUpdateParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                bareMetalMachineUpdateParameters,
                accept,
                context);
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineUpdateParameters 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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<BareMetalMachineInner>, BareMetalMachineInner> beginUpdateAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePatchParameters bareMetalMachineUpdateParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineUpdateParameters);
        return this
            .client
            .<BareMetalMachineInner, BareMetalMachineInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                BareMetalMachineInner.class,
                BareMetalMachineInner.class,
                this.client.getContext());
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<BareMetalMachineInner>, BareMetalMachineInner> beginUpdateAsync(
        String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachinePatchParameters bareMetalMachineUpdateParameters = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineUpdateParameters);
        return this
            .client
            .<BareMetalMachineInner, BareMetalMachineInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                BareMetalMachineInner.class,
                BareMetalMachineInner.class,
                this.client.getContext());
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineUpdateParameters 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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<BareMetalMachineInner>, BareMetalMachineInner> beginUpdateAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePatchParameters bareMetalMachineUpdateParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineUpdateParameters, context);
        return this
            .client
            .<BareMetalMachineInner, BareMetalMachineInner>getLroResult(
                mono, this.client.getHttpPipeline(), BareMetalMachineInner.class, BareMetalMachineInner.class, context);
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<BareMetalMachineInner>, BareMetalMachineInner> beginUpdate(
        String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachinePatchParameters bareMetalMachineUpdateParameters = null;
        return this
            .beginUpdateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineUpdateParameters)
            .getSyncPoller();
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineUpdateParameters 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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<BareMetalMachineInner>, BareMetalMachineInner> beginUpdate(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePatchParameters bareMetalMachineUpdateParameters,
        Context context) {
        return this
            .beginUpdateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineUpdateParameters, context)
            .getSyncPoller();
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineUpdateParameters 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 bareMetalMachine represents the physical machine in the rack on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BareMetalMachineInner> updateAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePatchParameters bareMetalMachineUpdateParameters) {
        return beginUpdateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineUpdateParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachine represents the physical machine in the rack on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BareMetalMachineInner> updateAsync(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachinePatchParameters bareMetalMachineUpdateParameters = null;
        return beginUpdateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineUpdateParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineUpdateParameters 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 bareMetalMachine represents the physical machine in the rack on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<BareMetalMachineInner> updateAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePatchParameters bareMetalMachineUpdateParameters,
        Context context) {
        return beginUpdateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineUpdateParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public BareMetalMachineInner update(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachinePatchParameters bareMetalMachineUpdateParameters = null;
        return updateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineUpdateParameters).block();
    }

    /**
     * Patch the bare metal machine.
     *
     * <p>Patch properties of the provided bare metal machine, or update tags associated with the bare metal machine.
     * Properties and tag updates can be done independently.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineUpdateParameters 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 bareMetalMachine represents the physical machine in the rack.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public BareMetalMachineInner update(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePatchParameters bareMetalMachineUpdateParameters,
        Context context) {
        return updateAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineUpdateParameters, context).block();
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineCordonParameters 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>>> cordonWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineCordonParameters bareMetalMachineCordonParameters) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineCordonParameters != null) {
            bareMetalMachineCordonParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .cordon(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            bareMetalMachineCordonParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineCordonParameters 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>>> cordonWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineCordonParameters bareMetalMachineCordonParameters,
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineCordonParameters != null) {
            bareMetalMachineCordonParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .cordon(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                bareMetalMachineCordonParameters,
                accept,
                context);
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineCordonParameters 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> beginCordonAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineCordonParameters bareMetalMachineCordonParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            cordonWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineCordonParameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginCordonAsync(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachineCordonParameters bareMetalMachineCordonParameters = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            cordonWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineCordonParameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineCordonParameters 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> beginCordonAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineCordonParameters bareMetalMachineCordonParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            cordonWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineCordonParameters, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginCordon(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachineCordonParameters bareMetalMachineCordonParameters = null;
        return this
            .beginCordonAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineCordonParameters)
            .getSyncPoller();
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineCordonParameters 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> beginCordon(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineCordonParameters bareMetalMachineCordonParameters,
        Context context) {
        return this
            .beginCordonAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineCordonParameters, context)
            .getSyncPoller();
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineCordonParameters 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> cordonAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineCordonParameters bareMetalMachineCordonParameters) {
        return beginCordonAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineCordonParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> cordonAsync(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachineCordonParameters bareMetalMachineCordonParameters = null;
        return beginCordonAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineCordonParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineCordonParameters 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> cordonAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineCordonParameters bareMetalMachineCordonParameters,
        Context context) {
        return beginCordonAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineCordonParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 cordon(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachineCordonParameters bareMetalMachineCordonParameters = null;
        cordonAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineCordonParameters).block();
    }

    /**
     * Cordon the bare metal machine.
     *
     * <p>Cordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineCordonParameters 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 cordon(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineCordonParameters bareMetalMachineCordonParameters,
        Context context) {
        cordonAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineCordonParameters, context).block();
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachinePowerOffParameters 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>>> powerOffWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachinePowerOffParameters != null) {
            bareMetalMachinePowerOffParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .powerOff(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            bareMetalMachinePowerOffParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachinePowerOffParameters 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>>> powerOffWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters,
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachinePowerOffParameters != null) {
            bareMetalMachinePowerOffParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .powerOff(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                bareMetalMachinePowerOffParameters,
                accept,
                context);
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachinePowerOffParameters 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> beginPowerOffAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            powerOffWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachinePowerOffParameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginPowerOffAsync(
        String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            powerOffWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachinePowerOffParameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachinePowerOffParameters 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> beginPowerOffAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            powerOffWithResponseAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachinePowerOffParameters, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginPowerOff(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters = null;
        return this
            .beginPowerOffAsync(resourceGroupName, bareMetalMachineName, bareMetalMachinePowerOffParameters)
            .getSyncPoller();
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachinePowerOffParameters 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> beginPowerOff(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters,
        Context context) {
        return this
            .beginPowerOffAsync(resourceGroupName, bareMetalMachineName, bareMetalMachinePowerOffParameters, context)
            .getSyncPoller();
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachinePowerOffParameters 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> powerOffAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters) {
        return beginPowerOffAsync(resourceGroupName, bareMetalMachineName, bareMetalMachinePowerOffParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> powerOffAsync(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters = null;
        return beginPowerOffAsync(resourceGroupName, bareMetalMachineName, bareMetalMachinePowerOffParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachinePowerOffParameters 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> powerOffAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters,
        Context context) {
        return beginPowerOffAsync(resourceGroupName, bareMetalMachineName, bareMetalMachinePowerOffParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 powerOff(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters = null;
        powerOffAsync(resourceGroupName, bareMetalMachineName, bareMetalMachinePowerOffParameters).block();
    }

    /**
     * Power off the bare metal machine.
     *
     * <p>Power off the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachinePowerOffParameters 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 powerOff(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachinePowerOffParameters bareMetalMachinePowerOffParameters,
        Context context) {
        powerOffAsync(resourceGroupName, bareMetalMachineName, bareMetalMachinePowerOffParameters, context).block();
    }

    /**
     * Reimage the bare metal machine.
     *
     * <p>Reimage the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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>>> reimageWithResponseAsync(
        String resourceGroupName, String bareMetalMachineName) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .reimage(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Reimage the bare metal machine.
     *
     * <p>Reimage the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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>>> reimageWithResponseAsync(
        String resourceGroupName, String bareMetalMachineName, 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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .reimage(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                accept,
                context);
    }

    /**
     * Reimage the bare metal machine.
     *
     * <p>Reimage the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginReimageAsync(
        String resourceGroupName, String bareMetalMachineName) {
        Mono<Response<Flux<ByteBuffer>>> mono = reimageWithResponseAsync(resourceGroupName, bareMetalMachineName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Reimage the bare metal machine.
     *
     * <p>Reimage the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginReimageAsync(
        String resourceGroupName, String bareMetalMachineName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            reimageWithResponseAsync(resourceGroupName, bareMetalMachineName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Reimage the bare metal machine.
     *
     * <p>Reimage the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginReimage(String resourceGroupName, String bareMetalMachineName) {
        return this.beginReimageAsync(resourceGroupName, bareMetalMachineName).getSyncPoller();
    }

    /**
     * Reimage the bare metal machine.
     *
     * <p>Reimage the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginReimage(
        String resourceGroupName, String bareMetalMachineName, Context context) {
        return this.beginReimageAsync(resourceGroupName, bareMetalMachineName, context).getSyncPoller();
    }

    /**
     * Reimage the bare metal machine.
     *
     * <p>Reimage the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> reimageAsync(String resourceGroupName, String bareMetalMachineName) {
        return beginReimageAsync(resourceGroupName, bareMetalMachineName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Reimage the bare metal machine.
     *
     * <p>Reimage the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> reimageAsync(String resourceGroupName, String bareMetalMachineName, Context context) {
        return beginReimageAsync(resourceGroupName, bareMetalMachineName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Reimage the bare metal machine.
     *
     * <p>Reimage the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 reimage(String resourceGroupName, String bareMetalMachineName) {
        reimageAsync(resourceGroupName, bareMetalMachineName).block();
    }

    /**
     * Reimage the bare metal machine.
     *
     * <p>Reimage the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 reimage(String resourceGroupName, String bareMetalMachineName, Context context) {
        reimageAsync(resourceGroupName, bareMetalMachineName, context).block();
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineReplaceParameters 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>>> replaceWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineReplaceParameters != null) {
            bareMetalMachineReplaceParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .replace(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            bareMetalMachineReplaceParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineReplaceParameters 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>>> replaceWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters,
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineReplaceParameters != null) {
            bareMetalMachineReplaceParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .replace(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                bareMetalMachineReplaceParameters,
                accept,
                context);
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineReplaceParameters 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> beginReplaceAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            replaceWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineReplaceParameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginReplaceAsync(
        String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters = null;
        Mono<Response<Flux<ByteBuffer>>> mono =
            replaceWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineReplaceParameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineReplaceParameters 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> beginReplaceAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            replaceWithResponseAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineReplaceParameters, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginReplace(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters = null;
        return this
            .beginReplaceAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineReplaceParameters)
            .getSyncPoller();
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineReplaceParameters 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> beginReplace(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters,
        Context context) {
        return this
            .beginReplaceAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineReplaceParameters, context)
            .getSyncPoller();
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineReplaceParameters 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> replaceAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters) {
        return beginReplaceAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineReplaceParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> replaceAsync(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters = null;
        return beginReplaceAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineReplaceParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineReplaceParameters 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> replaceAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters,
        Context context) {
        return beginReplaceAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineReplaceParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 replace(String resourceGroupName, String bareMetalMachineName) {
        final BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters = null;
        replaceAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineReplaceParameters).block();
    }

    /**
     * Replace (service) the bare metal machine.
     *
     * <p>Replace the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineReplaceParameters 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 replace(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineReplaceParameters bareMetalMachineReplaceParameters,
        Context context) {
        replaceAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineReplaceParameters, context).block();
    }

    /**
     * Restart the bare metal machine.
     *
     * <p>Restart the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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>>> restartWithResponseAsync(
        String resourceGroupName, String bareMetalMachineName) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .restart(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Restart the bare metal machine.
     *
     * <p>Restart the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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>>> restartWithResponseAsync(
        String resourceGroupName, String bareMetalMachineName, 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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .restart(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                accept,
                context);
    }

    /**
     * Restart the bare metal machine.
     *
     * <p>Restart the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginRestartAsync(
        String resourceGroupName, String bareMetalMachineName) {
        Mono<Response<Flux<ByteBuffer>>> mono = restartWithResponseAsync(resourceGroupName, bareMetalMachineName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Restart the bare metal machine.
     *
     * <p>Restart the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginRestartAsync(
        String resourceGroupName, String bareMetalMachineName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            restartWithResponseAsync(resourceGroupName, bareMetalMachineName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Restart the bare metal machine.
     *
     * <p>Restart the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginRestart(String resourceGroupName, String bareMetalMachineName) {
        return this.beginRestartAsync(resourceGroupName, bareMetalMachineName).getSyncPoller();
    }

    /**
     * Restart the bare metal machine.
     *
     * <p>Restart the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginRestart(
        String resourceGroupName, String bareMetalMachineName, Context context) {
        return this.beginRestartAsync(resourceGroupName, bareMetalMachineName, context).getSyncPoller();
    }

    /**
     * Restart the bare metal machine.
     *
     * <p>Restart the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> restartAsync(String resourceGroupName, String bareMetalMachineName) {
        return beginRestartAsync(resourceGroupName, bareMetalMachineName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Restart the bare metal machine.
     *
     * <p>Restart the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> restartAsync(String resourceGroupName, String bareMetalMachineName, Context context) {
        return beginRestartAsync(resourceGroupName, bareMetalMachineName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Restart the bare metal machine.
     *
     * <p>Restart the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 restart(String resourceGroupName, String bareMetalMachineName) {
        restartAsync(resourceGroupName, bareMetalMachineName).block();
    }

    /**
     * Restart the bare metal machine.
     *
     * <p>Restart the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 restart(String resourceGroupName, String bareMetalMachineName, Context context) {
        restartAsync(resourceGroupName, bareMetalMachineName, context).block();
    }

    /**
     * Run the command on the bare metal machine.
     *
     * <p>Run the command or the script on the provided bare metal machine. The URL to storage account with the command
     * execution results and the command exit code can be retrieved from the operation status API once available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunCommandParameters 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>>> runCommandWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineRunCommandParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter bareMetalMachineRunCommandParameters is required and cannot be null."));
        } else {
            bareMetalMachineRunCommandParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .runCommand(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            bareMetalMachineRunCommandParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Run the command on the bare metal machine.
     *
     * <p>Run the command or the script on the provided bare metal machine. The URL to storage account with the command
     * execution results and the command exit code can be retrieved from the operation status API once available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunCommandParameters 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>>> runCommandWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters,
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineRunCommandParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter bareMetalMachineRunCommandParameters is required and cannot be null."));
        } else {
            bareMetalMachineRunCommandParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .runCommand(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                bareMetalMachineRunCommandParameters,
                accept,
                context);
    }

    /**
     * Run the command on the bare metal machine.
     *
     * <p>Run the command or the script on the provided bare metal machine. The URL to storage account with the command
     * execution results and the command exit code can be retrieved from the operation status API once available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunCommandParameters 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> beginRunCommandAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            runCommandWithResponseAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineRunCommandParameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Run the command on the bare metal machine.
     *
     * <p>Run the command or the script on the provided bare metal machine. The URL to storage account with the command
     * execution results and the command exit code can be retrieved from the operation status API once available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunCommandParameters 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> beginRunCommandAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            runCommandWithResponseAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunCommandParameters, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Run the command on the bare metal machine.
     *
     * <p>Run the command or the script on the provided bare metal machine. The URL to storage account with the command
     * execution results and the command exit code can be retrieved from the operation status API once available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunCommandParameters 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> beginRunCommand(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters) {
        return this
            .beginRunCommandAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineRunCommandParameters)
            .getSyncPoller();
    }

    /**
     * Run the command on the bare metal machine.
     *
     * <p>Run the command or the script on the provided bare metal machine. The URL to storage account with the command
     * execution results and the command exit code can be retrieved from the operation status API once available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunCommandParameters 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> beginRunCommand(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters,
        Context context) {
        return this
            .beginRunCommandAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunCommandParameters, context)
            .getSyncPoller();
    }

    /**
     * Run the command on the bare metal machine.
     *
     * <p>Run the command or the script on the provided bare metal machine. The URL to storage account with the command
     * execution results and the command exit code can be retrieved from the operation status API once available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunCommandParameters 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> runCommandAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters) {
        return beginRunCommandAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineRunCommandParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Run the command on the bare metal machine.
     *
     * <p>Run the command or the script on the provided bare metal machine. The URL to storage account with the command
     * execution results and the command exit code can be retrieved from the operation status API once available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunCommandParameters 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> runCommandAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters,
        Context context) {
        return beginRunCommandAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunCommandParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Run the command on the bare metal machine.
     *
     * <p>Run the command or the script on the provided bare metal machine. The URL to storage account with the command
     * execution results and the command exit code can be retrieved from the operation status API once available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunCommandParameters 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 runCommand(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters) {
        runCommandAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineRunCommandParameters).block();
    }

    /**
     * Run the command on the bare metal machine.
     *
     * <p>Run the command or the script on the provided bare metal machine. The URL to storage account with the command
     * execution results and the command exit code can be retrieved from the operation status API once available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunCommandParameters 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 runCommand(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunCommandParameters bareMetalMachineRunCommandParameters,
        Context context) {
        runCommandAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineRunCommandParameters, context).block();
    }

    /**
     * Run data extraction for a bare metal machine.
     *
     * <p>Run one or more data extractions on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunDataExtractsParameters 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>>> runDataExtractsWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineRunDataExtractsParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter bareMetalMachineRunDataExtractsParameters is required and cannot be null."));
        } else {
            bareMetalMachineRunDataExtractsParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .runDataExtracts(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            bareMetalMachineRunDataExtractsParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Run data extraction for a bare metal machine.
     *
     * <p>Run one or more data extractions on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunDataExtractsParameters 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>>> runDataExtractsWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters,
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineRunDataExtractsParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter bareMetalMachineRunDataExtractsParameters is required and cannot be null."));
        } else {
            bareMetalMachineRunDataExtractsParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .runDataExtracts(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                bareMetalMachineRunDataExtractsParameters,
                accept,
                context);
    }

    /**
     * Run data extraction for a bare metal machine.
     *
     * <p>Run one or more data extractions on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunDataExtractsParameters 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> beginRunDataExtractsAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            runDataExtractsWithResponseAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunDataExtractsParameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Run data extraction for a bare metal machine.
     *
     * <p>Run one or more data extractions on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunDataExtractsParameters 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> beginRunDataExtractsAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            runDataExtractsWithResponseAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunDataExtractsParameters, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Run data extraction for a bare metal machine.
     *
     * <p>Run one or more data extractions on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunDataExtractsParameters 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> beginRunDataExtracts(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters) {
        return this
            .beginRunDataExtractsAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunDataExtractsParameters)
            .getSyncPoller();
    }

    /**
     * Run data extraction for a bare metal machine.
     *
     * <p>Run one or more data extractions on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunDataExtractsParameters 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> beginRunDataExtracts(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters,
        Context context) {
        return this
            .beginRunDataExtractsAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunDataExtractsParameters, context)
            .getSyncPoller();
    }

    /**
     * Run data extraction for a bare metal machine.
     *
     * <p>Run one or more data extractions on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunDataExtractsParameters 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> runDataExtractsAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters) {
        return beginRunDataExtractsAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunDataExtractsParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Run data extraction for a bare metal machine.
     *
     * <p>Run one or more data extractions on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunDataExtractsParameters 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> runDataExtractsAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters,
        Context context) {
        return beginRunDataExtractsAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunDataExtractsParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Run data extraction for a bare metal machine.
     *
     * <p>Run one or more data extractions on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunDataExtractsParameters 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 runDataExtracts(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters) {
        runDataExtractsAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineRunDataExtractsParameters)
            .block();
    }

    /**
     * Run data extraction for a bare metal machine.
     *
     * <p>Run one or more data extractions on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunDataExtractsParameters 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 runDataExtracts(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunDataExtractsParameters bareMetalMachineRunDataExtractsParameters,
        Context context) {
        runDataExtractsAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunDataExtractsParameters, context)
            .block();
    }

    /**
     * Run read-only commands against a bare metal machine.
     *
     * <p>Run one or more read-only commands on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunReadCommandsParameters 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>>> runReadCommandsWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineRunReadCommandsParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter bareMetalMachineRunReadCommandsParameters is required and cannot be null."));
        } else {
            bareMetalMachineRunReadCommandsParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .runReadCommands(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            bareMetalMachineRunReadCommandsParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Run read-only commands against a bare metal machine.
     *
     * <p>Run one or more read-only commands on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunReadCommandsParameters 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>>> runReadCommandsWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters,
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineRunReadCommandsParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter bareMetalMachineRunReadCommandsParameters is required and cannot be null."));
        } else {
            bareMetalMachineRunReadCommandsParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .runReadCommands(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                bareMetalMachineRunReadCommandsParameters,
                accept,
                context);
    }

    /**
     * Run read-only commands against a bare metal machine.
     *
     * <p>Run one or more read-only commands on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunReadCommandsParameters 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> beginRunReadCommandsAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            runReadCommandsWithResponseAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunReadCommandsParameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Run read-only commands against a bare metal machine.
     *
     * <p>Run one or more read-only commands on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunReadCommandsParameters 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> beginRunReadCommandsAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            runReadCommandsWithResponseAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunReadCommandsParameters, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Run read-only commands against a bare metal machine.
     *
     * <p>Run one or more read-only commands on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunReadCommandsParameters 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> beginRunReadCommands(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters) {
        return this
            .beginRunReadCommandsAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunReadCommandsParameters)
            .getSyncPoller();
    }

    /**
     * Run read-only commands against a bare metal machine.
     *
     * <p>Run one or more read-only commands on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunReadCommandsParameters 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> beginRunReadCommands(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters,
        Context context) {
        return this
            .beginRunReadCommandsAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunReadCommandsParameters, context)
            .getSyncPoller();
    }

    /**
     * Run read-only commands against a bare metal machine.
     *
     * <p>Run one or more read-only commands on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunReadCommandsParameters 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> runReadCommandsAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters) {
        return beginRunReadCommandsAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunReadCommandsParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Run read-only commands against a bare metal machine.
     *
     * <p>Run one or more read-only commands on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunReadCommandsParameters 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> runReadCommandsAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters,
        Context context) {
        return beginRunReadCommandsAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunReadCommandsParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Run read-only commands against a bare metal machine.
     *
     * <p>Run one or more read-only commands on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunReadCommandsParameters 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 runReadCommands(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters) {
        runReadCommandsAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineRunReadCommandsParameters)
            .block();
    }

    /**
     * Run read-only commands against a bare metal machine.
     *
     * <p>Run one or more read-only commands on the provided bare metal machine. The URL to storage account with the
     * command execution results and the command exit code can be retrieved from the operation status API once
     * available.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineRunReadCommandsParameters 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 runReadCommands(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineRunReadCommandsParameters bareMetalMachineRunReadCommandsParameters,
        Context context) {
        runReadCommandsAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineRunReadCommandsParameters, context)
            .block();
    }

    /**
     * Start the bare metal machine.
     *
     * <p>Start the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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>>> startWithResponseAsync(
        String resourceGroupName, String bareMetalMachineName) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .start(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Start the bare metal machine.
     *
     * <p>Start the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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>>> startWithResponseAsync(
        String resourceGroupName, String bareMetalMachineName, 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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .start(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                accept,
                context);
    }

    /**
     * Start the bare metal machine.
     *
     * <p>Start the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginStartAsync(String resourceGroupName, String bareMetalMachineName) {
        Mono<Response<Flux<ByteBuffer>>> mono = startWithResponseAsync(resourceGroupName, bareMetalMachineName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Start the bare metal machine.
     *
     * <p>Start the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginStartAsync(
        String resourceGroupName, String bareMetalMachineName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            startWithResponseAsync(resourceGroupName, bareMetalMachineName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Start the bare metal machine.
     *
     * <p>Start the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginStart(String resourceGroupName, String bareMetalMachineName) {
        return this.beginStartAsync(resourceGroupName, bareMetalMachineName).getSyncPoller();
    }

    /**
     * Start the bare metal machine.
     *
     * <p>Start the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginStart(
        String resourceGroupName, String bareMetalMachineName, Context context) {
        return this.beginStartAsync(resourceGroupName, bareMetalMachineName, context).getSyncPoller();
    }

    /**
     * Start the bare metal machine.
     *
     * <p>Start the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> startAsync(String resourceGroupName, String bareMetalMachineName) {
        return beginStartAsync(resourceGroupName, bareMetalMachineName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Start the bare metal machine.
     *
     * <p>Start the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> startAsync(String resourceGroupName, String bareMetalMachineName, Context context) {
        return beginStartAsync(resourceGroupName, bareMetalMachineName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Start the bare metal machine.
     *
     * <p>Start the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 start(String resourceGroupName, String bareMetalMachineName) {
        startAsync(resourceGroupName, bareMetalMachineName).block();
    }

    /**
     * Start the bare metal machine.
     *
     * <p>Start the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 start(String resourceGroupName, String bareMetalMachineName, Context context) {
        startAsync(resourceGroupName, bareMetalMachineName, context).block();
    }

    /**
     * Uncordon the bare metal machine.
     *
     * <p>Uncordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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>>> uncordonWithResponseAsync(
        String resourceGroupName, String bareMetalMachineName) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .uncordon(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Uncordon the bare metal machine.
     *
     * <p>Uncordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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>>> uncordonWithResponseAsync(
        String resourceGroupName, String bareMetalMachineName, 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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .uncordon(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                accept,
                context);
    }

    /**
     * Uncordon the bare metal machine.
     *
     * <p>Uncordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginUncordonAsync(
        String resourceGroupName, String bareMetalMachineName) {
        Mono<Response<Flux<ByteBuffer>>> mono = uncordonWithResponseAsync(resourceGroupName, bareMetalMachineName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Uncordon the bare metal machine.
     *
     * <p>Uncordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginUncordonAsync(
        String resourceGroupName, String bareMetalMachineName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            uncordonWithResponseAsync(resourceGroupName, bareMetalMachineName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Uncordon the bare metal machine.
     *
     * <p>Uncordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginUncordon(String resourceGroupName, String bareMetalMachineName) {
        return this.beginUncordonAsync(resourceGroupName, bareMetalMachineName).getSyncPoller();
    }

    /**
     * Uncordon the bare metal machine.
     *
     * <p>Uncordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> beginUncordon(
        String resourceGroupName, String bareMetalMachineName, Context context) {
        return this.beginUncordonAsync(resourceGroupName, bareMetalMachineName, context).getSyncPoller();
    }

    /**
     * Uncordon the bare metal machine.
     *
     * <p>Uncordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> uncordonAsync(String resourceGroupName, String bareMetalMachineName) {
        return beginUncordonAsync(resourceGroupName, bareMetalMachineName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Uncordon the bare metal machine.
     *
     * <p>Uncordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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> uncordonAsync(String resourceGroupName, String bareMetalMachineName, Context context) {
        return beginUncordonAsync(resourceGroupName, bareMetalMachineName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Uncordon the bare metal machine.
     *
     * <p>Uncordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 uncordon(String resourceGroupName, String bareMetalMachineName) {
        uncordonAsync(resourceGroupName, bareMetalMachineName).block();
    }

    /**
     * Uncordon the bare metal machine.
     *
     * <p>Uncordon the provided bare metal machine's Kubernetes node.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @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 uncordon(String resourceGroupName, String bareMetalMachineName, Context context) {
        uncordonAsync(resourceGroupName, bareMetalMachineName, context).block();
    }

    /**
     * Trigger hardware validation of the bare metal machine.
     *
     * <p>Validate the hardware of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineValidateHardwareParameters 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>>> validateHardwareWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters) {
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineValidateHardwareParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter bareMetalMachineValidateHardwareParameters is required and cannot be null."));
        } else {
            bareMetalMachineValidateHardwareParameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .validateHardware(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            bareMetalMachineName,
                            bareMetalMachineValidateHardwareParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Trigger hardware validation of the bare metal machine.
     *
     * <p>Validate the hardware of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineValidateHardwareParameters 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>>> validateHardwareWithResponseAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters,
        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 (bareMetalMachineName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter bareMetalMachineName is required and cannot be null."));
        }
        if (bareMetalMachineValidateHardwareParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter bareMetalMachineValidateHardwareParameters is required and cannot be null."));
        } else {
            bareMetalMachineValidateHardwareParameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .validateHardware(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                bareMetalMachineName,
                bareMetalMachineValidateHardwareParameters,
                accept,
                context);
    }

    /**
     * Trigger hardware validation of the bare metal machine.
     *
     * <p>Validate the hardware of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineValidateHardwareParameters 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> beginValidateHardwareAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            validateHardwareWithResponseAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineValidateHardwareParameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Trigger hardware validation of the bare metal machine.
     *
     * <p>Validate the hardware of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineValidateHardwareParameters 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> beginValidateHardwareAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            validateHardwareWithResponseAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineValidateHardwareParameters, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Trigger hardware validation of the bare metal machine.
     *
     * <p>Validate the hardware of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineValidateHardwareParameters 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> beginValidateHardware(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters) {
        return this
            .beginValidateHardwareAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineValidateHardwareParameters)
            .getSyncPoller();
    }

    /**
     * Trigger hardware validation of the bare metal machine.
     *
     * <p>Validate the hardware of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineValidateHardwareParameters 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> beginValidateHardware(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters,
        Context context) {
        return this
            .beginValidateHardwareAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineValidateHardwareParameters, context)
            .getSyncPoller();
    }

    /**
     * Trigger hardware validation of the bare metal machine.
     *
     * <p>Validate the hardware of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineValidateHardwareParameters 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> validateHardwareAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters) {
        return beginValidateHardwareAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineValidateHardwareParameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Trigger hardware validation of the bare metal machine.
     *
     * <p>Validate the hardware of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineValidateHardwareParameters 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> validateHardwareAsync(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters,
        Context context) {
        return beginValidateHardwareAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineValidateHardwareParameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Trigger hardware validation of the bare metal machine.
     *
     * <p>Validate the hardware of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineValidateHardwareParameters 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 validateHardware(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters) {
        validateHardwareAsync(resourceGroupName, bareMetalMachineName, bareMetalMachineValidateHardwareParameters)
            .block();
    }

    /**
     * Trigger hardware validation of the bare metal machine.
     *
     * <p>Validate the hardware of the provided bare metal machine.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param bareMetalMachineName The name of the bare metal machine.
     * @param bareMetalMachineValidateHardwareParameters 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 validateHardware(
        String resourceGroupName,
        String bareMetalMachineName,
        BareMetalMachineValidateHardwareParameters bareMetalMachineValidateHardwareParameters,
        Context context) {
        validateHardwareAsync(
                resourceGroupName, bareMetalMachineName, bareMetalMachineValidateHardwareParameters, 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 bareMetalMachineList represents a list of bare metal machines along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BareMetalMachineInner>> 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<BareMetalMachineInner>>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 bareMetalMachineList represents a list of bare metal machines along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BareMetalMachineInner>> 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 bareMetalMachineList represents a list of bare metal machines along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BareMetalMachineInner>> 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<BareMetalMachineInner>>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 bareMetalMachineList represents a list of bare metal machines along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<BareMetalMachineInner>> 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));
    }
}
