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

package com.azure.resourcemanager.automation.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.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.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.resourcemanager.automation.fluent.HybridRunbookWorkersClient;
import com.azure.resourcemanager.automation.fluent.models.HybridRunbookWorkerInner;
import com.azure.resourcemanager.automation.models.HybridRunbookWorkerCreateParameters;
import com.azure.resourcemanager.automation.models.HybridRunbookWorkerMoveParameters;
import com.azure.resourcemanager.automation.models.HybridRunbookWorkersListResult;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for AutomationClientHybridRunbookWorkers to be used by the proxy service
     * to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "AutomationClientHybr")
    private interface HybridRunbookWorkersService {
        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation"
                + "/automationAccounts/{automationAccountName}/hybridRunbookWorkerGroups/{hybridRunbookWorkerGroupName}"
                + "/hybridRunbookWorkers/{hybridRunbookWorkerId}")
        @ExpectedResponses({200, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> delete(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("automationAccountName") String automationAccountName,
            @PathParam("hybridRunbookWorkerGroupName") String hybridRunbookWorkerGroupName,
            @PathParam("hybridRunbookWorkerId") String hybridRunbookWorkerId,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation"
                + "/automationAccounts/{automationAccountName}/hybridRunbookWorkerGroups/{hybridRunbookWorkerGroupName}"
                + "/hybridRunbookWorkers/{hybridRunbookWorkerId}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<HybridRunbookWorkerInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("automationAccountName") String automationAccountName,
            @PathParam("hybridRunbookWorkerGroupName") String hybridRunbookWorkerGroupName,
            @PathParam("hybridRunbookWorkerId") String hybridRunbookWorkerId,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation"
                + "/automationAccounts/{automationAccountName}/hybridRunbookWorkerGroups/{hybridRunbookWorkerGroupName}"
                + "/hybridRunbookWorkers/{hybridRunbookWorkerId}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<HybridRunbookWorkerInner>> create(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("automationAccountName") String automationAccountName,
            @PathParam("hybridRunbookWorkerGroupName") String hybridRunbookWorkerGroupName,
            @PathParam("hybridRunbookWorkerId") String hybridRunbookWorkerId,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") HybridRunbookWorkerCreateParameters hybridRunbookWorkerCreationParameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation"
                + "/automationAccounts/{automationAccountName}/hybridRunbookWorkerGroups/{hybridRunbookWorkerGroupName}"
                + "/hybridRunbookWorkers/{hybridRunbookWorkerId}/move")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> move(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("automationAccountName") String automationAccountName,
            @PathParam("hybridRunbookWorkerGroupName") String hybridRunbookWorkerGroupName,
            @PathParam("hybridRunbookWorkerId") String hybridRunbookWorkerId,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") HybridRunbookWorkerMoveParameters hybridRunbookWorkerMoveParameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Automation"
                + "/automationAccounts/{automationAccountName}/hybridRunbookWorkerGroups/{hybridRunbookWorkerGroupName}"
                + "/hybridRunbookWorkers")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<HybridRunbookWorkersListResult>> listByHybridRunbookWorkerGroup(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("automationAccountName") String automationAccountName,
            @PathParam("hybridRunbookWorkerGroupName") String hybridRunbookWorkerGroupName,
            @QueryParam("$filter") String filter,
            @PathParam("subscriptionId") String subscriptionId,
            @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<HybridRunbookWorkersListResult>> listByHybridRunbookWorkerGroupNext(
            @PathParam(value = "nextLink", encoded = true) String nextLink,
            @HostParam("$host") String endpoint,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * Delete a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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<Void>> deleteWithResponseAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (automationAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter automationAccountName is required and cannot be null."));
        }
        if (hybridRunbookWorkerGroupName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerGroupName is required and cannot be null."));
        }
        if (hybridRunbookWorkerId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter hybridRunbookWorkerId is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String apiVersion = "2021-06-22";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            automationAccountName,
                            hybridRunbookWorkerGroupName,
                            hybridRunbookWorkerId,
                            this.client.getSubscriptionId(),
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @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<Void>> deleteWithResponseAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (automationAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter automationAccountName is required and cannot be null."));
        }
        if (hybridRunbookWorkerGroupName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerGroupName is required and cannot be null."));
        }
        if (hybridRunbookWorkerId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter hybridRunbookWorkerId is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String apiVersion = "2021-06-22";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                this.client.getSubscriptionId(),
                apiVersion,
                accept,
                context);
    }

    /**
     * Delete a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId) {
        return deleteWithResponseAsync(
                resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, hybridRunbookWorkerId)
            .flatMap(ignored -> Mono.empty());
    }

    /**
     * Delete a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId) {
        deleteAsync(resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, hybridRunbookWorkerId)
            .block();
    }

    /**
     * Delete a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @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}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        Context context) {
        return deleteWithResponseAsync(
                resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, hybridRunbookWorkerId, context)
            .block();
    }

    /**
     * Retrieve a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return definition of hybrid runbook worker along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HybridRunbookWorkerInner>> getWithResponseAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (automationAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter automationAccountName is required and cannot be null."));
        }
        if (hybridRunbookWorkerGroupName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerGroupName is required and cannot be null."));
        }
        if (hybridRunbookWorkerId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter hybridRunbookWorkerId is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String apiVersion = "2021-06-22";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            automationAccountName,
                            hybridRunbookWorkerGroupName,
                            hybridRunbookWorkerId,
                            this.client.getSubscriptionId(),
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Retrieve a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @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 definition of hybrid runbook worker along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HybridRunbookWorkerInner>> getWithResponseAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (automationAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter automationAccountName is required and cannot be null."));
        }
        if (hybridRunbookWorkerGroupName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerGroupName is required and cannot be null."));
        }
        if (hybridRunbookWorkerId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter hybridRunbookWorkerId is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String apiVersion = "2021-06-22";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                this.client.getSubscriptionId(),
                apiVersion,
                accept,
                context);
    }

    /**
     * Retrieve a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return definition of hybrid runbook worker on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<HybridRunbookWorkerInner> getAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId) {
        return getWithResponseAsync(
                resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, hybridRunbookWorkerId)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Retrieve a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return definition of hybrid runbook worker.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public HybridRunbookWorkerInner get(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId) {
        return getAsync(resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, hybridRunbookWorkerId)
            .block();
    }

    /**
     * Retrieve a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @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 definition of hybrid runbook worker along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<HybridRunbookWorkerInner> getWithResponse(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        Context context) {
        return getWithResponseAsync(
                resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, hybridRunbookWorkerId, context)
            .block();
    }

    /**
     * Create a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @param hybridRunbookWorkerCreationParameters The create or update parameters for hybrid runbook worker.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return definition of hybrid runbook worker along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HybridRunbookWorkerInner>> createWithResponseAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        HybridRunbookWorkerCreateParameters hybridRunbookWorkerCreationParameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (automationAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter automationAccountName is required and cannot be null."));
        }
        if (hybridRunbookWorkerGroupName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerGroupName is required and cannot be null."));
        }
        if (hybridRunbookWorkerId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter hybridRunbookWorkerId 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 (hybridRunbookWorkerCreationParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerCreationParameters is required and cannot be null."));
        } else {
            hybridRunbookWorkerCreationParameters.validate();
        }
        final String apiVersion = "2021-06-22";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .create(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            automationAccountName,
                            hybridRunbookWorkerGroupName,
                            hybridRunbookWorkerId,
                            this.client.getSubscriptionId(),
                            apiVersion,
                            hybridRunbookWorkerCreationParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @param hybridRunbookWorkerCreationParameters The create or update parameters for hybrid runbook worker.
     * @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 definition of hybrid runbook worker along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<HybridRunbookWorkerInner>> createWithResponseAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        HybridRunbookWorkerCreateParameters hybridRunbookWorkerCreationParameters,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (automationAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter automationAccountName is required and cannot be null."));
        }
        if (hybridRunbookWorkerGroupName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerGroupName is required and cannot be null."));
        }
        if (hybridRunbookWorkerId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter hybridRunbookWorkerId 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 (hybridRunbookWorkerCreationParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerCreationParameters is required and cannot be null."));
        } else {
            hybridRunbookWorkerCreationParameters.validate();
        }
        final String apiVersion = "2021-06-22";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .create(
                this.client.getEndpoint(),
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                this.client.getSubscriptionId(),
                apiVersion,
                hybridRunbookWorkerCreationParameters,
                accept,
                context);
    }

    /**
     * Create a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @param hybridRunbookWorkerCreationParameters The create or update parameters for hybrid runbook worker.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return definition of hybrid runbook worker on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<HybridRunbookWorkerInner> createAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        HybridRunbookWorkerCreateParameters hybridRunbookWorkerCreationParameters) {
        return createWithResponseAsync(
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                hybridRunbookWorkerCreationParameters)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Create a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @param hybridRunbookWorkerCreationParameters The create or update parameters for hybrid runbook worker.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return definition of hybrid runbook worker.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public HybridRunbookWorkerInner create(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        HybridRunbookWorkerCreateParameters hybridRunbookWorkerCreationParameters) {
        return createAsync(
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                hybridRunbookWorkerCreationParameters)
            .block();
    }

    /**
     * Create a hybrid runbook worker.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @param hybridRunbookWorkerCreationParameters The create or update parameters for hybrid runbook worker.
     * @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 definition of hybrid runbook worker along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<HybridRunbookWorkerInner> createWithResponse(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        HybridRunbookWorkerCreateParameters hybridRunbookWorkerCreationParameters,
        Context context) {
        return createWithResponseAsync(
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                hybridRunbookWorkerCreationParameters,
                context)
            .block();
    }

    /**
     * Move a hybrid worker to a different group.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @param hybridRunbookWorkerMoveParameters The hybrid runbook worker move parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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<Void>> moveWithResponseAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        HybridRunbookWorkerMoveParameters hybridRunbookWorkerMoveParameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (automationAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter automationAccountName is required and cannot be null."));
        }
        if (hybridRunbookWorkerGroupName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerGroupName is required and cannot be null."));
        }
        if (hybridRunbookWorkerId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter hybridRunbookWorkerId 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 (hybridRunbookWorkerMoveParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerMoveParameters is required and cannot be null."));
        } else {
            hybridRunbookWorkerMoveParameters.validate();
        }
        final String apiVersion = "2021-06-22";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .move(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            automationAccountName,
                            hybridRunbookWorkerGroupName,
                            hybridRunbookWorkerId,
                            this.client.getSubscriptionId(),
                            apiVersion,
                            hybridRunbookWorkerMoveParameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Move a hybrid worker to a different group.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @param hybridRunbookWorkerMoveParameters The hybrid runbook worker move parameters.
     * @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<Void>> moveWithResponseAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        HybridRunbookWorkerMoveParameters hybridRunbookWorkerMoveParameters,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (automationAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter automationAccountName is required and cannot be null."));
        }
        if (hybridRunbookWorkerGroupName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerGroupName is required and cannot be null."));
        }
        if (hybridRunbookWorkerId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter hybridRunbookWorkerId 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 (hybridRunbookWorkerMoveParameters == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerMoveParameters is required and cannot be null."));
        } else {
            hybridRunbookWorkerMoveParameters.validate();
        }
        final String apiVersion = "2021-06-22";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .move(
                this.client.getEndpoint(),
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                this.client.getSubscriptionId(),
                apiVersion,
                hybridRunbookWorkerMoveParameters,
                accept,
                context);
    }

    /**
     * Move a hybrid worker to a different group.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @param hybridRunbookWorkerMoveParameters The hybrid runbook worker move parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> moveAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        HybridRunbookWorkerMoveParameters hybridRunbookWorkerMoveParameters) {
        return moveWithResponseAsync(
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                hybridRunbookWorkerMoveParameters)
            .flatMap(ignored -> Mono.empty());
    }

    /**
     * Move a hybrid worker to a different group.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @param hybridRunbookWorkerMoveParameters The hybrid runbook worker move parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 move(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        HybridRunbookWorkerMoveParameters hybridRunbookWorkerMoveParameters) {
        moveAsync(
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                hybridRunbookWorkerMoveParameters)
            .block();
    }

    /**
     * Move a hybrid worker to a different group.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param hybridRunbookWorkerId The hybrid runbook worker id.
     * @param hybridRunbookWorkerMoveParameters The hybrid runbook worker move parameters.
     * @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}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> moveWithResponse(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String hybridRunbookWorkerId,
        HybridRunbookWorkerMoveParameters hybridRunbookWorkerMoveParameters,
        Context context) {
        return moveWithResponseAsync(
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                hybridRunbookWorkerId,
                hybridRunbookWorkerMoveParameters,
                context)
            .block();
    }

    /**
     * Retrieve a list of hybrid runbook workers.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param filter The filter to apply on the operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response model for the list hybrid runbook workers along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<HybridRunbookWorkerInner>> listByHybridRunbookWorkerGroupSinglePageAsync(
        String resourceGroupName, String automationAccountName, String hybridRunbookWorkerGroupName, String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (automationAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter automationAccountName is required and cannot be null."));
        }
        if (hybridRunbookWorkerGroupName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String apiVersion = "2021-06-22";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByHybridRunbookWorkerGroup(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            automationAccountName,
                            hybridRunbookWorkerGroupName,
                            filter,
                            this.client.getSubscriptionId(),
                            apiVersion,
                            accept,
                            context))
            .<PagedResponse<HybridRunbookWorkerInner>>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()));
    }

    /**
     * Retrieve a list of hybrid runbook workers.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param filter The filter to apply on the operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response model for the list hybrid runbook workers along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<HybridRunbookWorkerInner>> listByHybridRunbookWorkerGroupSinglePageAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String filter,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (automationAccountName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter automationAccountName is required and cannot be null."));
        }
        if (hybridRunbookWorkerGroupName == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter hybridRunbookWorkerGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String apiVersion = "2021-06-22";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByHybridRunbookWorkerGroup(
                this.client.getEndpoint(),
                resourceGroupName,
                automationAccountName,
                hybridRunbookWorkerGroupName,
                filter,
                this.client.getSubscriptionId(),
                apiVersion,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Retrieve a list of hybrid runbook workers.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param filter The filter to apply on the operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response model for the list hybrid runbook workers as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<HybridRunbookWorkerInner> listByHybridRunbookWorkerGroupAsync(
        String resourceGroupName, String automationAccountName, String hybridRunbookWorkerGroupName, String filter) {
        return new PagedFlux<>(
            () ->
                listByHybridRunbookWorkerGroupSinglePageAsync(
                    resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, filter),
            nextLink -> listByHybridRunbookWorkerGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Retrieve a list of hybrid runbook workers.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 model for the list hybrid runbook workers as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<HybridRunbookWorkerInner> listByHybridRunbookWorkerGroupAsync(
        String resourceGroupName, String automationAccountName, String hybridRunbookWorkerGroupName) {
        final String filter = null;
        return new PagedFlux<>(
            () ->
                listByHybridRunbookWorkerGroupSinglePageAsync(
                    resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, filter),
            nextLink -> listByHybridRunbookWorkerGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Retrieve a list of hybrid runbook workers.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param filter The filter to apply on the operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response model for the list hybrid runbook workers as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<HybridRunbookWorkerInner> listByHybridRunbookWorkerGroupAsync(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String filter,
        Context context) {
        return new PagedFlux<>(
            () ->
                listByHybridRunbookWorkerGroupSinglePageAsync(
                    resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, filter, context),
            nextLink -> listByHybridRunbookWorkerGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * Retrieve a list of hybrid runbook workers.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 model for the list hybrid runbook workers as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<HybridRunbookWorkerInner> listByHybridRunbookWorkerGroup(
        String resourceGroupName, String automationAccountName, String hybridRunbookWorkerGroupName) {
        final String filter = null;
        return new PagedIterable<>(
            listByHybridRunbookWorkerGroupAsync(
                resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, filter));
    }

    /**
     * Retrieve a list of hybrid runbook workers.
     *
     * @param resourceGroupName Name of an Azure Resource group.
     * @param automationAccountName The name of the automation account.
     * @param hybridRunbookWorkerGroupName The hybrid runbook worker group name.
     * @param filter The filter to apply on the operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response model for the list hybrid runbook workers as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<HybridRunbookWorkerInner> listByHybridRunbookWorkerGroup(
        String resourceGroupName,
        String automationAccountName,
        String hybridRunbookWorkerGroupName,
        String filter,
        Context context) {
        return new PagedIterable<>(
            listByHybridRunbookWorkerGroupAsync(
                resourceGroupName, automationAccountName, hybridRunbookWorkerGroupName, filter, context));
    }

    /**
     * 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 the response model for the list hybrid runbook workers along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<HybridRunbookWorkerInner>> listByHybridRunbookWorkerGroupNextSinglePageAsync(
        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.listByHybridRunbookWorkerGroupNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<HybridRunbookWorkerInner>>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 the response model for the list hybrid runbook workers along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<HybridRunbookWorkerInner>> listByHybridRunbookWorkerGroupNextSinglePageAsync(
        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
            .listByHybridRunbookWorkerGroupNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
