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

package com.azure.resourcemanager.policyinsights.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.policyinsights.fluent.RemediationsClient;
import com.azure.resourcemanager.policyinsights.fluent.models.RemediationDeploymentInner;
import com.azure.resourcemanager.policyinsights.fluent.models.RemediationInner;
import com.azure.resourcemanager.policyinsights.models.RemediationDeploymentsListResult;
import com.azure.resourcemanager.policyinsights.models.RemediationListResult;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for PolicyInsightsClientRemediations to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "PolicyInsightsClient")
    private interface RemediationsService {
        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers"
                + "/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationDeploymentsListResult>> listDeploymentsAtManagementGroup(
            @HostParam("$host") String endpoint,
            @PathParam("managementGroupsNamespace") String managementGroupsNamespace,
            @PathParam("managementGroupId") String managementGroupId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("$top") Integer top,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers"
                + "/Microsoft.PolicyInsights/remediations/{remediationName}/cancel")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> cancelAtManagementGroup(
            @HostParam("$host") String endpoint,
            @PathParam("managementGroupsNamespace") String managementGroupsNamespace,
            @PathParam("managementGroupId") String managementGroupId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers"
                + "/Microsoft.PolicyInsights/remediations")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationListResult>> listForManagementGroup(
            @HostParam("$host") String endpoint,
            @PathParam("managementGroupsNamespace") String managementGroupsNamespace,
            @PathParam("managementGroupId") String managementGroupId,
            @QueryParam("$top") Integer top,
            @QueryParam("$filter") String filter,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers"
                + "/Microsoft.PolicyInsights/remediations/{remediationName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> createOrUpdateAtManagementGroup(
            @HostParam("$host") String endpoint,
            @PathParam("managementGroupsNamespace") String managementGroupsNamespace,
            @PathParam("managementGroupId") String managementGroupId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") RemediationInner parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get(
            "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers"
                + "/Microsoft.PolicyInsights/remediations/{remediationName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> getAtManagementGroup(
            @HostParam("$host") String endpoint,
            @PathParam("managementGroupsNamespace") String managementGroupsNamespace,
            @PathParam("managementGroupId") String managementGroupId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/providers/{managementGroupsNamespace}/managementGroups/{managementGroupId}/providers"
                + "/Microsoft.PolicyInsights/remediations/{remediationName}")
        @ExpectedResponses({200, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> deleteAtManagementGroup(
            @HostParam("$host") String endpoint,
            @PathParam("managementGroupsNamespace") String managementGroupsNamespace,
            @PathParam("managementGroupId") String managementGroupId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}"
                + "/listDeployments")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationDeploymentsListResult>> listDeploymentsAtSubscription(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("$top") Integer top,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> cancelAtSubscription(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Put("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> createOrUpdateAtSubscription(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") RemediationInner parameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Delete("/subscriptions/{subscriptionId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}")
        @ExpectedResponses({200, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> deleteAtSubscription(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights"
                + "/remediations/{remediationName}/listDeployments")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationDeploymentsListResult>> listDeploymentsAtResourceGroup(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("remediationName") String remediationName,
            @QueryParam("$top") Integer top,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights"
                + "/remediations/{remediationName}/cancel")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> cancelAtResourceGroup(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.PolicyInsights"
                + "/remediations/{remediationName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> createOrUpdateAtResourceGroup(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") RemediationInner parameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

        @Headers({"Content-Type: application/json"})
        @Post("/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/listDeployments")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationDeploymentsListResult>> listDeploymentsAtResource(
            @HostParam("$host") String endpoint,
            @PathParam(value = "resourceId", encoded = true) String resourceId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("$top") Integer top,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}/cancel")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> cancelAtResource(
            @HostParam("$host") String endpoint,
            @PathParam(value = "resourceId", encoded = true) String resourceId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{resourceId}/providers/Microsoft.PolicyInsights/remediations")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationListResult>> listForResource(
            @HostParam("$host") String endpoint,
            @PathParam(value = "resourceId", encoded = true) String resourceId,
            @QueryParam("$top") Integer top,
            @QueryParam("$filter") String filter,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put("/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> createOrUpdateAtResource(
            @HostParam("$host") String endpoint,
            @PathParam(value = "resourceId", encoded = true) String resourceId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") RemediationInner parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> getAtResource(
            @HostParam("$host") String endpoint,
            @PathParam(value = "resourceId", encoded = true) String resourceId,
            @PathParam("remediationName") String remediationName,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete("/{resourceId}/providers/Microsoft.PolicyInsights/remediations/{remediationName}")
        @ExpectedResponses({200, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<RemediationInner>> deleteAtResource(
            @HostParam("$host") String endpoint,
            @PathParam(value = "resourceId", encoded = true) String resourceId,
            @PathParam("remediationName") String remediationName,
            @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<RemediationDeploymentsListResult>> listDeploymentsAtManagementGroupNext(
            @PathParam(value = "nextLink", encoded = true) String nextLink,
            @HostParam("$host") String endpoint,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

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

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

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

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

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

    /**
     * Gets all deployments for a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at management group scope along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationDeploymentInner>> listDeploymentsAtManagementGroupSinglePageAsync(
        String managementGroupId, String remediationName, Integer top) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listDeploymentsAtManagementGroup(
                            this.client.getEndpoint(),
                            managementGroupsNamespace,
                            managementGroupId,
                            remediationName,
                            top,
                            apiVersion,
                            accept,
                            context))
            .<PagedResponse<RemediationDeploymentInner>>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 all deployments for a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at management group scope along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationDeploymentInner>> listDeploymentsAtManagementGroupSinglePageAsync(
        String managementGroupId, String remediationName, Integer top, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listDeploymentsAtManagementGroup(
                this.client.getEndpoint(),
                managementGroupsNamespace,
                managementGroupId,
                remediationName,
                top,
                apiVersion,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Gets all deployments for a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at management group scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtManagementGroupAsync(
        String managementGroupId, String remediationName, Integer top) {
        return new PagedFlux<>(
            () -> listDeploymentsAtManagementGroupSinglePageAsync(managementGroupId, remediationName, top),
            nextLink -> listDeploymentsAtManagementGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all deployments for a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at management group scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtManagementGroupAsync(
        String managementGroupId, String remediationName) {
        final Integer top = null;
        return new PagedFlux<>(
            () -> listDeploymentsAtManagementGroupSinglePageAsync(managementGroupId, remediationName, top),
            nextLink -> listDeploymentsAtManagementGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all deployments for a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at management group scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtManagementGroupAsync(
        String managementGroupId, String remediationName, Integer top, Context context) {
        return new PagedFlux<>(
            () -> listDeploymentsAtManagementGroupSinglePageAsync(managementGroupId, remediationName, top, context),
            nextLink -> listDeploymentsAtManagementGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets all deployments for a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at management group scope as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationDeploymentInner> listDeploymentsAtManagementGroup(
        String managementGroupId, String remediationName) {
        final Integer top = null;
        return new PagedIterable<>(listDeploymentsAtManagementGroupAsync(managementGroupId, remediationName, top));
    }

    /**
     * Gets all deployments for a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at management group scope as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationDeploymentInner> listDeploymentsAtManagementGroup(
        String managementGroupId, String remediationName, Integer top, Context context) {
        return new PagedIterable<>(
            listDeploymentsAtManagementGroupAsync(managementGroupId, remediationName, top, context));
    }

    /**
     * Cancels a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> cancelAtManagementGroupWithResponseAsync(
        String managementGroupId, String remediationName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .cancelAtManagementGroup(
                            this.client.getEndpoint(),
                            managementGroupsNamespace,
                            managementGroupId,
                            remediationName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Cancels a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> cancelAtManagementGroupWithResponseAsync(
        String managementGroupId, String remediationName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .cancelAtManagementGroup(
                this.client.getEndpoint(),
                managementGroupsNamespace,
                managementGroupId,
                remediationName,
                apiVersion,
                accept,
                context);
    }

    /**
     * Cancels a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> cancelAtManagementGroupAsync(String managementGroupId, String remediationName) {
        return cancelAtManagementGroupWithResponseAsync(managementGroupId, remediationName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Cancels a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> cancelAtManagementGroupWithResponse(
        String managementGroupId, String remediationName, Context context) {
        return cancelAtManagementGroupWithResponseAsync(managementGroupId, remediationName, context).block();
    }

    /**
     * Cancels a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner cancelAtManagementGroup(String managementGroupId, String remediationName) {
        return cancelAtManagementGroupWithResponse(managementGroupId, remediationName, Context.NONE).getValue();
    }

    /**
     * Gets all remediations for the management group.
     *
     * @param managementGroupId Management group ID.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all remediations for the management group along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationInner>> listForManagementGroupSinglePageAsync(
        String managementGroupId, Integer top, String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listForManagementGroup(
                            this.client.getEndpoint(),
                            managementGroupsNamespace,
                            managementGroupId,
                            top,
                            filter,
                            apiVersion,
                            accept,
                            context))
            .<PagedResponse<RemediationInner>>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 all remediations for the management group.
     *
     * @param managementGroupId Management group ID.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for the management group along with {@link PagedResponse} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationInner>> listForManagementGroupSinglePageAsync(
        String managementGroupId, Integer top, 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 (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listForManagementGroup(
                this.client.getEndpoint(),
                managementGroupsNamespace,
                managementGroupId,
                top,
                filter,
                apiVersion,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Gets all remediations for the management group.
     *
     * @param managementGroupId Management group ID.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all remediations for the management group as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listForManagementGroupAsync(
        String managementGroupId, Integer top, String filter) {
        return new PagedFlux<>(
            () -> listForManagementGroupSinglePageAsync(managementGroupId, top, filter),
            nextLink -> listForManagementGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all remediations for the management group.
     *
     * @param managementGroupId Management group 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 all remediations for the management group as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listForManagementGroupAsync(String managementGroupId) {
        final Integer top = null;
        final String filter = null;
        return new PagedFlux<>(
            () -> listForManagementGroupSinglePageAsync(managementGroupId, top, filter),
            nextLink -> listForManagementGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all remediations for the management group.
     *
     * @param managementGroupId Management group ID.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for the management group as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listForManagementGroupAsync(
        String managementGroupId, Integer top, String filter, Context context) {
        return new PagedFlux<>(
            () -> listForManagementGroupSinglePageAsync(managementGroupId, top, filter, context),
            nextLink -> listForManagementGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets all remediations for the management group.
     *
     * @param managementGroupId Management group 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 all remediations for the management group as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationInner> listForManagementGroup(String managementGroupId) {
        final Integer top = null;
        final String filter = null;
        return new PagedIterable<>(listForManagementGroupAsync(managementGroupId, top, filter));
    }

    /**
     * Gets all remediations for the management group.
     *
     * @param managementGroupId Management group ID.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for the management group as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationInner> listForManagementGroup(
        String managementGroupId, Integer top, String filter, Context context) {
        return new PagedIterable<>(listForManagementGroupAsync(managementGroupId, top, filter, context));
    }

    /**
     * Creates or updates a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> createOrUpdateAtManagementGroupWithResponseAsync(
        String managementGroupId, String remediationName, RemediationInner parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdateAtManagementGroup(
                            this.client.getEndpoint(),
                            managementGroupsNamespace,
                            managementGroupId,
                            remediationName,
                            apiVersion,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> createOrUpdateAtManagementGroupWithResponseAsync(
        String managementGroupId, String remediationName, RemediationInner parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdateAtManagementGroup(
                this.client.getEndpoint(),
                managementGroupsNamespace,
                managementGroupId,
                remediationName,
                apiVersion,
                parameters,
                accept,
                context);
    }

    /**
     * Creates or updates a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> createOrUpdateAtManagementGroupAsync(
        String managementGroupId, String remediationName, RemediationInner parameters) {
        return createOrUpdateAtManagementGroupWithResponseAsync(managementGroupId, remediationName, parameters)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates or updates a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> createOrUpdateAtManagementGroupWithResponse(
        String managementGroupId, String remediationName, RemediationInner parameters, Context context) {
        return createOrUpdateAtManagementGroupWithResponseAsync(managementGroupId, remediationName, parameters, context)
            .block();
    }

    /**
     * Creates or updates a remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner createOrUpdateAtManagementGroup(
        String managementGroupId, String remediationName, RemediationInner parameters) {
        return createOrUpdateAtManagementGroupWithResponse(managementGroupId, remediationName, parameters, Context.NONE)
            .getValue();
    }

    /**
     * Gets an existing remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at management group scope along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> getAtManagementGroupWithResponseAsync(
        String managementGroupId, String remediationName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getAtManagementGroup(
                            this.client.getEndpoint(),
                            managementGroupsNamespace,
                            managementGroupId,
                            remediationName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets an existing remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @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 an existing remediation at management group scope along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> getAtManagementGroupWithResponseAsync(
        String managementGroupId, String remediationName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getAtManagementGroup(
                this.client.getEndpoint(),
                managementGroupsNamespace,
                managementGroupId,
                remediationName,
                apiVersion,
                accept,
                context);
    }

    /**
     * Gets an existing remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at management group scope on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> getAtManagementGroupAsync(String managementGroupId, String remediationName) {
        return getAtManagementGroupWithResponseAsync(managementGroupId, remediationName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets an existing remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @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 an existing remediation at management group scope along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> getAtManagementGroupWithResponse(
        String managementGroupId, String remediationName, Context context) {
        return getAtManagementGroupWithResponseAsync(managementGroupId, remediationName, context).block();
    }

    /**
     * Gets an existing remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at management group scope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner getAtManagementGroup(String managementGroupId, String remediationName) {
        return getAtManagementGroupWithResponse(managementGroupId, remediationName, Context.NONE).getValue();
    }

    /**
     * Deletes an existing remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> deleteAtManagementGroupWithResponseAsync(
        String managementGroupId, String remediationName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .deleteAtManagementGroup(
                            this.client.getEndpoint(),
                            managementGroupsNamespace,
                            managementGroupId,
                            remediationName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes an existing remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> deleteAtManagementGroupWithResponseAsync(
        String managementGroupId, String remediationName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (managementGroupId == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter managementGroupId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String managementGroupsNamespace = "Microsoft.Management";
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .deleteAtManagementGroup(
                this.client.getEndpoint(),
                managementGroupsNamespace,
                managementGroupId,
                remediationName,
                apiVersion,
                accept,
                context);
    }

    /**
     * Deletes an existing remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> deleteAtManagementGroupAsync(String managementGroupId, String remediationName) {
        return deleteAtManagementGroupWithResponseAsync(managementGroupId, remediationName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Deletes an existing remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> deleteAtManagementGroupWithResponse(
        String managementGroupId, String remediationName, Context context) {
        return deleteAtManagementGroupWithResponseAsync(managementGroupId, remediationName, context).block();
    }

    /**
     * Deletes an existing remediation at management group scope.
     *
     * @param managementGroupId Management group ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner deleteAtManagementGroup(String managementGroupId, String remediationName) {
        return deleteAtManagementGroupWithResponse(managementGroupId, remediationName, Context.NONE).getValue();
    }

    /**
     * Gets all deployments for a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at subscription scope along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationDeploymentInner>> listDeploymentsAtSubscriptionSinglePageAsync(
        String remediationName, Integer top) {
        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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listDeploymentsAtSubscription(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            remediationName,
                            top,
                            apiVersion,
                            accept,
                            context))
            .<PagedResponse<RemediationDeploymentInner>>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 all deployments for a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at subscription scope along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationDeploymentInner>> listDeploymentsAtSubscriptionSinglePageAsync(
        String remediationName, Integer top, 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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listDeploymentsAtSubscription(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                remediationName,
                top,
                apiVersion,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Gets all deployments for a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at subscription scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtSubscriptionAsync(
        String remediationName, Integer top) {
        return new PagedFlux<>(
            () -> listDeploymentsAtSubscriptionSinglePageAsync(remediationName, top),
            nextLink -> listDeploymentsAtSubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all deployments for a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at subscription scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtSubscriptionAsync(String remediationName) {
        final Integer top = null;
        return new PagedFlux<>(
            () -> listDeploymentsAtSubscriptionSinglePageAsync(remediationName, top),
            nextLink -> listDeploymentsAtSubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all deployments for a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at subscription scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtSubscriptionAsync(
        String remediationName, Integer top, Context context) {
        return new PagedFlux<>(
            () -> listDeploymentsAtSubscriptionSinglePageAsync(remediationName, top, context),
            nextLink -> listDeploymentsAtSubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets all deployments for a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at subscription scope as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationDeploymentInner> listDeploymentsAtSubscription(String remediationName) {
        final Integer top = null;
        return new PagedIterable<>(listDeploymentsAtSubscriptionAsync(remediationName, top));
    }

    /**
     * Gets all deployments for a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at subscription scope as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationDeploymentInner> listDeploymentsAtSubscription(
        String remediationName, Integer top, Context context) {
        return new PagedIterable<>(listDeploymentsAtSubscriptionAsync(remediationName, top, context));
    }

    /**
     * Cancels a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> cancelAtSubscriptionWithResponseAsync(String remediationName) {
        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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .cancelAtSubscription(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            remediationName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Cancels a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> cancelAtSubscriptionWithResponseAsync(
        String remediationName, 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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .cancelAtSubscription(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                remediationName,
                apiVersion,
                accept,
                context);
    }

    /**
     * Cancels a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> cancelAtSubscriptionAsync(String remediationName) {
        return cancelAtSubscriptionWithResponseAsync(remediationName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Cancels a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> cancelAtSubscriptionWithResponse(String remediationName, Context context) {
        return cancelAtSubscriptionWithResponseAsync(remediationName, context).block();
    }

    /**
     * Cancels a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner cancelAtSubscription(String remediationName) {
        return cancelAtSubscriptionWithResponse(remediationName, Context.NONE).getValue();
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all remediations for the subscription along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationInner>> listSinglePageAsync(Integer top, String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            top,
                            filter,
                            apiVersion,
                            accept,
                            context))
            .<PagedResponse<RemediationInner>>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 all remediations for the subscription.
     *
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for the subscription along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationInner>> listSinglePageAsync(Integer top, 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 (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(this.client.getEndpoint(), this.client.getSubscriptionId(), top, filter, apiVersion, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all remediations for the subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listAsync(Integer top, String filter) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(top, filter), nextLink -> listForSubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all remediations for the subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listAsync() {
        final Integer top = null;
        final String filter = null;
        return new PagedFlux<>(
            () -> listSinglePageAsync(top, filter), nextLink -> listForSubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for the subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listAsync(Integer top, String filter, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(top, filter, context),
            nextLink -> listForSubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all remediations for the subscription as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationInner> list() {
        final Integer top = null;
        final String filter = null;
        return new PagedIterable<>(listAsync(top, filter));
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for the subscription as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationInner> list(Integer top, String filter, Context context) {
        return new PagedIterable<>(listAsync(top, filter, context));
    }

    /**
     * Creates or updates a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> createOrUpdateAtSubscriptionWithResponseAsync(
        String remediationName, RemediationInner parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdateAtSubscription(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            remediationName,
                            apiVersion,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> createOrUpdateAtSubscriptionWithResponseAsync(
        String remediationName, RemediationInner parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdateAtSubscription(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                remediationName,
                apiVersion,
                parameters,
                accept,
                context);
    }

    /**
     * Creates or updates a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> createOrUpdateAtSubscriptionAsync(
        String remediationName, RemediationInner parameters) {
        return createOrUpdateAtSubscriptionWithResponseAsync(remediationName, parameters)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates or updates a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> createOrUpdateAtSubscriptionWithResponse(
        String remediationName, RemediationInner parameters, Context context) {
        return createOrUpdateAtSubscriptionWithResponseAsync(remediationName, parameters, context).block();
    }

    /**
     * Creates or updates a remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner createOrUpdateAtSubscription(String remediationName, RemediationInner parameters) {
        return createOrUpdateAtSubscriptionWithResponse(remediationName, parameters, Context.NONE).getValue();
    }

    /**
     * Gets an existing remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at subscription scope along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> getAtSubscriptionWithResponseAsync(String remediationName) {
        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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getAtSubscription(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            remediationName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets an existing remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @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 an existing remediation at subscription scope along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> getAtSubscriptionWithResponseAsync(
        String remediationName, 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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getAtSubscription(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                remediationName,
                apiVersion,
                accept,
                context);
    }

    /**
     * Gets an existing remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at subscription scope on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> getAtSubscriptionAsync(String remediationName) {
        return getAtSubscriptionWithResponseAsync(remediationName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets an existing remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @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 an existing remediation at subscription scope along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> getAtSubscriptionWithResponse(String remediationName, Context context) {
        return getAtSubscriptionWithResponseAsync(remediationName, context).block();
    }

    /**
     * Gets an existing remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at subscription scope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner getAtSubscription(String remediationName) {
        return getAtSubscriptionWithResponse(remediationName, Context.NONE).getValue();
    }

    /**
     * Deletes an existing remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> deleteAtSubscriptionWithResponseAsync(String remediationName) {
        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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .deleteAtSubscription(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            remediationName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes an existing remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> deleteAtSubscriptionWithResponseAsync(
        String remediationName, 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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .deleteAtSubscription(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                remediationName,
                apiVersion,
                accept,
                context);
    }

    /**
     * Deletes an existing remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> deleteAtSubscriptionAsync(String remediationName) {
        return deleteAtSubscriptionWithResponseAsync(remediationName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Deletes an existing remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> deleteAtSubscriptionWithResponse(String remediationName, Context context) {
        return deleteAtSubscriptionWithResponseAsync(remediationName, context).block();
    }

    /**
     * Deletes an existing remediation at subscription scope.
     *
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner deleteAtSubscription(String remediationName) {
        return deleteAtSubscriptionWithResponse(remediationName, Context.NONE).getValue();
    }

    /**
     * Gets all deployments for a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at resource group scope along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationDeploymentInner>> listDeploymentsAtResourceGroupSinglePageAsync(
        String resourceGroupName, String remediationName, Integer top) {
        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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listDeploymentsAtResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            remediationName,
                            top,
                            apiVersion,
                            accept,
                            context))
            .<PagedResponse<RemediationDeploymentInner>>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 all deployments for a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at resource group scope along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationDeploymentInner>> listDeploymentsAtResourceGroupSinglePageAsync(
        String resourceGroupName, String remediationName, Integer top, 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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listDeploymentsAtResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                remediationName,
                top,
                apiVersion,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Gets all deployments for a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at resource group scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtResourceGroupAsync(
        String resourceGroupName, String remediationName, Integer top) {
        return new PagedFlux<>(
            () -> listDeploymentsAtResourceGroupSinglePageAsync(resourceGroupName, remediationName, top),
            nextLink -> listDeploymentsAtResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all deployments for a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at resource group scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtResourceGroupAsync(
        String resourceGroupName, String remediationName) {
        final Integer top = null;
        return new PagedFlux<>(
            () -> listDeploymentsAtResourceGroupSinglePageAsync(resourceGroupName, remediationName, top),
            nextLink -> listDeploymentsAtResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all deployments for a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at resource group scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtResourceGroupAsync(
        String resourceGroupName, String remediationName, Integer top, Context context) {
        return new PagedFlux<>(
            () -> listDeploymentsAtResourceGroupSinglePageAsync(resourceGroupName, remediationName, top, context),
            nextLink -> listDeploymentsAtResourceGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets all deployments for a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at resource group scope as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationDeploymentInner> listDeploymentsAtResourceGroup(
        String resourceGroupName, String remediationName) {
        final Integer top = null;
        return new PagedIterable<>(listDeploymentsAtResourceGroupAsync(resourceGroupName, remediationName, top));
    }

    /**
     * Gets all deployments for a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at resource group scope as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationDeploymentInner> listDeploymentsAtResourceGroup(
        String resourceGroupName, String remediationName, Integer top, Context context) {
        return new PagedIterable<>(
            listDeploymentsAtResourceGroupAsync(resourceGroupName, remediationName, top, context));
    }

    /**
     * Cancels a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> cancelAtResourceGroupWithResponseAsync(
        String resourceGroupName, String remediationName) {
        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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .cancelAtResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            remediationName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Cancels a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> cancelAtResourceGroupWithResponseAsync(
        String resourceGroupName, String remediationName, 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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .cancelAtResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                remediationName,
                apiVersion,
                accept,
                context);
    }

    /**
     * Cancels a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> cancelAtResourceGroupAsync(String resourceGroupName, String remediationName) {
        return cancelAtResourceGroupWithResponseAsync(resourceGroupName, remediationName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Cancels a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> cancelAtResourceGroupWithResponse(
        String resourceGroupName, String remediationName, Context context) {
        return cancelAtResourceGroupWithResponseAsync(resourceGroupName, remediationName, context).block();
    }

    /**
     * Cancels a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner cancelAtResourceGroup(String resourceGroupName, String remediationName) {
        return cancelAtResourceGroupWithResponse(resourceGroupName, remediationName, Context.NONE).getValue();
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all remediations for the subscription along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, Integer top, String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            top,
                            filter,
                            apiVersion,
                            accept,
                            context))
            .<PagedResponse<RemediationInner>>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 all remediations for the subscription.
     *
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for the subscription along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, Integer top, 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 (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                top,
                filter,
                apiVersion,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all remediations for the subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listByResourceGroupAsync(String resourceGroupName, Integer top, String filter) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, top, filter),
            nextLink -> listForResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @param resourceGroupName Resource 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 all remediations for the subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listByResourceGroupAsync(String resourceGroupName) {
        final Integer top = null;
        final String filter = null;
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, top, filter),
            nextLink -> listForResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for the subscription as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listByResourceGroupAsync(
        String resourceGroupName, Integer top, String filter, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, top, filter, context),
            nextLink -> listForResourceGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @param resourceGroupName Resource 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 all remediations for the subscription as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationInner> listByResourceGroup(String resourceGroupName) {
        final Integer top = null;
        final String filter = null;
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, top, filter));
    }

    /**
     * Gets all remediations for the subscription.
     *
     * @param resourceGroupName Resource group name.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for the subscription as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationInner> listByResourceGroup(
        String resourceGroupName, Integer top, String filter, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, top, filter, context));
    }

    /**
     * Creates or updates a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> createOrUpdateAtResourceGroupWithResponseAsync(
        String resourceGroupName, String remediationName, RemediationInner parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdateAtResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            remediationName,
                            apiVersion,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> createOrUpdateAtResourceGroupWithResponseAsync(
        String resourceGroupName, String remediationName, RemediationInner parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdateAtResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                remediationName,
                apiVersion,
                parameters,
                accept,
                context);
    }

    /**
     * Creates or updates a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> createOrUpdateAtResourceGroupAsync(
        String resourceGroupName, String remediationName, RemediationInner parameters) {
        return createOrUpdateAtResourceGroupWithResponseAsync(resourceGroupName, remediationName, parameters)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates or updates a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> createOrUpdateAtResourceGroupWithResponse(
        String resourceGroupName, String remediationName, RemediationInner parameters, Context context) {
        return createOrUpdateAtResourceGroupWithResponseAsync(resourceGroupName, remediationName, parameters, context)
            .block();
    }

    /**
     * Creates or updates a remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner createOrUpdateAtResourceGroup(
        String resourceGroupName, String remediationName, RemediationInner parameters) {
        return createOrUpdateAtResourceGroupWithResponse(resourceGroupName, remediationName, parameters, Context.NONE)
            .getValue();
    }

    /**
     * Gets an existing remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at resource group scope along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String remediationName) {
        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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            remediationName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets an existing remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @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 an existing remediation at resource group scope along with {@link Response} on successful completion of
     *     {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String remediationName, 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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getByResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                remediationName,
                apiVersion,
                accept,
                context);
    }

    /**
     * Gets an existing remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at resource group scope on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> getByResourceGroupAsync(String resourceGroupName, String remediationName) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, remediationName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets an existing remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @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 an existing remediation at resource group scope along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> getByResourceGroupWithResponse(
        String resourceGroupName, String remediationName, Context context) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, remediationName, context).block();
    }

    /**
     * Gets an existing remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at resource group scope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner getByResourceGroup(String resourceGroupName, String remediationName) {
        return getByResourceGroupWithResponse(resourceGroupName, remediationName, Context.NONE).getValue();
    }

    /**
     * Deletes an existing remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> deleteWithResponseAsync(String resourceGroupName, String remediationName) {
        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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            remediationName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes an existing remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> deleteWithResponseAsync(
        String resourceGroupName, String remediationName, 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 (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                remediationName,
                apiVersion,
                accept,
                context);
    }

    /**
     * Deletes an existing remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> deleteAsync(String resourceGroupName, String remediationName) {
        return deleteWithResponseAsync(resourceGroupName, remediationName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Deletes an existing remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> deleteWithResponse(
        String resourceGroupName, String remediationName, Context context) {
        return deleteWithResponseAsync(resourceGroupName, remediationName, context).block();
    }

    /**
     * Deletes an existing remediation at resource group scope.
     *
     * @param resourceGroupName Resource group name.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner delete(String resourceGroupName, String remediationName) {
        return deleteWithResponse(resourceGroupName, remediationName, Context.NONE).getValue();
    }

    /**
     * Gets all deployments for a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at resource scope along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationDeploymentInner>> listDeploymentsAtResourceSinglePageAsync(
        String resourceId, String remediationName, Integer top) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listDeploymentsAtResource(
                            this.client.getEndpoint(), resourceId, remediationName, top, apiVersion, accept, context))
            .<PagedResponse<RemediationDeploymentInner>>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 all deployments for a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at resource scope along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationDeploymentInner>> listDeploymentsAtResourceSinglePageAsync(
        String resourceId, String remediationName, Integer top, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listDeploymentsAtResource(
                this.client.getEndpoint(), resourceId, remediationName, top, apiVersion, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Gets all deployments for a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at resource scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtResourceAsync(
        String resourceId, String remediationName, Integer top) {
        return new PagedFlux<>(
            () -> listDeploymentsAtResourceSinglePageAsync(resourceId, remediationName, top),
            nextLink -> listDeploymentsAtResourceNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all deployments for a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at resource scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtResourceAsync(
        String resourceId, String remediationName) {
        final Integer top = null;
        return new PagedFlux<>(
            () -> listDeploymentsAtResourceSinglePageAsync(resourceId, remediationName, top),
            nextLink -> listDeploymentsAtResourceNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all deployments for a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at resource scope as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationDeploymentInner> listDeploymentsAtResourceAsync(
        String resourceId, String remediationName, Integer top, Context context) {
        return new PagedFlux<>(
            () -> listDeploymentsAtResourceSinglePageAsync(resourceId, remediationName, top, context),
            nextLink -> listDeploymentsAtResourceNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets all deployments for a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all deployments for a remediation at resource scope as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationDeploymentInner> listDeploymentsAtResource(
        String resourceId, String remediationName) {
        final Integer top = null;
        return new PagedIterable<>(listDeploymentsAtResourceAsync(resourceId, remediationName, top));
    }

    /**
     * Gets all deployments for a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @param top Maximum number of records to return.
     * @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 all deployments for a remediation at resource scope as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationDeploymentInner> listDeploymentsAtResource(
        String resourceId, String remediationName, Integer top, Context context) {
        return new PagedIterable<>(listDeploymentsAtResourceAsync(resourceId, remediationName, top, context));
    }

    /**
     * Cancel a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> cancelAtResourceWithResponseAsync(
        String resourceId, String remediationName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .cancelAtResource(
                            this.client.getEndpoint(), resourceId, remediationName, apiVersion, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Cancel a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> cancelAtResourceWithResponseAsync(
        String resourceId, String remediationName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .cancelAtResource(this.client.getEndpoint(), resourceId, remediationName, apiVersion, accept, context);
    }

    /**
     * Cancel a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> cancelAtResourceAsync(String resourceId, String remediationName) {
        return cancelAtResourceWithResponseAsync(resourceId, remediationName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Cancel a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> cancelAtResourceWithResponse(
        String resourceId, String remediationName, Context context) {
        return cancelAtResourceWithResponseAsync(resourceId, remediationName, context).block();
    }

    /**
     * Cancel a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner cancelAtResource(String resourceId, String remediationName) {
        return cancelAtResourceWithResponse(resourceId, remediationName, Context.NONE).getValue();
    }

    /**
     * Gets all remediations for a resource.
     *
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all remediations for a resource along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationInner>> listForResourceSinglePageAsync(
        String resourceId, Integer top, String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listForResource(
                            this.client.getEndpoint(), resourceId, top, filter, apiVersion, accept, context))
            .<PagedResponse<RemediationInner>>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 all remediations for a resource.
     *
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for a resource along with {@link PagedResponse} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<RemediationInner>> listForResourceSinglePageAsync(
        String resourceId, Integer top, 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 (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listForResource(this.client.getEndpoint(), resourceId, top, filter, apiVersion, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Gets all remediations for a resource.
     *
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return all remediations for a resource as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listForResourceAsync(String resourceId, Integer top, String filter) {
        return new PagedFlux<>(
            () -> listForResourceSinglePageAsync(resourceId, top, filter),
            nextLink -> listForResourceNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all remediations for a resource.
     *
     * @param resourceId Resource 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 all remediations for a resource as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listForResourceAsync(String resourceId) {
        final Integer top = null;
        final String filter = null;
        return new PagedFlux<>(
            () -> listForResourceSinglePageAsync(resourceId, top, filter),
            nextLink -> listForResourceNextSinglePageAsync(nextLink));
    }

    /**
     * Gets all remediations for a resource.
     *
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for a resource as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<RemediationInner> listForResourceAsync(
        String resourceId, Integer top, String filter, Context context) {
        return new PagedFlux<>(
            () -> listForResourceSinglePageAsync(resourceId, top, filter, context),
            nextLink -> listForResourceNextSinglePageAsync(nextLink, context));
    }

    /**
     * Gets all remediations for a resource.
     *
     * @param resourceId Resource 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 all remediations for a resource as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationInner> listForResource(String resourceId) {
        final Integer top = null;
        final String filter = null;
        return new PagedIterable<>(listForResourceAsync(resourceId, top, filter));
    }

    /**
     * Gets all remediations for a resource.
     *
     * @param resourceId Resource ID.
     * @param top Maximum number of records to return.
     * @param filter OData filter expression.
     * @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 all remediations for a resource as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<RemediationInner> listForResource(
        String resourceId, Integer top, String filter, Context context) {
        return new PagedIterable<>(listForResourceAsync(resourceId, top, filter, context));
    }

    /**
     * Creates or updates a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> createOrUpdateAtResourceWithResponseAsync(
        String resourceId, String remediationName, RemediationInner parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdateAtResource(
                            this.client.getEndpoint(),
                            resourceId,
                            remediationName,
                            apiVersion,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> createOrUpdateAtResourceWithResponseAsync(
        String resourceId, String remediationName, RemediationInner parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdateAtResource(
                this.client.getEndpoint(), resourceId, remediationName, apiVersion, parameters, accept, context);
    }

    /**
     * Creates or updates a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> createOrUpdateAtResourceAsync(
        String resourceId, String remediationName, RemediationInner parameters) {
        return createOrUpdateAtResourceWithResponseAsync(resourceId, remediationName, parameters)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Creates or updates a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> createOrUpdateAtResourceWithResponse(
        String resourceId, String remediationName, RemediationInner parameters, Context context) {
        return createOrUpdateAtResourceWithResponseAsync(resourceId, remediationName, parameters, context).block();
    }

    /**
     * Creates or updates a remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @param parameters The remediation 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner createOrUpdateAtResource(
        String resourceId, String remediationName, RemediationInner parameters) {
        return createOrUpdateAtResourceWithResponse(resourceId, remediationName, parameters, Context.NONE).getValue();
    }

    /**
     * Gets an existing remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at resource scope along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> getAtResourceWithResponseAsync(String resourceId, String remediationName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getAtResource(
                            this.client.getEndpoint(), resourceId, remediationName, apiVersion, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets an existing remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @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 an existing remediation at resource scope along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> getAtResourceWithResponseAsync(
        String resourceId, String remediationName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getAtResource(this.client.getEndpoint(), resourceId, remediationName, apiVersion, accept, context);
    }

    /**
     * Gets an existing remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at resource scope on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> getAtResourceAsync(String resourceId, String remediationName) {
        return getAtResourceWithResponseAsync(resourceId, remediationName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets an existing remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @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 an existing remediation at resource scope along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> getAtResourceWithResponse(
        String resourceId, String remediationName, Context context) {
        return getAtResourceWithResponseAsync(resourceId, remediationName, context).block();
    }

    /**
     * Gets an existing remediation at resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return an existing remediation at resource scope.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner getAtResource(String resourceId, String remediationName) {
        return getAtResourceWithResponse(resourceId, remediationName, Context.NONE).getValue();
    }

    /**
     * Deletes an existing remediation at individual resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> deleteAtResourceWithResponseAsync(
        String resourceId, String remediationName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .deleteAtResource(
                            this.client.getEndpoint(), resourceId, remediationName, apiVersion, accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes an existing remediation at individual resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<RemediationInner>> deleteAtResourceWithResponseAsync(
        String resourceId, String remediationName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceId == null) {
            return Mono.error(new IllegalArgumentException("Parameter resourceId is required and cannot be null."));
        }
        if (remediationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter remediationName is required and cannot be null."));
        }
        final String apiVersion = "2021-10-01";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .deleteAtResource(this.client.getEndpoint(), resourceId, remediationName, apiVersion, accept, context);
    }

    /**
     * Deletes an existing remediation at individual resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<RemediationInner> deleteAtResourceAsync(String resourceId, String remediationName) {
        return deleteAtResourceWithResponseAsync(resourceId, remediationName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Deletes an existing remediation at individual resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @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 remediation definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<RemediationInner> deleteAtResourceWithResponse(
        String resourceId, String remediationName, Context context) {
        return deleteAtResourceWithResponseAsync(resourceId, remediationName, context).block();
    }

    /**
     * Deletes an existing remediation at individual resource scope.
     *
     * @param resourceId Resource ID.
     * @param remediationName The name of the remediation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 remediation definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public RemediationInner deleteAtResource(String resourceId, String remediationName) {
        return deleteAtResourceWithResponse(resourceId, remediationName, Context.NONE).getValue();
    }

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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