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

package com.azure.resourcemanager.datamigration.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.datamigration.fluent.ServicesClient;
import com.azure.resourcemanager.datamigration.fluent.models.AvailableServiceSkuInner;
import com.azure.resourcemanager.datamigration.fluent.models.DataMigrationServiceInner;
import com.azure.resourcemanager.datamigration.fluent.models.DataMigrationServiceStatusResponseInner;
import com.azure.resourcemanager.datamigration.fluent.models.NameAvailabilityResponseInner;
import com.azure.resourcemanager.datamigration.models.DataMigrationServiceList;
import com.azure.resourcemanager.datamigration.models.NameAvailabilityRequest;
import com.azure.resourcemanager.datamigration.models.ServiceSkuList;
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 ServicesClient. */
public final class ServicesClientImpl implements ServicesClient {
    /** The proxy service used to perform REST calls. */
    private final ServicesService service;

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

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

    /**
     * The interface defining all the services for DataMigrationManagementClientServices to be used by the proxy service
     * to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "DataMigrationManagem")
    public interface ServicesService {
        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.DataMigration/services"
                + "/{serviceName}")
        @ExpectedResponses({200, 201, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("groupName") String groupName,
            @PathParam("serviceName") String serviceName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") DataMigrationServiceInner parameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.DataMigration/services"
                + "/{serviceName}/checkStatus")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<DataMigrationServiceStatusResponseInner>> checkStatus(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("groupName") String groupName,
            @PathParam("serviceName") String serviceName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.DataMigration/services"
                + "/{serviceName}/stop")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> stop(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("groupName") String groupName,
            @PathParam("serviceName") String serviceName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{groupName}/providers/Microsoft.DataMigration/services"
                + "/{serviceName}/checkNameAvailability")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<NameAvailabilityResponseInner>> nestedCheckNameAvailability(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("groupName") String groupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("serviceName") String serviceName,
            @BodyParam("application/json") NameAvailabilityRequest parameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/Microsoft.DataMigration/locations/{location}"
                + "/checkNameAvailability")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<NameAvailabilityResponseInner>> checkNameAvailability(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("location") String location,
            @BodyParam("application/json") NameAvailabilityRequest parameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Create or update DMS Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PUT method
     * creates a new service or updates an existing one. When a service is updated, existing child resources (i.e.
     * tasks) are unaffected. Services currently support a single kind, "vm", which refers to a VM-based service,
     * although other kinds may be added in the future. This method can change the kind, SKU, and network of the
     * service, but if tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request
     * ("ServiceIsBusy"). The provider will reply when successful with 200 OK or 201 Created. Long-running operations
     * use the provisioningState property.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Database Migration Service resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters) {
        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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            groupName,
                            serviceName,
                            this.client.getApiVersion(),
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create or update DMS Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PUT method
     * creates a new service or updates an existing one. When a service is updated, existing child resources (i.e.
     * tasks) are unaffected. Services currently support a single kind, "vm", which refers to a VM-based service,
     * although other kinds may be added in the future. This method can change the kind, SKU, and network of the
     * service, but if tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request
     * ("ServiceIsBusy"). The provider will reply when successful with 200 OK or 201 Created. Long-running operations
     * use the provisioningState property.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @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 Database Migration Service resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters, 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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                groupName,
                serviceName,
                this.client.getApiVersion(),
                parameters,
                accept,
                context);
    }

    /**
     * Create or update DMS Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PUT method
     * creates a new service or updates an existing one. When a service is updated, existing child resources (i.e.
     * tasks) are unaffected. Services currently support a single kind, "vm", which refers to a VM-based service,
     * although other kinds may be added in the future. This method can change the kind, SKU, and network of the
     * service, but if tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request
     * ("ServiceIsBusy"). The provider will reply when successful with 200 OK or 201 Created. Long-running operations
     * use the provisioningState property.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of a Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DataMigrationServiceInner>, DataMigrationServiceInner> beginCreateOrUpdateAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono = createOrUpdateWithResponseAsync(groupName, serviceName, parameters);
        return this
            .client
            .<DataMigrationServiceInner, DataMigrationServiceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DataMigrationServiceInner.class,
                DataMigrationServiceInner.class,
                this.client.getContext());
    }

    /**
     * Create or update DMS Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PUT method
     * creates a new service or updates an existing one. When a service is updated, existing child resources (i.e.
     * tasks) are unaffected. Services currently support a single kind, "vm", which refers to a VM-based service,
     * although other kinds may be added in the future. This method can change the kind, SKU, and network of the
     * service, but if tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request
     * ("ServiceIsBusy"). The provider will reply when successful with 200 OK or 201 Created. Long-running operations
     * use the provisioningState property.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of a Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DataMigrationServiceInner>, DataMigrationServiceInner> beginCreateOrUpdateAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(groupName, serviceName, parameters, context);
        return this
            .client
            .<DataMigrationServiceInner, DataMigrationServiceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DataMigrationServiceInner.class,
                DataMigrationServiceInner.class,
                context);
    }

    /**
     * Create or update DMS Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PUT method
     * creates a new service or updates an existing one. When a service is updated, existing child resources (i.e.
     * tasks) are unaffected. Services currently support a single kind, "vm", which refers to a VM-based service,
     * although other kinds may be added in the future. This method can change the kind, SKU, and network of the
     * service, but if tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request
     * ("ServiceIsBusy"). The provider will reply when successful with 200 OK or 201 Created. Long-running operations
     * use the provisioningState property.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of a Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DataMigrationServiceInner>, DataMigrationServiceInner> beginCreateOrUpdate(
        String groupName, String serviceName, DataMigrationServiceInner parameters) {
        return this.beginCreateOrUpdateAsync(groupName, serviceName, parameters).getSyncPoller();
    }

    /**
     * Create or update DMS Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PUT method
     * creates a new service or updates an existing one. When a service is updated, existing child resources (i.e.
     * tasks) are unaffected. Services currently support a single kind, "vm", which refers to a VM-based service,
     * although other kinds may be added in the future. This method can change the kind, SKU, and network of the
     * service, but if tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request
     * ("ServiceIsBusy"). The provider will reply when successful with 200 OK or 201 Created. Long-running operations
     * use the provisioningState property.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of a Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DataMigrationServiceInner>, DataMigrationServiceInner> beginCreateOrUpdate(
        String groupName, String serviceName, DataMigrationServiceInner parameters, Context context) {
        return this.beginCreateOrUpdateAsync(groupName, serviceName, parameters, context).getSyncPoller();
    }

    /**
     * Create or update DMS Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PUT method
     * creates a new service or updates an existing one. When a service is updated, existing child resources (i.e.
     * tasks) are unaffected. Services currently support a single kind, "vm", which refers to a VM-based service,
     * although other kinds may be added in the future. This method can change the kind, SKU, and network of the
     * service, but if tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request
     * ("ServiceIsBusy"). The provider will reply when successful with 200 OK or 201 Created. Long-running operations
     * use the provisioningState property.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Database Migration Service resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DataMigrationServiceInner> createOrUpdateAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters) {
        return beginCreateOrUpdateAsync(groupName, serviceName, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update DMS Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PUT method
     * creates a new service or updates an existing one. When a service is updated, existing child resources (i.e.
     * tasks) are unaffected. Services currently support a single kind, "vm", which refers to a VM-based service,
     * although other kinds may be added in the future. This method can change the kind, SKU, and network of the
     * service, but if tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request
     * ("ServiceIsBusy"). The provider will reply when successful with 200 OK or 201 Created. Long-running operations
     * use the provisioningState property.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @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 Database Migration Service resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DataMigrationServiceInner> createOrUpdateAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters, Context context) {
        return beginCreateOrUpdateAsync(groupName, serviceName, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update DMS Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PUT method
     * creates a new service or updates an existing one. When a service is updated, existing child resources (i.e.
     * tasks) are unaffected. Services currently support a single kind, "vm", which refers to a VM-based service,
     * although other kinds may be added in the future. This method can change the kind, SKU, and network of the
     * service, but if tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request
     * ("ServiceIsBusy"). The provider will reply when successful with 200 OK or 201 Created. Long-running operations
     * use the provisioningState property.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DataMigrationServiceInner createOrUpdate(
        String groupName, String serviceName, DataMigrationServiceInner parameters) {
        return createOrUpdateAsync(groupName, serviceName, parameters).block();
    }

    /**
     * Create or update DMS Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PUT method
     * creates a new service or updates an existing one. When a service is updated, existing child resources (i.e.
     * tasks) are unaffected. Services currently support a single kind, "vm", which refers to a VM-based service,
     * although other kinds may be added in the future. This method can change the kind, SKU, and network of the
     * service, but if tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request
     * ("ServiceIsBusy"). The provider will reply when successful with 200 OK or 201 Created. Long-running operations
     * use the provisioningState property.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @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 Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DataMigrationServiceInner createOrUpdate(
        String groupName, String serviceName, DataMigrationServiceInner parameters, Context context) {
        return createOrUpdateAsync(groupName, serviceName, parameters, context).block();
    }

    /**
     * Get DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The GET method
     * retrieves information about a service instance.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Database Migration Service resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<DataMigrationServiceInner>> getByResourceGroupWithResponseAsync(
        String groupName, String serviceName) {
        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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            groupName,
                            serviceName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The GET method
     * retrieves information about a service instance.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 Database Migration Service resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<DataMigrationServiceInner>> getByResourceGroupWithResponseAsync(
        String groupName, String serviceName, 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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getByResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                groupName,
                serviceName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Get DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The GET method
     * retrieves information about a service instance.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Database Migration Service resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DataMigrationServiceInner> getByResourceGroupAsync(String groupName, String serviceName) {
        return getByResourceGroupWithResponseAsync(groupName, serviceName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The GET method
     * retrieves information about a service instance.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 Database Migration Service resource along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<DataMigrationServiceInner> getByResourceGroupWithResponse(
        String groupName, String serviceName, Context context) {
        return getByResourceGroupWithResponseAsync(groupName, serviceName, context).block();
    }

    /**
     * Get DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The GET method
     * retrieves information about a service instance.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DataMigrationServiceInner getByResourceGroup(String groupName, String serviceName) {
        return getByResourceGroupWithResponse(groupName, serviceName, Context.NONE).getValue();
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param deleteRunningTasks Delete the resource even if it contains running tasks.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 groupName, String serviceName, Boolean deleteRunningTasks) {
        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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            groupName,
                            serviceName,
                            this.client.getApiVersion(),
                            deleteRunningTasks,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param deleteRunningTasks Delete the resource even if it contains running tasks.
     * @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 groupName, String serviceName, Boolean deleteRunningTasks, 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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                groupName,
                serviceName,
                this.client.getApiVersion(),
                deleteRunningTasks,
                accept,
                context);
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param deleteRunningTasks Delete the resource even if it contains running tasks.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 groupName, String serviceName, Boolean deleteRunningTasks) {
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(groupName, serviceName, deleteRunningTasks);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 groupName, String serviceName) {
        final Boolean deleteRunningTasks = null;
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(groupName, serviceName, deleteRunningTasks);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param deleteRunningTasks Delete the resource even if it contains running tasks.
     * @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 groupName, String serviceName, Boolean deleteRunningTasks, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(groupName, serviceName, deleteRunningTasks, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 groupName, String serviceName) {
        final Boolean deleteRunningTasks = null;
        return this.beginDeleteAsync(groupName, serviceName, deleteRunningTasks).getSyncPoller();
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param deleteRunningTasks Delete the resource even if it contains running tasks.
     * @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 groupName, String serviceName, Boolean deleteRunningTasks, Context context) {
        return this.beginDeleteAsync(groupName, serviceName, deleteRunningTasks, context).getSyncPoller();
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param deleteRunningTasks Delete the resource even if it contains running tasks.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 groupName, String serviceName, Boolean deleteRunningTasks) {
        return beginDeleteAsync(groupName, serviceName, deleteRunningTasks)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 groupName, String serviceName) {
        final Boolean deleteRunningTasks = null;
        return beginDeleteAsync(groupName, serviceName, deleteRunningTasks)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param deleteRunningTasks Delete the resource even if it contains running tasks.
     * @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 groupName, String serviceName, Boolean deleteRunningTasks, Context context) {
        return beginDeleteAsync(groupName, serviceName, deleteRunningTasks, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 groupName, String serviceName) {
        final Boolean deleteRunningTasks = null;
        deleteAsync(groupName, serviceName, deleteRunningTasks).block();
    }

    /**
     * Delete DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The DELETE
     * method deletes a service. Any running tasks will be canceled.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param deleteRunningTasks Delete the resource even if it contains running tasks.
     * @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 groupName, String serviceName, Boolean deleteRunningTasks, Context context) {
        deleteAsync(groupName, serviceName, deleteRunningTasks, context).block();
    }

    /**
     * Create or update DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PATCH
     * method updates an existing service. This method can change the kind, SKU, and network of the service, but if
     * tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request ("ServiceIsBusy").
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Database Migration Service resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters) {
        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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            groupName,
                            serviceName,
                            this.client.getApiVersion(),
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create or update DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PATCH
     * method updates an existing service. This method can change the kind, SKU, and network of the service, but if
     * tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request ("ServiceIsBusy").
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @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 Database Migration Service resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters, 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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                groupName,
                serviceName,
                this.client.getApiVersion(),
                parameters,
                accept,
                context);
    }

    /**
     * Create or update DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PATCH
     * method updates an existing service. This method can change the kind, SKU, and network of the service, but if
     * tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request ("ServiceIsBusy").
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of a Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DataMigrationServiceInner>, DataMigrationServiceInner> beginUpdateAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono = updateWithResponseAsync(groupName, serviceName, parameters);
        return this
            .client
            .<DataMigrationServiceInner, DataMigrationServiceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DataMigrationServiceInner.class,
                DataMigrationServiceInner.class,
                this.client.getContext());
    }

    /**
     * Create or update DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PATCH
     * method updates an existing service. This method can change the kind, SKU, and network of the service, but if
     * tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request ("ServiceIsBusy").
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of a Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DataMigrationServiceInner>, DataMigrationServiceInner> beginUpdateAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = updateWithResponseAsync(groupName, serviceName, parameters, context);
        return this
            .client
            .<DataMigrationServiceInner, DataMigrationServiceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DataMigrationServiceInner.class,
                DataMigrationServiceInner.class,
                context);
    }

    /**
     * Create or update DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PATCH
     * method updates an existing service. This method can change the kind, SKU, and network of the service, but if
     * tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request ("ServiceIsBusy").
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of a Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DataMigrationServiceInner>, DataMigrationServiceInner> beginUpdate(
        String groupName, String serviceName, DataMigrationServiceInner parameters) {
        return this.beginUpdateAsync(groupName, serviceName, parameters).getSyncPoller();
    }

    /**
     * Create or update DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PATCH
     * method updates an existing service. This method can change the kind, SKU, and network of the service, but if
     * tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request ("ServiceIsBusy").
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of a Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DataMigrationServiceInner>, DataMigrationServiceInner> beginUpdate(
        String groupName, String serviceName, DataMigrationServiceInner parameters, Context context) {
        return this.beginUpdateAsync(groupName, serviceName, parameters, context).getSyncPoller();
    }

    /**
     * Create or update DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PATCH
     * method updates an existing service. This method can change the kind, SKU, and network of the service, but if
     * tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request ("ServiceIsBusy").
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Database Migration Service resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DataMigrationServiceInner> updateAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters) {
        return beginUpdateAsync(groupName, serviceName, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PATCH
     * method updates an existing service. This method can change the kind, SKU, and network of the service, but if
     * tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request ("ServiceIsBusy").
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @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 Database Migration Service resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DataMigrationServiceInner> updateAsync(
        String groupName, String serviceName, DataMigrationServiceInner parameters, Context context) {
        return beginUpdateAsync(groupName, serviceName, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create or update DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PATCH
     * method updates an existing service. This method can change the kind, SKU, and network of the service, but if
     * tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request ("ServiceIsBusy").
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DataMigrationServiceInner update(
        String groupName, String serviceName, DataMigrationServiceInner parameters) {
        return updateAsync(groupName, serviceName, parameters).block();
    }

    /**
     * Create or update DMS Service Instance
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The PATCH
     * method updates an existing service. This method can change the kind, SKU, and network of the service, but if
     * tasks are currently running (i.e. the service is busy), this will fail with 400 Bad Request ("ServiceIsBusy").
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Information about the service.
     * @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 Database Migration Service resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DataMigrationServiceInner update(
        String groupName, String serviceName, DataMigrationServiceInner parameters, Context context) {
        return updateAsync(groupName, serviceName, parameters, context).block();
    }

    /**
     * Check service health status
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * performs a health check and returns the status of the service and virtual machine size.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return service health status along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<DataMigrationServiceStatusResponseInner>> checkStatusWithResponseAsync(
        String groupName, String serviceName) {
        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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .checkStatus(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            groupName,
                            serviceName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Check service health status
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * performs a health check and returns the status of the service and virtual machine size.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 service health status along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<DataMigrationServiceStatusResponseInner>> checkStatusWithResponseAsync(
        String groupName, String serviceName, 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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .checkStatus(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                groupName,
                serviceName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Check service health status
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * performs a health check and returns the status of the service and virtual machine size.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return service health status on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DataMigrationServiceStatusResponseInner> checkStatusAsync(String groupName, String serviceName) {
        return checkStatusWithResponseAsync(groupName, serviceName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Check service health status
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * performs a health check and returns the status of the service and virtual machine size.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 service health status along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<DataMigrationServiceStatusResponseInner> checkStatusWithResponse(
        String groupName, String serviceName, Context context) {
        return checkStatusWithResponseAsync(groupName, serviceName, context).block();
    }

    /**
     * Check service health status
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * performs a health check and returns the status of the service and virtual machine size.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return service health status.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DataMigrationServiceStatusResponseInner checkStatus(String groupName, String serviceName) {
        return checkStatusWithResponse(groupName, serviceName, Context.NONE).getValue();
    }

    /**
     * Start service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * starts the service and the service can be used for data migration.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 groupName, String serviceName) {
        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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .start(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            groupName,
                            serviceName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Start service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * starts the service and the service can be used for data migration.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 groupName, String serviceName, 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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .start(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                groupName,
                serviceName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Start service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * starts the service and the service can be used for data migration.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 groupName, String serviceName) {
        Mono<Response<Flux<ByteBuffer>>> mono = startWithResponseAsync(groupName, serviceName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Start service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * starts the service and the service can be used for data migration.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 groupName, String serviceName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = startWithResponseAsync(groupName, serviceName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Start service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * starts the service and the service can be used for data migration.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 groupName, String serviceName) {
        return this.beginStartAsync(groupName, serviceName).getSyncPoller();
    }

    /**
     * Start service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * starts the service and the service can be used for data migration.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 groupName, String serviceName, Context context) {
        return this.beginStartAsync(groupName, serviceName, context).getSyncPoller();
    }

    /**
     * Start service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * starts the service and the service can be used for data migration.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 groupName, String serviceName) {
        return beginStartAsync(groupName, serviceName).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Start service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * starts the service and the service can be used for data migration.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 groupName, String serviceName, Context context) {
        return beginStartAsync(groupName, serviceName, context).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Start service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * starts the service and the service can be used for data migration.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 groupName, String serviceName) {
        startAsync(groupName, serviceName).block();
    }

    /**
     * Start service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * starts the service and the service can be used for data migration.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 groupName, String serviceName, Context context) {
        startAsync(groupName, serviceName, context).block();
    }

    /**
     * Stop service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * stops the service and the service cannot be used for data migration. The service owner won't be billed when the
     * service is stopped.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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>>> stopWithResponseAsync(String groupName, String serviceName) {
        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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .stop(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            groupName,
                            serviceName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Stop service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * stops the service and the service cannot be used for data migration. The service owner won't be billed when the
     * service is stopped.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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>>> stopWithResponseAsync(
        String groupName, String serviceName, 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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .stop(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                groupName,
                serviceName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Stop service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * stops the service and the service cannot be used for data migration. The service owner won't be billed when the
     * service is stopped.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> beginStopAsync(String groupName, String serviceName) {
        Mono<Response<Flux<ByteBuffer>>> mono = stopWithResponseAsync(groupName, serviceName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Stop service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * stops the service and the service cannot be used for data migration. The service owner won't be billed when the
     * service is stopped.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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> beginStopAsync(String groupName, String serviceName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = stopWithResponseAsync(groupName, serviceName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Stop service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * stops the service and the service cannot be used for data migration. The service owner won't be billed when the
     * service is stopped.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> beginStop(String groupName, String serviceName) {
        return this.beginStopAsync(groupName, serviceName).getSyncPoller();
    }

    /**
     * Stop service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * stops the service and the service cannot be used for data migration. The service owner won't be billed when the
     * service is stopped.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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> beginStop(String groupName, String serviceName, Context context) {
        return this.beginStopAsync(groupName, serviceName, context).getSyncPoller();
    }

    /**
     * Stop service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * stops the service and the service cannot be used for data migration. The service owner won't be billed when the
     * service is stopped.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> stopAsync(String groupName, String serviceName) {
        return beginStopAsync(groupName, serviceName).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Stop service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * stops the service and the service cannot be used for data migration. The service owner won't be billed when the
     * service is stopped.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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> stopAsync(String groupName, String serviceName, Context context) {
        return beginStopAsync(groupName, serviceName, context).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Stop service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * stops the service and the service cannot be used for data migration. The service owner won't be billed when the
     * service is stopped.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 stop(String groupName, String serviceName) {
        stopAsync(groupName, serviceName).block();
    }

    /**
     * Stop service
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This action
     * stops the service and the service cannot be used for data migration. The service owner won't be billed when the
     * service is stopped.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 stop(String groupName, String serviceName, Context context) {
        stopAsync(groupName, serviceName, context).block();
    }

    /**
     * Get compatible SKUs
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The skus
     * action returns the list of SKUs that a service resource can be updated to.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return oData page of available SKUs along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AvailableServiceSkuInner>> listSkusSinglePageAsync(
        String groupName, String serviceName) {
        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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listSkus(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            groupName,
                            serviceName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<AvailableServiceSkuInner>>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 compatible SKUs
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The skus
     * action returns the list of SKUs that a service resource can be updated to.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 oData page of available SKUs along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AvailableServiceSkuInner>> listSkusSinglePageAsync(
        String groupName, String serviceName, 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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listSkus(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                groupName,
                serviceName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get compatible SKUs
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The skus
     * action returns the list of SKUs that a service resource can be updated to.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return oData page of available SKUs as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<AvailableServiceSkuInner> listSkusAsync(String groupName, String serviceName) {
        return new PagedFlux<>(
            () -> listSkusSinglePageAsync(groupName, serviceName), nextLink -> listSkusNextSinglePageAsync(nextLink));
    }

    /**
     * Get compatible SKUs
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The skus
     * action returns the list of SKUs that a service resource can be updated to.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 oData page of available SKUs as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<AvailableServiceSkuInner> listSkusAsync(String groupName, String serviceName, Context context) {
        return new PagedFlux<>(
            () -> listSkusSinglePageAsync(groupName, serviceName, context),
            nextLink -> listSkusNextSinglePageAsync(nextLink, context));
    }

    /**
     * Get compatible SKUs
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The skus
     * action returns the list of SKUs that a service resource can be updated to.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return oData page of available SKUs as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<AvailableServiceSkuInner> listSkus(String groupName, String serviceName) {
        return new PagedIterable<>(listSkusAsync(groupName, serviceName));
    }

    /**
     * Get compatible SKUs
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. The skus
     * action returns the list of SKUs that a service resource can be updated to.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @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 oData page of available SKUs as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<AvailableServiceSkuInner> listSkus(String groupName, String serviceName, Context context) {
        return new PagedIterable<>(listSkusAsync(groupName, serviceName, context));
    }

    /**
     * Check nested resource name validity and availability
     *
     * <p>This method checks whether a proposed nested resource name is valid and available.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Requested name to validate.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return indicates whether a proposed resource name is available along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<NameAvailabilityResponseInner>> nestedCheckNameAvailabilityWithResponseAsync(
        String groupName, String serviceName, NameAvailabilityRequest parameters) {
        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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .nestedCheckNameAvailability(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            groupName,
                            this.client.getApiVersion(),
                            serviceName,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Check nested resource name validity and availability
     *
     * <p>This method checks whether a proposed nested resource name is valid and available.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Requested name to validate.
     * @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 indicates whether a proposed resource name is available along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<NameAvailabilityResponseInner>> nestedCheckNameAvailabilityWithResponseAsync(
        String groupName, String serviceName, NameAvailabilityRequest parameters, 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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .nestedCheckNameAvailability(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                groupName,
                this.client.getApiVersion(),
                serviceName,
                parameters,
                accept,
                context);
    }

    /**
     * Check nested resource name validity and availability
     *
     * <p>This method checks whether a proposed nested resource name is valid and available.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Requested name to validate.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return indicates whether a proposed resource name is available on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<NameAvailabilityResponseInner> nestedCheckNameAvailabilityAsync(
        String groupName, String serviceName, NameAvailabilityRequest parameters) {
        return nestedCheckNameAvailabilityWithResponseAsync(groupName, serviceName, parameters)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Check nested resource name validity and availability
     *
     * <p>This method checks whether a proposed nested resource name is valid and available.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Requested name to validate.
     * @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 indicates whether a proposed resource name is available along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<NameAvailabilityResponseInner> nestedCheckNameAvailabilityWithResponse(
        String groupName, String serviceName, NameAvailabilityRequest parameters, Context context) {
        return nestedCheckNameAvailabilityWithResponseAsync(groupName, serviceName, parameters, context).block();
    }

    /**
     * Check nested resource name validity and availability
     *
     * <p>This method checks whether a proposed nested resource name is valid and available.
     *
     * @param groupName Name of the resource group.
     * @param serviceName Name of the service.
     * @param parameters Requested name to validate.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return indicates whether a proposed resource name is available.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public NameAvailabilityResponseInner nestedCheckNameAvailability(
        String groupName, String serviceName, NameAvailabilityRequest parameters) {
        return nestedCheckNameAvailabilityWithResponse(groupName, serviceName, parameters, Context.NONE).getValue();
    }

    /**
     * Get services in resource group
     *
     * <p>The Services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a resource group.
     *
     * @param groupName Name of the resource group.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return oData page of service objects along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DataMigrationServiceInner>> listByResourceGroupSinglePageAsync(String groupName) {
        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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            groupName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<DataMigrationServiceInner>>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 services in resource group
     *
     * <p>The Services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a resource group.
     *
     * @param groupName Name of the resource group.
     * @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 oData page of service objects along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DataMigrationServiceInner>> listByResourceGroupSinglePageAsync(
        String groupName, 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 (groupName == null) {
            return Mono.error(new IllegalArgumentException("Parameter groupName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                groupName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get services in resource group
     *
     * <p>The Services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a resource group.
     *
     * @param groupName Name of the resource group.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return oData page of service objects as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<DataMigrationServiceInner> listByResourceGroupAsync(String groupName) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(groupName),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Get services in resource group
     *
     * <p>The Services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a resource group.
     *
     * @param groupName Name of the resource group.
     * @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 oData page of service objects as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<DataMigrationServiceInner> listByResourceGroupAsync(String groupName, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(groupName, context),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * Get services in resource group
     *
     * <p>The Services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a resource group.
     *
     * @param groupName Name of the resource group.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return oData page of service objects as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<DataMigrationServiceInner> listByResourceGroup(String groupName) {
        return new PagedIterable<>(listByResourceGroupAsync(groupName));
    }

    /**
     * Get services in resource group
     *
     * <p>The Services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a resource group.
     *
     * @param groupName Name of the resource group.
     * @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 oData page of service objects as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<DataMigrationServiceInner> listByResourceGroup(String groupName, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(groupName, context));
    }

    /**
     * Get services in subscription
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return oData page of service objects along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DataMigrationServiceInner>> 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.getSubscriptionId(),
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<DataMigrationServiceInner>>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 services in subscription
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a 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 oData page of service objects along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DataMigrationServiceInner>> 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.getSubscriptionId(),
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Get services in subscription
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return oData page of service objects as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<DataMigrationServiceInner> listAsync() {
        return new PagedFlux<>(() -> listSinglePageAsync(), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Get services in subscription
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a 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 oData page of service objects as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<DataMigrationServiceInner> listAsync(Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(context), nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Get services in subscription
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return oData page of service objects as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<DataMigrationServiceInner> list() {
        return new PagedIterable<>(listAsync());
    }

    /**
     * Get services in subscription
     *
     * <p>The services resource is the top-level resource that represents the Database Migration Service. This method
     * returns a list of service resources in a 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 oData page of service objects as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<DataMigrationServiceInner> list(Context context) {
        return new PagedIterable<>(listAsync(context));
    }

    /**
     * Check name validity and availability
     *
     * <p>This method checks whether a proposed top-level resource name is valid and available.
     *
     * @param location The Azure region of the operation.
     * @param parameters Requested name to validate.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return indicates whether a proposed resource name is available along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<NameAvailabilityResponseInner>> checkNameAvailabilityWithResponseAsync(
        String location, NameAvailabilityRequest parameters) {
        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 (location == null) {
            return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .checkNameAvailability(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            location,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Check name validity and availability
     *
     * <p>This method checks whether a proposed top-level resource name is valid and available.
     *
     * @param location The Azure region of the operation.
     * @param parameters Requested name to validate.
     * @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 indicates whether a proposed resource name is available along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<NameAvailabilityResponseInner>> checkNameAvailabilityWithResponseAsync(
        String location, NameAvailabilityRequest parameters, 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 (location == null) {
            return Mono.error(new IllegalArgumentException("Parameter location is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .checkNameAvailability(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                location,
                parameters,
                accept,
                context);
    }

    /**
     * Check name validity and availability
     *
     * <p>This method checks whether a proposed top-level resource name is valid and available.
     *
     * @param location The Azure region of the operation.
     * @param parameters Requested name to validate.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return indicates whether a proposed resource name is available on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<NameAvailabilityResponseInner> checkNameAvailabilityAsync(
        String location, NameAvailabilityRequest parameters) {
        return checkNameAvailabilityWithResponseAsync(location, parameters)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Check name validity and availability
     *
     * <p>This method checks whether a proposed top-level resource name is valid and available.
     *
     * @param location The Azure region of the operation.
     * @param parameters Requested name to validate.
     * @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 indicates whether a proposed resource name is available along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<NameAvailabilityResponseInner> checkNameAvailabilityWithResponse(
        String location, NameAvailabilityRequest parameters, Context context) {
        return checkNameAvailabilityWithResponseAsync(location, parameters, context).block();
    }

    /**
     * Check name validity and availability
     *
     * <p>This method checks whether a proposed top-level resource name is valid and available.
     *
     * @param location The Azure region of the operation.
     * @param parameters Requested name to validate.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return indicates whether a proposed resource name is available.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public NameAvailabilityResponseInner checkNameAvailability(String location, NameAvailabilityRequest parameters) {
        return checkNameAvailabilityWithResponse(location, parameters, Context.NONE).getValue();
    }

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

    /**
     * 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 oData page of service objects along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DataMigrationServiceInner>> listNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<DataMigrationServiceInner>>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 oData page of service objects along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DataMigrationServiceInner>> listNextSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
