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

package com.azure.resourcemanager.alertsmanagement.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.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.RestProxy;
import com.azure.core.management.exception.ManagementException;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.resourcemanager.alertsmanagement.fluent.AlertProcessingRulesClient;
import com.azure.resourcemanager.alertsmanagement.fluent.models.AlertProcessingRuleInner;
import com.azure.resourcemanager.alertsmanagement.models.AlertProcessingRulesCreateOrUpdateResponse;
import com.azure.resourcemanager.alertsmanagement.models.AlertProcessingRulesDeleteResponse;
import com.azure.resourcemanager.alertsmanagement.models.AlertProcessingRulesGetByResourceGroupResponse;
import com.azure.resourcemanager.alertsmanagement.models.AlertProcessingRulesListByResourceGroupNextResponse;
import com.azure.resourcemanager.alertsmanagement.models.AlertProcessingRulesListByResourceGroupResponse;
import com.azure.resourcemanager.alertsmanagement.models.AlertProcessingRulesListBySubscriptionNextResponse;
import com.azure.resourcemanager.alertsmanagement.models.AlertProcessingRulesListResponse;
import com.azure.resourcemanager.alertsmanagement.models.AlertProcessingRulesUpdateResponse;
import com.azure.resourcemanager.alertsmanagement.models.PatchObject;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for AlertsManagementClientAlertProcessingRules to be used by the proxy
     * service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "AlertsManagementClie")
    private interface AlertProcessingRulesService {
        @Headers({"Content-Type: application/json"})
        @Get("/subscriptions/{subscriptionId}/providers/Microsoft.AlertsManagement/actionRules")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<AlertProcessingRulesListResponse> list(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement"
                + "/actionRules/{alertProcessingRuleName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<AlertProcessingRulesCreateOrUpdateResponse> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("alertProcessingRuleName") String alertProcessingRuleName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") AlertProcessingRuleInner alertProcessingRule,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.AlertsManagement"
                + "/actionRules/{alertProcessingRuleName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<AlertProcessingRulesUpdateResponse> update(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("alertProcessingRuleName") String alertProcessingRuleName,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") PatchObject alertProcessingRulePatch,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * List all alert processing rules in a subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of alert processing rules along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AlertProcessingRuleInner>> listSinglePageAsync() {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String apiVersion = "2021-08-08";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(this.client.getEndpoint(), this.client.getSubscriptionId(), apiVersion, accept, context))
            .<PagedResponse<AlertProcessingRuleInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        res.getDeserializedHeaders()))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List all alert processing rules in a subscription.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of alert processing rules along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AlertProcessingRuleInner>> listSinglePageAsync(Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String apiVersion = "2021-08-08";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(this.client.getEndpoint(), this.client.getSubscriptionId(), apiVersion, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        res.getDeserializedHeaders()));
    }

    /**
     * List all alert processing rules in a subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of alert processing rules as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<AlertProcessingRuleInner> listAsync() {
        return new PagedFlux<>(
            () -> listSinglePageAsync(), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * List all alert processing rules in a subscription.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of alert processing rules as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<AlertProcessingRuleInner> listAsync(Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(context), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * List all alert processing rules in a subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of alert processing rules as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<AlertProcessingRuleInner> list() {
        return new PagedIterable<>(listAsync());
    }

    /**
     * List all alert processing rules in a subscription.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return list of alert processing rules as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<AlertProcessingRuleInner> list(Context context) {
        return new PagedIterable<>(listAsync(context));
    }

    /**
     * List all alert processing rules in a resource group.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 alert processing rules along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AlertProcessingRuleInner>> listByResourceGroupSinglePageAsync(String resourceGroupName) {
        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-08-08";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            apiVersion,
                            accept,
                            context))
            .<PagedResponse<AlertProcessingRuleInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        res.getDeserializedHeaders()))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List all alert processing rules in a resource group.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @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 alert processing rules along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AlertProcessingRuleInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, 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-08-08";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                apiVersion,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        res.getDeserializedHeaders()));
    }

    /**
     * List all alert processing rules in a resource group.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 alert processing rules as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<AlertProcessingRuleInner> listByResourceGroupAsync(String resourceGroupName) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink));
    }

    /**
     * List all alert processing rules in a resource group.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @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 alert processing rules as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<AlertProcessingRuleInner> listByResourceGroupAsync(String resourceGroupName, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, context),
            nextLink -> listByResourceGroupNextSinglePageAsync(nextLink, context));
    }

    /**
     * List all alert processing rules in a resource group.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 alert processing rules as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<AlertProcessingRuleInner> listByResourceGroup(String resourceGroupName) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName));
    }

    /**
     * List all alert processing rules in a resource group.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @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 alert processing rules as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<AlertProcessingRuleInner> listByResourceGroup(String resourceGroupName, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, context));
    }

    /**
     * Get an alert processing rule by name.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be fetched.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 alert processing rule by name on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AlertProcessingRulesGetByResourceGroupResponse> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String alertProcessingRuleName) {
        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 (alertProcessingRuleName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter alertProcessingRuleName is required and cannot be null."));
        }
        final String apiVersion = "2021-08-08";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getByResourceGroup(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            alertProcessingRuleName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get an alert processing rule by name.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be fetched.
     * @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 alert processing rule by name on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AlertProcessingRulesGetByResourceGroupResponse> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String alertProcessingRuleName, 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 (alertProcessingRuleName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter alertProcessingRuleName is required and cannot be null."));
        }
        final String apiVersion = "2021-08-08";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getByResourceGroup(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                alertProcessingRuleName,
                apiVersion,
                accept,
                context);
    }

    /**
     * Get an alert processing rule by name.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be fetched.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 alert processing rule by name on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AlertProcessingRuleInner> getByResourceGroupAsync(
        String resourceGroupName, String alertProcessingRuleName) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, alertProcessingRuleName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get an alert processing rule by name.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be fetched.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 alert processing rule by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AlertProcessingRuleInner getByResourceGroup(String resourceGroupName, String alertProcessingRuleName) {
        return getByResourceGroupAsync(resourceGroupName, alertProcessingRuleName).block();
    }

    /**
     * Get an alert processing rule by name.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be fetched.
     * @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 alert processing rule by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AlertProcessingRulesGetByResourceGroupResponse getByResourceGroupWithResponse(
        String resourceGroupName, String alertProcessingRuleName, Context context) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, alertProcessingRuleName, context).block();
    }

    /**
     * Create or update an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be created/updated.
     * @param alertProcessingRule Alert processing rule to be created/updated.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return alert processing rule object containing target scopes, conditions and scheduling logic on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AlertProcessingRulesCreateOrUpdateResponse> createOrUpdateWithResponseAsync(
        String resourceGroupName, String alertProcessingRuleName, AlertProcessingRuleInner alertProcessingRule) {
        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 (alertProcessingRuleName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter alertProcessingRuleName is required and cannot be null."));
        }
        if (alertProcessingRule == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter alertProcessingRule is required and cannot be null."));
        } else {
            alertProcessingRule.validate();
        }
        final String apiVersion = "2021-08-08";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            alertProcessingRuleName,
                            apiVersion,
                            alertProcessingRule,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create or update an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be created/updated.
     * @param alertProcessingRule Alert processing rule to be created/updated.
     * @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 alert processing rule object containing target scopes, conditions and scheduling logic on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AlertProcessingRulesCreateOrUpdateResponse> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String alertProcessingRuleName,
        AlertProcessingRuleInner alertProcessingRule,
        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 (alertProcessingRuleName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter alertProcessingRuleName is required and cannot be null."));
        }
        if (alertProcessingRule == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter alertProcessingRule is required and cannot be null."));
        } else {
            alertProcessingRule.validate();
        }
        final String apiVersion = "2021-08-08";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                alertProcessingRuleName,
                apiVersion,
                alertProcessingRule,
                accept,
                context);
    }

    /**
     * Create or update an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be created/updated.
     * @param alertProcessingRule Alert processing rule to be created/updated.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return alert processing rule object containing target scopes, conditions and scheduling logic on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AlertProcessingRuleInner> createOrUpdateAsync(
        String resourceGroupName, String alertProcessingRuleName, AlertProcessingRuleInner alertProcessingRule) {
        return createOrUpdateWithResponseAsync(resourceGroupName, alertProcessingRuleName, alertProcessingRule)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Create or update an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be created/updated.
     * @param alertProcessingRule Alert processing rule to be created/updated.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return alert processing rule object containing target scopes, conditions and scheduling logic.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AlertProcessingRuleInner createOrUpdate(
        String resourceGroupName, String alertProcessingRuleName, AlertProcessingRuleInner alertProcessingRule) {
        return createOrUpdateAsync(resourceGroupName, alertProcessingRuleName, alertProcessingRule).block();
    }

    /**
     * Create or update an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be created/updated.
     * @param alertProcessingRule Alert processing rule to be created/updated.
     * @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 alert processing rule object containing target scopes, conditions and scheduling logic.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AlertProcessingRulesCreateOrUpdateResponse createOrUpdateWithResponse(
        String resourceGroupName,
        String alertProcessingRuleName,
        AlertProcessingRuleInner alertProcessingRule,
        Context context) {
        return createOrUpdateWithResponseAsync(resourceGroupName, alertProcessingRuleName, alertProcessingRule, context)
            .block();
    }

    /**
     * Delete an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be deleted.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AlertProcessingRulesDeleteResponse> deleteWithResponseAsync(
        String resourceGroupName, String alertProcessingRuleName) {
        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 (alertProcessingRuleName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter alertProcessingRuleName is required and cannot be null."));
        }
        final String apiVersion = "2021-08-08";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            alertProcessingRuleName,
                            apiVersion,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be deleted.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AlertProcessingRulesDeleteResponse> deleteWithResponseAsync(
        String resourceGroupName, String alertProcessingRuleName, 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 (alertProcessingRuleName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter alertProcessingRuleName is required and cannot be null."));
        }
        final String apiVersion = "2021-08-08";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                alertProcessingRuleName,
                apiVersion,
                accept,
                context);
    }

    /**
     * Delete an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be deleted.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String alertProcessingRuleName) {
        return deleteWithResponseAsync(resourceGroupName, alertProcessingRuleName).flatMap(ignored -> Mono.empty());
    }

    /**
     * Delete an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be deleted.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String alertProcessingRuleName) {
        deleteAsync(resourceGroupName, alertProcessingRuleName).block();
    }

    /**
     * Delete an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name of the alert processing rule that needs to be deleted.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AlertProcessingRulesDeleteResponse deleteWithResponse(
        String resourceGroupName, String alertProcessingRuleName, Context context) {
        return deleteWithResponseAsync(resourceGroupName, alertProcessingRuleName, context).block();
    }

    /**
     * Enable, disable, or update tags for an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name that needs to be updated.
     * @param alertProcessingRulePatch Parameters supplied to the operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return alert processing rule object containing target scopes, conditions and scheduling logic on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AlertProcessingRulesUpdateResponse> updateWithResponseAsync(
        String resourceGroupName, String alertProcessingRuleName, PatchObject alertProcessingRulePatch) {
        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 (alertProcessingRuleName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter alertProcessingRuleName is required and cannot be null."));
        }
        if (alertProcessingRulePatch == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter alertProcessingRulePatch is required and cannot be null."));
        } else {
            alertProcessingRulePatch.validate();
        }
        final String apiVersion = "2021-08-08";
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            alertProcessingRuleName,
                            apiVersion,
                            alertProcessingRulePatch,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Enable, disable, or update tags for an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name that needs to be updated.
     * @param alertProcessingRulePatch Parameters supplied to the operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return alert processing rule object containing target scopes, conditions and scheduling logic on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AlertProcessingRulesUpdateResponse> updateWithResponseAsync(
        String resourceGroupName,
        String alertProcessingRuleName,
        PatchObject alertProcessingRulePatch,
        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 (alertProcessingRuleName == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter alertProcessingRuleName is required and cannot be null."));
        }
        if (alertProcessingRulePatch == null) {
            return Mono
                .error(
                    new IllegalArgumentException("Parameter alertProcessingRulePatch is required and cannot be null."));
        } else {
            alertProcessingRulePatch.validate();
        }
        final String apiVersion = "2021-08-08";
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                alertProcessingRuleName,
                apiVersion,
                alertProcessingRulePatch,
                accept,
                context);
    }

    /**
     * Enable, disable, or update tags for an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name that needs to be updated.
     * @param alertProcessingRulePatch Parameters supplied to the operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return alert processing rule object containing target scopes, conditions and scheduling logic on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AlertProcessingRuleInner> updateAsync(
        String resourceGroupName, String alertProcessingRuleName, PatchObject alertProcessingRulePatch) {
        return updateWithResponseAsync(resourceGroupName, alertProcessingRuleName, alertProcessingRulePatch)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Enable, disable, or update tags for an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name that needs to be updated.
     * @param alertProcessingRulePatch Parameters supplied to the operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return alert processing rule object containing target scopes, conditions and scheduling logic.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AlertProcessingRuleInner update(
        String resourceGroupName, String alertProcessingRuleName, PatchObject alertProcessingRulePatch) {
        return updateAsync(resourceGroupName, alertProcessingRuleName, alertProcessingRulePatch).block();
    }

    /**
     * Enable, disable, or update tags for an alert processing rule.
     *
     * @param resourceGroupName Resource group name where the resource is created.
     * @param alertProcessingRuleName The name that needs to be updated.
     * @param alertProcessingRulePatch Parameters supplied to the operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return alert processing rule object containing target scopes, conditions and scheduling logic.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AlertProcessingRulesUpdateResponse updateWithResponse(
        String resourceGroupName,
        String alertProcessingRuleName,
        PatchObject alertProcessingRulePatch,
        Context context) {
        return updateWithResponseAsync(resourceGroupName, alertProcessingRuleName, alertProcessingRulePatch, context)
            .block();
    }

    /**
     * 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 alert processing rules along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AlertProcessingRuleInner>> listBySubscriptionNextSinglePageAsync(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.listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<AlertProcessingRuleInner>>map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        res.getDeserializedHeaders()))
            .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 alert processing rules along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<AlertProcessingRuleInner>> listBySubscriptionNextSinglePageAsync(
        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
            .listBySubscriptionNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        res.getDeserializedHeaders()));
    }

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