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

package com.azure.resourcemanager.storagemover.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.storagemover.fluent.JobDefinitionsClient;
import com.azure.resourcemanager.storagemover.fluent.models.JobDefinitionInner;
import com.azure.resourcemanager.storagemover.fluent.models.JobRunResourceIdInner;
import com.azure.resourcemanager.storagemover.models.JobDefinitionList;
import com.azure.resourcemanager.storagemover.models.JobDefinitionUpdateParameters;
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 JobDefinitionsClient. */
public final class JobDefinitionsClientImpl implements JobDefinitionsClient {
    /** The proxy service used to perform REST calls. */
    private final JobDefinitionsService service;

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

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

    /**
     * The interface defining all the services for StorageMoverClientJobDefinitions to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "StorageMoverClientJo")
    public interface JobDefinitionsService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageMover/storageMovers/{storageMoverName}/projects/{projectName}/jobDefinitions")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<JobDefinitionList>> list(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("storageMoverName") String storageMoverName,
            @PathParam("projectName") String projectName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageMover/storageMovers/{storageMoverName}/projects/{projectName}/jobDefinitions/{jobDefinitionName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<JobDefinitionInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("storageMoverName") String storageMoverName,
            @PathParam("projectName") String projectName,
            @PathParam("jobDefinitionName") String jobDefinitionName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageMover/storageMovers/{storageMoverName}/projects/{projectName}/jobDefinitions/{jobDefinitionName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<JobDefinitionInner>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("storageMoverName") String storageMoverName,
            @PathParam("projectName") String projectName,
            @PathParam("jobDefinitionName") String jobDefinitionName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") JobDefinitionInner jobDefinition,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageMover/storageMovers/{storageMoverName}/projects/{projectName}/jobDefinitions/{jobDefinitionName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<JobDefinitionInner>> update(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("storageMoverName") String storageMoverName,
            @PathParam("projectName") String projectName,
            @PathParam("jobDefinitionName") String jobDefinitionName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") JobDefinitionUpdateParameters jobDefinition,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageMover/storageMovers/{storageMoverName}/projects/{projectName}/jobDefinitions/{jobDefinitionName}/startJob")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<JobRunResourceIdInner>> startJob(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("storageMoverName") String storageMoverName,
            @PathParam("projectName") String projectName,
            @PathParam("jobDefinitionName") String jobDefinitionName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.StorageMover/storageMovers/{storageMoverName}/projects/{projectName}/jobDefinitions/{jobDefinitionName}/stopJob")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<JobRunResourceIdInner>> stopJob(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("storageMoverName") String storageMoverName,
            @PathParam("projectName") String projectName,
            @PathParam("jobDefinitionName") String jobDefinitionName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Lists all Job Definitions in a Project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of Job Definitions along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<JobDefinitionInner>> listSinglePageAsync(
        String resourceGroupName, String storageMoverName, String projectName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            storageMoverName,
                            projectName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .<PagedResponse<JobDefinitionInner>>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()));
    }

    /**
     * Lists all Job Definitions in a Project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of Job Definitions along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<JobDefinitionInner>> listSinglePageAsync(
        String resourceGroupName, String storageMoverName, String projectName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName 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(),
                resourceGroupName,
                storageMoverName,
                projectName,
                this.client.getApiVersion(),
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Lists all Job Definitions in a Project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of Job Definitions as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<JobDefinitionInner> listAsync(
        String resourceGroupName, String storageMoverName, String projectName) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, storageMoverName, projectName),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Lists all Job Definitions in a Project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of Job Definitions as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<JobDefinitionInner> listAsync(
        String resourceGroupName, String storageMoverName, String projectName, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(resourceGroupName, storageMoverName, projectName, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists all Job Definitions in a Project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of Job Definitions as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<JobDefinitionInner> list(
        String resourceGroupName, String storageMoverName, String projectName) {
        return new PagedIterable<>(listAsync(resourceGroupName, storageMoverName, projectName));
    }

    /**
     * Lists all Job Definitions in a Project.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of Job Definitions as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<JobDefinitionInner> list(
        String resourceGroupName, String storageMoverName, String projectName, Context context) {
        return new PagedIterable<>(listAsync(resourceGroupName, storageMoverName, projectName, context));
    }

    /**
     * Gets a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a Job Definition resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JobDefinitionInner>> getWithResponseAsync(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            storageMoverName,
                            projectName,
                            jobDefinitionName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a Job Definition resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JobDefinitionInner>> getWithResponseAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                storageMoverName,
                projectName,
                jobDefinitionName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Gets a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a Job Definition resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<JobDefinitionInner> getAsync(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        return getWithResponseAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a Job Definition resource along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<JobDefinitionInner> getWithResponse(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        Context context) {
        return getWithResponseAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName, context)
            .block();
    }

    /**
     * Gets a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a Job Definition resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public JobDefinitionInner get(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        return getWithResponse(resourceGroupName, storageMoverName, projectName, jobDefinitionName, Context.NONE)
            .getValue();
    }

    /**
     * Creates or updates a Job Definition resource, which contains configuration for a single unit of managed data
     * transfer.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param jobDefinition The Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Job Definition resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JobDefinitionInner>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        JobDefinitionInner jobDefinition) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName is required and cannot be null."));
        }
        if (jobDefinition == null) {
            return Mono.error(new IllegalArgumentException("Parameter jobDefinition is required and cannot be null."));
        } else {
            jobDefinition.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            storageMoverName,
                            projectName,
                            jobDefinitionName,
                            this.client.getApiVersion(),
                            jobDefinition,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a Job Definition resource, which contains configuration for a single unit of managed data
     * transfer.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param jobDefinition The Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Job Definition resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JobDefinitionInner>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        JobDefinitionInner jobDefinition,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName is required and cannot be null."));
        }
        if (jobDefinition == null) {
            return Mono.error(new IllegalArgumentException("Parameter jobDefinition is required and cannot be null."));
        } else {
            jobDefinition.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                storageMoverName,
                projectName,
                jobDefinitionName,
                this.client.getApiVersion(),
                jobDefinition,
                accept,
                context);
    }

    /**
     * Creates or updates a Job Definition resource, which contains configuration for a single unit of managed data
     * transfer.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param jobDefinition The Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Job Definition resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<JobDefinitionInner> createOrUpdateAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        JobDefinitionInner jobDefinition) {
        return createOrUpdateWithResponseAsync(
                resourceGroupName, storageMoverName, projectName, jobDefinitionName, jobDefinition)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates or updates a Job Definition resource, which contains configuration for a single unit of managed data
     * transfer.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param jobDefinition The Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Job Definition resource along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<JobDefinitionInner> createOrUpdateWithResponse(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        JobDefinitionInner jobDefinition,
        Context context) {
        return createOrUpdateWithResponseAsync(
                resourceGroupName, storageMoverName, projectName, jobDefinitionName, jobDefinition, context)
            .block();
    }

    /**
     * Creates or updates a Job Definition resource, which contains configuration for a single unit of managed data
     * transfer.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param jobDefinition The Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Job Definition resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public JobDefinitionInner createOrUpdate(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        JobDefinitionInner jobDefinition) {
        return createOrUpdateWithResponse(
                resourceGroupName, storageMoverName, projectName, jobDefinitionName, jobDefinition, Context.NONE)
            .getValue();
    }

    /**
     * Updates properties for a Job Definition resource. Properties not specified in the request body will be unchanged.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param jobDefinition The Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Job Definition resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JobDefinitionInner>> updateWithResponseAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        JobDefinitionUpdateParameters jobDefinition) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName is required and cannot be null."));
        }
        if (jobDefinition == null) {
            return Mono.error(new IllegalArgumentException("Parameter jobDefinition is required and cannot be null."));
        } else {
            jobDefinition.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            storageMoverName,
                            projectName,
                            jobDefinitionName,
                            this.client.getApiVersion(),
                            jobDefinition,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Updates properties for a Job Definition resource. Properties not specified in the request body will be unchanged.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param jobDefinition The Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Job Definition resource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JobDefinitionInner>> updateWithResponseAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        JobDefinitionUpdateParameters jobDefinition,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName is required and cannot be null."));
        }
        if (jobDefinition == null) {
            return Mono.error(new IllegalArgumentException("Parameter jobDefinition is required and cannot be null."));
        } else {
            jobDefinition.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                storageMoverName,
                projectName,
                jobDefinitionName,
                this.client.getApiVersion(),
                jobDefinition,
                accept,
                context);
    }

    /**
     * Updates properties for a Job Definition resource. Properties not specified in the request body will be unchanged.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param jobDefinition The Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Job Definition resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<JobDefinitionInner> updateAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        JobDefinitionUpdateParameters jobDefinition) {
        return updateWithResponseAsync(
                resourceGroupName, storageMoverName, projectName, jobDefinitionName, jobDefinition)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Updates properties for a Job Definition resource. Properties not specified in the request body will be unchanged.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param jobDefinition The Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Job Definition resource along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<JobDefinitionInner> updateWithResponse(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        JobDefinitionUpdateParameters jobDefinition,
        Context context) {
        return updateWithResponseAsync(
                resourceGroupName, storageMoverName, projectName, jobDefinitionName, jobDefinition, context)
            .block();
    }

    /**
     * Updates properties for a Job Definition resource. Properties not specified in the request body will be unchanged.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param jobDefinition The Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Job Definition resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public JobDefinitionInner update(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        JobDefinitionUpdateParameters jobDefinition) {
        return updateWithResponse(
                resourceGroupName, storageMoverName, projectName, jobDefinitionName, jobDefinition, Context.NONE)
            .getValue();
    }

    /**
     * Deletes a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            storageMoverName,
                            projectName,
                            jobDefinitionName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName 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(),
                resourceGroupName,
                storageMoverName,
                projectName,
                jobDefinitionName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Deletes a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Deletes a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Deletes a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        return this
            .beginDeleteAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName)
            .getSyncPoller();
    }

    /**
     * Deletes a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        Context context) {
        return this
            .beginDeleteAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName, context)
            .getSyncPoller();
    }

    /**
     * Deletes a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        return beginDeleteAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        Context context) {
        return beginDeleteAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        deleteAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName).block();
    }

    /**
     * Deletes a Job Definition resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        Context context) {
        deleteAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName, context).block();
    }

    /**
     * Requests an Agent to start a new instance of this Job Definition, generating a new Job Run resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response that identifies a Job Run along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JobRunResourceIdInner>> startJobWithResponseAsync(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .startJob(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            storageMoverName,
                            projectName,
                            jobDefinitionName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Requests an Agent to start a new instance of this Job Definition, generating a new Job Run resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response that identifies a Job Run along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JobRunResourceIdInner>> startJobWithResponseAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .startJob(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                storageMoverName,
                projectName,
                jobDefinitionName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Requests an Agent to start a new instance of this Job Definition, generating a new Job Run resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response that identifies a Job Run on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<JobRunResourceIdInner> startJobAsync(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        return startJobWithResponseAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Requests an Agent to start a new instance of this Job Definition, generating a new Job Run resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response that identifies a Job Run along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<JobRunResourceIdInner> startJobWithResponse(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        Context context) {
        return startJobWithResponseAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName, context)
            .block();
    }

    /**
     * Requests an Agent to start a new instance of this Job Definition, generating a new Job Run resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response that identifies a Job Run.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public JobRunResourceIdInner startJob(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        return startJobWithResponse(resourceGroupName, storageMoverName, projectName, jobDefinitionName, Context.NONE)
            .getValue();
    }

    /**
     * Requests the Agent of any active instance of this Job Definition to stop.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response that identifies a Job Run along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JobRunResourceIdInner>> stopJobWithResponseAsync(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .stopJob(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            storageMoverName,
                            projectName,
                            jobDefinitionName,
                            this.client.getApiVersion(),
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Requests the Agent of any active instance of this Job Definition to stop.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response that identifies a Job Run along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<JobRunResourceIdInner>> stopJobWithResponseAsync(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (storageMoverName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter storageMoverName is required and cannot be null."));
        }
        if (projectName == null) {
            return Mono.error(new IllegalArgumentException("Parameter projectName is required and cannot be null."));
        }
        if (jobDefinitionName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter jobDefinitionName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .stopJob(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                storageMoverName,
                projectName,
                jobDefinitionName,
                this.client.getApiVersion(),
                accept,
                context);
    }

    /**
     * Requests the Agent of any active instance of this Job Definition to stop.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response that identifies a Job Run on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<JobRunResourceIdInner> stopJobAsync(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        return stopJobWithResponseAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Requests the Agent of any active instance of this Job Definition to stop.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response that identifies a Job Run along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<JobRunResourceIdInner> stopJobWithResponse(
        String resourceGroupName,
        String storageMoverName,
        String projectName,
        String jobDefinitionName,
        Context context) {
        return stopJobWithResponseAsync(resourceGroupName, storageMoverName, projectName, jobDefinitionName, context)
            .block();
    }

    /**
     * Requests the Agent of any active instance of this Job Definition to stop.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param storageMoverName The name of the Storage Mover resource.
     * @param projectName The name of the Project resource.
     * @param jobDefinitionName The name of the Job Definition resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response that identifies a Job Run.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public JobRunResourceIdInner stopJob(
        String resourceGroupName, String storageMoverName, String projectName, String jobDefinitionName) {
        return stopJobWithResponse(resourceGroupName, storageMoverName, projectName, jobDefinitionName, Context.NONE)
            .getValue();
    }

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

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of Job Definitions along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<JobDefinitionInner>> 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));
    }
}
