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

package com.azure.resourcemanager.machinelearningservices.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.PathParam;
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.logging.ClientLogger;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.machinelearningservices.fluent.MachineLearningServicesClient;
import com.azure.resourcemanager.machinelearningservices.fluent.models.ServiceResourceInner;
import com.azure.resourcemanager.machinelearningservices.models.CreateServiceRequest;
import com.azure.resourcemanager.machinelearningservices.models.OrderString;
import com.azure.resourcemanager.machinelearningservices.models.PaginatedServiceList;
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 MachineLearningServicesClient. */
public final class MachineLearningServicesClientImpl implements MachineLearningServicesClient {
    private final ClientLogger logger = new ClientLogger(MachineLearningServicesClientImpl.class);

    /** The proxy service used to perform REST calls. */
    private final MachineLearningServicesService service;

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

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

    /**
     * The interface defining all the services for AzureMachineLearningWorkspacesMachineLearningServices to be used by
     * the proxy service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "AzureMachineLearning")
    private interface MachineLearningServicesService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers"
                + "/Microsoft.MachineLearningServices/workspaces/{workspaceName}/services")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PaginatedServiceList>> listByWorkspace(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("workspaceName") String workspaceName,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$skip") String skip,
            @QueryParam("modelId") String modelId,
            @QueryParam("modelName") String modelName,
            @QueryParam("tag") String tag,
            @QueryParam("tags") String tags,
            @QueryParam("properties") String properties,
            @QueryParam("runId") String runId,
            @QueryParam("expand") Boolean expand,
            @QueryParam("orderby") OrderString orderby,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

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

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

    /**
     * Gets services in specified workspace.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param skip Continuation token for pagination.
     * @param modelId The Model Id.
     * @param modelName The Model name.
     * @param tag The object tag.
     * @param tags A set of tags with which to filter the returned services. It is a comma separated string of tags key
     *     or tags key=value Example: tagKey1,tagKey2,tagKey3=value3 .
     * @param properties A set of properties with which to filter the returned services. It is a comma separated string
     *     of properties key and/or properties key=value Example: propKey1,propKey2,propKey3=value3 .
     * @param runId runId for model associated with service.
     * @param expand Set to True to include Model details.
     * @param orderby The option to order the response.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return services in specified workspace.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ServiceResourceInner>> listByWorkspaceSinglePageAsync(
        String resourceGroupName,
        String workspaceName,
        String skip,
        String modelId,
        String modelName,
        String tag,
        String tags,
        String properties,
        String runId,
        Boolean expand,
        OrderString orderby) {
        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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByWorkspace(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            workspaceName,
                            this.client.getApiVersion(),
                            skip,
                            modelId,
                            modelName,
                            tag,
                            tags,
                            properties,
                            runId,
                            expand,
                            orderby,
                            accept,
                            context))
            .<PagedResponse<ServiceResourceInner>>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()));
    }

    /**
     * Gets services in specified workspace.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param skip Continuation token for pagination.
     * @param modelId The Model Id.
     * @param modelName The Model name.
     * @param tag The object tag.
     * @param tags A set of tags with which to filter the returned services. It is a comma separated string of tags key
     *     or tags key=value Example: tagKey1,tagKey2,tagKey3=value3 .
     * @param properties A set of properties with which to filter the returned services. It is a comma separated string
     *     of properties key and/or properties key=value Example: propKey1,propKey2,propKey3=value3 .
     * @param runId runId for model associated with service.
     * @param expand Set to True to include Model details.
     * @param orderby The option to order the response.
     * @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 services in specified workspace.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ServiceResourceInner>> listByWorkspaceSinglePageAsync(
        String resourceGroupName,
        String workspaceName,
        String skip,
        String modelId,
        String modelName,
        String tag,
        String tags,
        String properties,
        String runId,
        Boolean expand,
        OrderString orderby,
        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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByWorkspace(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                workspaceName,
                this.client.getApiVersion(),
                skip,
                modelId,
                modelName,
                tag,
                tags,
                properties,
                runId,
                expand,
                orderby,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Gets services in specified workspace.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param skip Continuation token for pagination.
     * @param modelId The Model Id.
     * @param modelName The Model name.
     * @param tag The object tag.
     * @param tags A set of tags with which to filter the returned services. It is a comma separated string of tags key
     *     or tags key=value Example: tagKey1,tagKey2,tagKey3=value3 .
     * @param properties A set of properties with which to filter the returned services. It is a comma separated string
     *     of properties key and/or properties key=value Example: propKey1,propKey2,propKey3=value3 .
     * @param runId runId for model associated with service.
     * @param expand Set to True to include Model details.
     * @param orderby The option to order the response.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return services in specified workspace.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ServiceResourceInner> listByWorkspaceAsync(
        String resourceGroupName,
        String workspaceName,
        String skip,
        String modelId,
        String modelName,
        String tag,
        String tags,
        String properties,
        String runId,
        Boolean expand,
        OrderString orderby) {
        return new PagedFlux<>(
            () ->
                listByWorkspaceSinglePageAsync(
                    resourceGroupName,
                    workspaceName,
                    skip,
                    modelId,
                    modelName,
                    tag,
                    tags,
                    properties,
                    runId,
                    expand,
                    orderby),
            nextLink -> listByWorkspaceNextSinglePageAsync(nextLink));
    }

    /**
     * Gets services in specified workspace.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return services in specified workspace.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ServiceResourceInner> listByWorkspaceAsync(String resourceGroupName, String workspaceName) {
        final String skip = null;
        final String modelId = null;
        final String modelName = null;
        final String tag = null;
        final String tags = null;
        final String properties = null;
        final String runId = null;
        final Boolean expand = null;
        final OrderString orderby = null;
        return new PagedFlux<>(
            () ->
                listByWorkspaceSinglePageAsync(
                    resourceGroupName,
                    workspaceName,
                    skip,
                    modelId,
                    modelName,
                    tag,
                    tags,
                    properties,
                    runId,
                    expand,
                    orderby),
            nextLink -> listByWorkspaceNextSinglePageAsync(nextLink));
    }

    /**
     * Gets services in specified workspace.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param skip Continuation token for pagination.
     * @param modelId The Model Id.
     * @param modelName The Model name.
     * @param tag The object tag.
     * @param tags A set of tags with which to filter the returned services. It is a comma separated string of tags key
     *     or tags key=value Example: tagKey1,tagKey2,tagKey3=value3 .
     * @param properties A set of properties with which to filter the returned services. It is a comma separated string
     *     of properties key and/or properties key=value Example: propKey1,propKey2,propKey3=value3 .
     * @param runId runId for model associated with service.
     * @param expand Set to True to include Model details.
     * @param orderby The option to order the response.
     * @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 services in specified workspace.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ServiceResourceInner> listByWorkspaceAsync(
        String resourceGroupName,
        String workspaceName,
        String skip,
        String modelId,
        String modelName,
        String tag,
        String tags,
        String properties,
        String runId,
        Boolean expand,
        OrderString orderby,
        Context context) {
        return new PagedFlux<>(
            () ->
                listByWorkspaceSinglePageAsync(
                    resourceGroupName,
                    workspaceName,
                    skip,
                    modelId,
                    modelName,
                    tag,
                    tags,
                    properties,
                    runId,
                    expand,
                    orderby,
                    context),
            nextLink -> listByWorkspaceNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets services in specified workspace.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return services in specified workspace.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ServiceResourceInner> listByWorkspace(String resourceGroupName, String workspaceName) {
        final String skip = null;
        final String modelId = null;
        final String modelName = null;
        final String tag = null;
        final String tags = null;
        final String properties = null;
        final String runId = null;
        final Boolean expand = null;
        final OrderString orderby = null;
        return new PagedIterable<>(
            listByWorkspaceAsync(
                resourceGroupName,
                workspaceName,
                skip,
                modelId,
                modelName,
                tag,
                tags,
                properties,
                runId,
                expand,
                orderby));
    }

    /**
     * Gets services in specified workspace.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param skip Continuation token for pagination.
     * @param modelId The Model Id.
     * @param modelName The Model name.
     * @param tag The object tag.
     * @param tags A set of tags with which to filter the returned services. It is a comma separated string of tags key
     *     or tags key=value Example: tagKey1,tagKey2,tagKey3=value3 .
     * @param properties A set of properties with which to filter the returned services. It is a comma separated string
     *     of properties key and/or properties key=value Example: propKey1,propKey2,propKey3=value3 .
     * @param runId runId for model associated with service.
     * @param expand Set to True to include Model details.
     * @param orderby The option to order the response.
     * @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 services in specified workspace.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ServiceResourceInner> listByWorkspace(
        String resourceGroupName,
        String workspaceName,
        String skip,
        String modelId,
        String modelName,
        String tag,
        String tags,
        String properties,
        String runId,
        Boolean expand,
        OrderString orderby,
        Context context) {
        return new PagedIterable<>(
            listByWorkspaceAsync(
                resourceGroupName,
                workspaceName,
                skip,
                modelId,
                modelName,
                tag,
                tags,
                properties,
                runId,
                expand,
                orderby,
                context));
    }

    /**
     * Get a Service by name.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param expand Set to True to include Model details.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Service by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ServiceResourceInner>> getWithResponseAsync(
        String resourceGroupName, String workspaceName, String serviceName, Boolean expand) {
        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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName 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
                        .get(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            workspaceName,
                            this.client.getApiVersion(),
                            serviceName,
                            expand,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get a Service by name.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param expand Set to True to include Model details.
     * @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 Service by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ServiceResourceInner>> getWithResponseAsync(
        String resourceGroupName, String workspaceName, String serviceName, Boolean expand, 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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName 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
            .get(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                workspaceName,
                this.client.getApiVersion(),
                serviceName,
                expand,
                accept,
                context);
    }

    /**
     * Get a Service by name.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param expand Set to True to include Model details.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Service by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ServiceResourceInner> getAsync(
        String resourceGroupName, String workspaceName, String serviceName, Boolean expand) {
        return getWithResponseAsync(resourceGroupName, workspaceName, serviceName, expand)
            .flatMap(
                (Response<ServiceResourceInner> res) -> {
                    if (res.getValue() != null) {
                        return Mono.just(res.getValue());
                    } else {
                        return Mono.empty();
                    }
                });
    }

    /**
     * Get a Service by name.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning 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 Service by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ServiceResourceInner> getAsync(String resourceGroupName, String workspaceName, String serviceName) {
        final Boolean expand = null;
        return getWithResponseAsync(resourceGroupName, workspaceName, serviceName, expand)
            .flatMap(
                (Response<ServiceResourceInner> res) -> {
                    if (res.getValue() != null) {
                        return Mono.just(res.getValue());
                    } else {
                        return Mono.empty();
                    }
                });
    }

    /**
     * Get a Service by name.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning 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 Service by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ServiceResourceInner get(String resourceGroupName, String workspaceName, String serviceName) {
        final Boolean expand = null;
        return getAsync(resourceGroupName, workspaceName, serviceName, expand).block();
    }

    /**
     * Get a Service by name.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param expand Set to True to include Model details.
     * @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 Service by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ServiceResourceInner> getWithResponse(
        String resourceGroupName, String workspaceName, String serviceName, Boolean expand, Context context) {
        return getWithResponseAsync(resourceGroupName, workspaceName, serviceName, expand, context).block();
    }

    /**
     * Delete a specific Service..
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning 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 completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(
        String resourceGroupName, String workspaceName, 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 (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName 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(),
                            resourceGroupName,
                            workspaceName,
                            this.client.getApiVersion(),
                            serviceName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a specific Service..
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning 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 completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(
        String resourceGroupName, String workspaceName, 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 (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName 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(),
                resourceGroupName,
                workspaceName,
                this.client.getApiVersion(),
                serviceName,
                accept,
                context);
    }

    /**
     * Delete a specific Service..
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning 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 completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String workspaceName, String serviceName) {
        return deleteWithResponseAsync(resourceGroupName, workspaceName, serviceName)
            .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * Delete a specific Service..
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning 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 resourceGroupName, String workspaceName, String serviceName) {
        deleteAsync(resourceGroupName, workspaceName, serviceName).block();
    }

    /**
     * Delete a specific Service..
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning 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 response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(
        String resourceGroupName, String workspaceName, String serviceName, Context context) {
        return deleteWithResponseAsync(resourceGroupName, workspaceName, serviceName, context).block();
    }

    /**
     * Creates or updates service. This call will update a service if it exists. This is a nonrecoverable operation. If
     * your intent is to create a new service, do a GET first to verify that it does not exist yet.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param properties The payload that is used to create or update 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 machine Learning service object wrapped into ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String workspaceName, String serviceName, CreateServiceRequest properties) {
        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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        if (properties == null) {
            return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null."));
        } else {
            properties.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            workspaceName,
                            this.client.getApiVersion(),
                            serviceName,
                            properties,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates service. This call will update a service if it exists. This is a nonrecoverable operation. If
     * your intent is to create a new service, do a GET first to verify that it does not exist yet.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param properties The payload that is used to create or update 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 machine Learning service object wrapped into ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String workspaceName,
        String serviceName,
        CreateServiceRequest properties,
        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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName is required and cannot be null."));
        }
        if (serviceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter serviceName is required and cannot be null."));
        }
        if (properties == null) {
            return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null."));
        } else {
            properties.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                workspaceName,
                this.client.getApiVersion(),
                serviceName,
                properties,
                accept,
                context);
    }

    /**
     * Creates or updates service. This call will update a service if it exists. This is a nonrecoverable operation. If
     * your intent is to create a new service, do a GET first to verify that it does not exist yet.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param properties The payload that is used to create or update 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 machine Learning service object wrapped into ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private PollerFlux<PollResult<ServiceResourceInner>, ServiceResourceInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String workspaceName, String serviceName, CreateServiceRequest properties) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, workspaceName, serviceName, properties);
        return this
            .client
            .<ServiceResourceInner, ServiceResourceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ServiceResourceInner.class,
                ServiceResourceInner.class,
                Context.NONE);
    }

    /**
     * Creates or updates service. This call will update a service if it exists. This is a nonrecoverable operation. If
     * your intent is to create a new service, do a GET first to verify that it does not exist yet.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param properties The payload that is used to create or update 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 machine Learning service object wrapped into ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private PollerFlux<PollResult<ServiceResourceInner>, ServiceResourceInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String workspaceName,
        String serviceName,
        CreateServiceRequest properties,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, workspaceName, serviceName, properties, context);
        return this
            .client
            .<ServiceResourceInner, ServiceResourceInner>getLroResult(
                mono, this.client.getHttpPipeline(), ServiceResourceInner.class, ServiceResourceInner.class, context);
    }

    /**
     * Creates or updates service. This call will update a service if it exists. This is a nonrecoverable operation. If
     * your intent is to create a new service, do a GET first to verify that it does not exist yet.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param properties The payload that is used to create or update 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 machine Learning service object wrapped into ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SyncPoller<PollResult<ServiceResourceInner>, ServiceResourceInner> beginCreateOrUpdate(
        String resourceGroupName, String workspaceName, String serviceName, CreateServiceRequest properties) {
        return beginCreateOrUpdateAsync(resourceGroupName, workspaceName, serviceName, properties).getSyncPoller();
    }

    /**
     * Creates or updates service. This call will update a service if it exists. This is a nonrecoverable operation. If
     * your intent is to create a new service, do a GET first to verify that it does not exist yet.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param properties The payload that is used to create or update 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 machine Learning service object wrapped into ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SyncPoller<PollResult<ServiceResourceInner>, ServiceResourceInner> beginCreateOrUpdate(
        String resourceGroupName,
        String workspaceName,
        String serviceName,
        CreateServiceRequest properties,
        Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, workspaceName, serviceName, properties, context)
            .getSyncPoller();
    }

    /**
     * Creates or updates service. This call will update a service if it exists. This is a nonrecoverable operation. If
     * your intent is to create a new service, do a GET first to verify that it does not exist yet.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param properties The payload that is used to create or update 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 machine Learning service object wrapped into ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ServiceResourceInner> createOrUpdateAsync(
        String resourceGroupName, String workspaceName, String serviceName, CreateServiceRequest properties) {
        return beginCreateOrUpdateAsync(resourceGroupName, workspaceName, serviceName, properties)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates service. This call will update a service if it exists. This is a nonrecoverable operation. If
     * your intent is to create a new service, do a GET first to verify that it does not exist yet.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param properties The payload that is used to create or update 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 machine Learning service object wrapped into ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ServiceResourceInner> createOrUpdateAsync(
        String resourceGroupName,
        String workspaceName,
        String serviceName,
        CreateServiceRequest properties,
        Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, workspaceName, serviceName, properties, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates service. This call will update a service if it exists. This is a nonrecoverable operation. If
     * your intent is to create a new service, do a GET first to verify that it does not exist yet.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param properties The payload that is used to create or update 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 machine Learning service object wrapped into ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ServiceResourceInner createOrUpdate(
        String resourceGroupName, String workspaceName, String serviceName, CreateServiceRequest properties) {
        return createOrUpdateAsync(resourceGroupName, workspaceName, serviceName, properties).block();
    }

    /**
     * Creates or updates service. This call will update a service if it exists. This is a nonrecoverable operation. If
     * your intent is to create a new service, do a GET first to verify that it does not exist yet.
     *
     * @param resourceGroupName Name of the resource group in which workspace is located.
     * @param workspaceName Name of Azure Machine Learning workspace.
     * @param serviceName Name of the Azure Machine Learning service.
     * @param properties The payload that is used to create or update 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 machine Learning service object wrapped into ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ServiceResourceInner createOrUpdate(
        String resourceGroupName,
        String workspaceName,
        String serviceName,
        CreateServiceRequest properties,
        Context context) {
        return createOrUpdateAsync(resourceGroupName, workspaceName, serviceName, properties, context).block();
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink 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 paginated list of Machine Learning service objects wrapped in ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ServiceResourceInner>> listByWorkspaceNextSinglePageAsync(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.listByWorkspaceNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ServiceResourceInner>>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 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 paginated list of Machine Learning service objects wrapped in ARM resource envelope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ServiceResourceInner>> listByWorkspaceNextSinglePageAsync(
        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
            .listByWorkspaceNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
