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

package com.azure.resourcemanager.costmanagement.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.costmanagement.fluent.ScheduledActionsClient;
import com.azure.resourcemanager.costmanagement.fluent.models.CheckNameAvailabilityResponseInner;
import com.azure.resourcemanager.costmanagement.fluent.models.ScheduledActionInner;
import com.azure.resourcemanager.costmanagement.models.CheckNameAvailabilityRequest;
import com.azure.resourcemanager.costmanagement.models.ScheduledActionListResult;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for CostManagementClientScheduledActions to be used by the proxy service
     * to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "CostManagementClient")
    public interface ScheduledActionsService {
        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.CostManagement/scheduledActions")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ScheduledActionListResult>> list(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$filter") String filter,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{scope}/providers/Microsoft.CostManagement/scheduledActions")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ScheduledActionListResult>> listByScope(
            @HostParam("$host") String endpoint,
            @PathParam("scope") String scope,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$filter") String filter,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put("/providers/Microsoft.CostManagement/scheduledActions/{name}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ScheduledActionInner>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("name") String name,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("If-Match") String ifMatch,
            @BodyParam("application/json") ScheduledActionInner scheduledAction,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/providers/Microsoft.CostManagement/scheduledActions/{name}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ScheduledActionInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("name") String name,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete("/providers/Microsoft.CostManagement/scheduledActions/{name}")
        @ExpectedResponses({200, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> delete(
            @HostParam("$host") String endpoint,
            @PathParam("name") String name,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put("/{scope}/providers/Microsoft.CostManagement/scheduledActions/{name}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ScheduledActionInner>> createOrUpdateByScope(
            @HostParam("$host") String endpoint,
            @PathParam("scope") String scope,
            @PathParam("name") String name,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("If-Match") String ifMatch,
            @BodyParam("application/json") ScheduledActionInner scheduledAction,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/{scope}/providers/Microsoft.CostManagement/scheduledActions/{name}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ScheduledActionInner>> getByScope(
            @HostParam("$host") String endpoint,
            @PathParam("scope") String scope,
            @PathParam("name") String name,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete("/{scope}/providers/Microsoft.CostManagement/scheduledActions/{name}")
        @ExpectedResponses({200, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> deleteByScope(
            @HostParam("$host") String endpoint,
            @PathParam("scope") String scope,
            @PathParam("name") String name,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/Microsoft.CostManagement/scheduledActions/{name}/execute")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> run(
            @HostParam("$host") String endpoint,
            @PathParam("name") String name,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/{scope}/providers/Microsoft.CostManagement/scheduledActions/{name}/execute")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> runByScope(
            @HostParam("$host") String endpoint,
            @PathParam("scope") String scope,
            @PathParam("name") String name,
            @QueryParam("api-version") String apiVersion,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/Microsoft.CostManagement/checkNameAvailability")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<CheckNameAvailabilityResponseInner>> checkNameAvailability(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") CheckNameAvailabilityRequest checkNameAvailabilityRequest,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/{scope}/providers/Microsoft.CostManagement/checkNameAvailability")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<CheckNameAvailabilityResponseInner>> checkNameAvailabilityByScope(
            @HostParam("$host") String endpoint,
            @PathParam("scope") String scope,
            @QueryParam("api-version") String apiVersion,
            @BodyParam("application/json") CheckNameAvailabilityRequest checkNameAvailabilityRequest,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * List all private scheduled actions.
     *
     * @param filter May be used to filter scheduled actions by properties/viewId. Supported operator is 'eq'.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return scheduled actions list result along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ScheduledActionInner>> listSinglePageAsync(String filter) {
        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.list(this.client.getEndpoint(), this.client.getApiVersion(), filter, accept, context))
            .<PagedResponse<ScheduledActionInner>>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()));
    }

    /**
     * List all private scheduled actions.
     *
     * @param filter May be used to filter scheduled actions by properties/viewId. Supported operator is 'eq'.
     * @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 scheduled actions list result along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ScheduledActionInner>> listSinglePageAsync(String filter, Context context) {
        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
            .list(this.client.getEndpoint(), this.client.getApiVersion(), filter, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List all private scheduled actions.
     *
     * @param filter May be used to filter scheduled actions by properties/viewId. Supported operator is 'eq'.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return scheduled actions list result as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ScheduledActionInner> listAsync(String filter) {
        return new PagedFlux<>(() -> listSinglePageAsync(filter), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * List all private scheduled actions.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return scheduled actions list result as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ScheduledActionInner> listAsync() {
        final String filter = null;
        return new PagedFlux<>(() -> listSinglePageAsync(filter), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * List all private scheduled actions.
     *
     * @param filter May be used to filter scheduled actions by properties/viewId. Supported operator is 'eq'.
     * @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 scheduled actions list result as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ScheduledActionInner> listAsync(String filter, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(filter, context), nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * List all private scheduled actions.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return scheduled actions list result as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ScheduledActionInner> list() {
        final String filter = null;
        return new PagedIterable<>(listAsync(filter));
    }

    /**
     * List all private scheduled actions.
     *
     * @param filter May be used to filter scheduled actions by properties/viewId. Supported operator is 'eq'.
     * @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 scheduled actions list result as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ScheduledActionInner> list(String filter, Context context) {
        return new PagedIterable<>(listAsync(filter, context));
    }

    /**
     * List all shared scheduled actions within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param filter May be used to filter scheduled actions by properties/viewId. Supported operator is 'eq'.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return scheduled actions list result along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ScheduledActionInner>> listByScopeSinglePageAsync(String scope, String filter) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByScope(
                            this.client.getEndpoint(), scope, this.client.getApiVersion(), filter, accept, context))
            .<PagedResponse<ScheduledActionInner>>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()));
    }

    /**
     * List all shared scheduled actions within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param filter May be used to filter scheduled actions by properties/viewId. Supported operator is 'eq'.
     * @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 scheduled actions list result along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ScheduledActionInner>> listByScopeSinglePageAsync(
        String scope, 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 (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByScope(this.client.getEndpoint(), scope, this.client.getApiVersion(), filter, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List all shared scheduled actions within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param filter May be used to filter scheduled actions by properties/viewId. Supported operator is 'eq'.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return scheduled actions list result as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ScheduledActionInner> listByScopeAsync(String scope, String filter) {
        return new PagedFlux<>(
            () -> listByScopeSinglePageAsync(scope, filter), nextLink -> listByScopeNextSinglePageAsync(nextLink));
    }

    /**
     * List all shared scheduled actions within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return scheduled actions list result as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ScheduledActionInner> listByScopeAsync(String scope) {
        final String filter = null;
        return new PagedFlux<>(
            () -> listByScopeSinglePageAsync(scope, filter), nextLink -> listByScopeNextSinglePageAsync(nextLink));
    }

    /**
     * List all shared scheduled actions within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param filter May be used to filter scheduled actions by properties/viewId. Supported operator is 'eq'.
     * @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 scheduled actions list result as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ScheduledActionInner> listByScopeAsync(String scope, String filter, Context context) {
        return new PagedFlux<>(
            () -> listByScopeSinglePageAsync(scope, filter, context),
            nextLink -> listByScopeNextSinglePageAsync(nextLink, context));
    }

    /**
     * List all shared scheduled actions within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return scheduled actions list result as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ScheduledActionInner> listByScope(String scope) {
        final String filter = null;
        return new PagedIterable<>(listByScopeAsync(scope, filter));
    }

    /**
     * List all shared scheduled actions within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param filter May be used to filter scheduled actions by properties/viewId. Supported operator is 'eq'.
     * @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 scheduled actions list result as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ScheduledActionInner> listByScope(String scope, String filter, Context context) {
        return new PagedIterable<>(listByScopeAsync(scope, filter, context));
    }

    /**
     * Create or update a private scheduled action.
     *
     * @param name Scheduled action name.
     * @param scheduledAction Scheduled action to be created or updated.
     * @param ifMatch ETag of the Entity. Not required when creating an entity. Optional when updating an entity and can
     *     be specified to achieve optimistic concurrency.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return scheduled action definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ScheduledActionInner>> createOrUpdateWithResponseAsync(
        String name, ScheduledActionInner scheduledAction, String ifMatch) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        if (scheduledAction == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter scheduledAction is required and cannot be null."));
        } else {
            scheduledAction.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            name,
                            this.client.getApiVersion(),
                            ifMatch,
                            scheduledAction,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create or update a private scheduled action.
     *
     * @param name Scheduled action name.
     * @param scheduledAction Scheduled action to be created or updated.
     * @param ifMatch ETag of the Entity. Not required when creating an entity. Optional when updating an entity and can
     *     be specified to achieve optimistic concurrency.
     * @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 scheduled action definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ScheduledActionInner>> createOrUpdateWithResponseAsync(
        String name, ScheduledActionInner scheduledAction, String ifMatch, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        if (scheduledAction == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter scheduledAction is required and cannot be null."));
        } else {
            scheduledAction.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                name,
                this.client.getApiVersion(),
                ifMatch,
                scheduledAction,
                accept,
                context);
    }

    /**
     * Create or update a private scheduled action.
     *
     * @param name Scheduled action name.
     * @param scheduledAction Scheduled action to be created or 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 scheduled action definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ScheduledActionInner> createOrUpdateAsync(String name, ScheduledActionInner scheduledAction) {
        final String ifMatch = null;
        return createOrUpdateWithResponseAsync(name, scheduledAction, ifMatch)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Create or update a private scheduled action.
     *
     * @param name Scheduled action name.
     * @param scheduledAction Scheduled action to be created or updated.
     * @param ifMatch ETag of the Entity. Not required when creating an entity. Optional when updating an entity and can
     *     be specified to achieve optimistic concurrency.
     * @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 scheduled action definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ScheduledActionInner> createOrUpdateWithResponse(
        String name, ScheduledActionInner scheduledAction, String ifMatch, Context context) {
        return createOrUpdateWithResponseAsync(name, scheduledAction, ifMatch, context).block();
    }

    /**
     * Create or update a private scheduled action.
     *
     * @param name Scheduled action name.
     * @param scheduledAction Scheduled action to be created or 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 scheduled action definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ScheduledActionInner createOrUpdate(String name, ScheduledActionInner scheduledAction) {
        final String ifMatch = null;
        return createOrUpdateWithResponse(name, scheduledAction, ifMatch, Context.NONE).getValue();
    }

    /**
     * Get the private scheduled action by name.
     *
     * @param name Scheduled action name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the private scheduled action by name along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ScheduledActionInner>> getWithResponseAsync(String name) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context -> service.get(this.client.getEndpoint(), name, this.client.getApiVersion(), accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the private scheduled action by name.
     *
     * @param name Scheduled action name.
     * @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 private scheduled action by name along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ScheduledActionInner>> getWithResponseAsync(String name, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.get(this.client.getEndpoint(), name, this.client.getApiVersion(), accept, context);
    }

    /**
     * Get the private scheduled action by name.
     *
     * @param name Scheduled action name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the private scheduled action by name on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ScheduledActionInner> getAsync(String name) {
        return getWithResponseAsync(name).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get the private scheduled action by name.
     *
     * @param name Scheduled action name.
     * @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 private scheduled action by name along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ScheduledActionInner> getWithResponse(String name, Context context) {
        return getWithResponseAsync(name, context).block();
    }

    /**
     * Get the private scheduled action by name.
     *
     * @param name Scheduled action name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the private scheduled action by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ScheduledActionInner get(String name) {
        return getWithResponse(name, Context.NONE).getValue();
    }

    /**
     * Delete a private scheduled action.
     *
     * @param name Scheduled action name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(String name) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service.delete(this.client.getEndpoint(), name, this.client.getApiVersion(), accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a private scheduled action.
     *
     * @param name Scheduled action name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteWithResponseAsync(String name, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.delete(this.client.getEndpoint(), name, this.client.getApiVersion(), accept, context);
    }

    /**
     * Delete a private scheduled action.
     *
     * @param name Scheduled action 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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String name) {
        return deleteWithResponseAsync(name).flatMap(ignored -> Mono.empty());
    }

    /**
     * Delete a private scheduled action.
     *
     * @param name Scheduled action name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(String name, Context context) {
        return deleteWithResponseAsync(name, context).block();
    }

    /**
     * Delete a private scheduled action.
     *
     * @param name Scheduled action 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String name) {
        deleteWithResponse(name, Context.NONE);
    }

    /**
     * Create or update a shared scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @param scheduledAction Scheduled action to be created or updated.
     * @param ifMatch ETag of the Entity. Not required when creating an entity. Optional when updating an entity and can
     *     be specified to achieve optimistic concurrency.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return scheduled action definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ScheduledActionInner>> createOrUpdateByScopeWithResponseAsync(
        String scope, String name, ScheduledActionInner scheduledAction, String ifMatch) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        if (scheduledAction == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter scheduledAction is required and cannot be null."));
        } else {
            scheduledAction.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdateByScope(
                            this.client.getEndpoint(),
                            scope,
                            name,
                            this.client.getApiVersion(),
                            ifMatch,
                            scheduledAction,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create or update a shared scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @param scheduledAction Scheduled action to be created or updated.
     * @param ifMatch ETag of the Entity. Not required when creating an entity. Optional when updating an entity and can
     *     be specified to achieve optimistic concurrency.
     * @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 scheduled action definition along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ScheduledActionInner>> createOrUpdateByScopeWithResponseAsync(
        String scope, String name, ScheduledActionInner scheduledAction, String ifMatch, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        if (scheduledAction == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter scheduledAction is required and cannot be null."));
        } else {
            scheduledAction.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdateByScope(
                this.client.getEndpoint(),
                scope,
                name,
                this.client.getApiVersion(),
                ifMatch,
                scheduledAction,
                accept,
                context);
    }

    /**
     * Create or update a shared scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @param scheduledAction Scheduled action to be created or 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 scheduled action definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ScheduledActionInner> createOrUpdateByScopeAsync(
        String scope, String name, ScheduledActionInner scheduledAction) {
        final String ifMatch = null;
        return createOrUpdateByScopeWithResponseAsync(scope, name, scheduledAction, ifMatch)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Create or update a shared scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @param scheduledAction Scheduled action to be created or updated.
     * @param ifMatch ETag of the Entity. Not required when creating an entity. Optional when updating an entity and can
     *     be specified to achieve optimistic concurrency.
     * @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 scheduled action definition along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ScheduledActionInner> createOrUpdateByScopeWithResponse(
        String scope, String name, ScheduledActionInner scheduledAction, String ifMatch, Context context) {
        return createOrUpdateByScopeWithResponseAsync(scope, name, scheduledAction, ifMatch, context).block();
    }

    /**
     * Create or update a shared scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @param scheduledAction Scheduled action to be created or 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 scheduled action definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ScheduledActionInner createOrUpdateByScope(String scope, String name, ScheduledActionInner scheduledAction) {
        final String ifMatch = null;
        return createOrUpdateByScopeWithResponse(scope, name, scheduledAction, ifMatch, Context.NONE).getValue();
    }

    /**
     * Get the shared scheduled action from the given scope by name.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the shared scheduled action from the given scope by name along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ScheduledActionInner>> getByScopeWithResponseAsync(String scope, String name) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getByScope(
                            this.client.getEndpoint(), scope, name, this.client.getApiVersion(), accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the shared scheduled action from the given scope by name.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @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 shared scheduled action from the given scope by name along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ScheduledActionInner>> getByScopeWithResponseAsync(
        String scope, String name, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.getByScope(this.client.getEndpoint(), scope, name, this.client.getApiVersion(), accept, context);
    }

    /**
     * Get the shared scheduled action from the given scope by name.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the shared scheduled action from the given scope by name on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ScheduledActionInner> getByScopeAsync(String scope, String name) {
        return getByScopeWithResponseAsync(scope, name).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get the shared scheduled action from the given scope by name.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @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 shared scheduled action from the given scope by name along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ScheduledActionInner> getByScopeWithResponse(String scope, String name, Context context) {
        return getByScopeWithResponseAsync(scope, name, context).block();
    }

    /**
     * Get the shared scheduled action from the given scope by name.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the shared scheduled action from the given scope by name.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ScheduledActionInner getByScope(String scope, String name) {
        return getByScopeWithResponse(scope, name, Context.NONE).getValue();
    }

    /**
     * Delete a scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteByScopeWithResponseAsync(String scope, String name) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .deleteByScope(
                            this.client.getEndpoint(), scope, name, this.client.getApiVersion(), accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> deleteByScopeWithResponseAsync(String scope, String name, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .deleteByScope(this.client.getEndpoint(), scope, name, this.client.getApiVersion(), accept, context);
    }

    /**
     * Delete a scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action 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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteByScopeAsync(String scope, String name) {
        return deleteByScopeWithResponseAsync(scope, name).flatMap(ignored -> Mono.empty());
    }

    /**
     * Delete a scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteByScopeWithResponse(String scope, String name, Context context) {
        return deleteByScopeWithResponseAsync(scope, name, context).block();
    }

    /**
     * Delete a scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void deleteByScope(String scope, String name) {
        deleteByScopeWithResponse(scope, name, Context.NONE);
    }

    /**
     * Processes a private scheduled action.
     *
     * @param name Scheduled action name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> runWithResponseAsync(String name) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context -> service.run(this.client.getEndpoint(), name, this.client.getApiVersion(), accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Processes a private scheduled action.
     *
     * @param name Scheduled action name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> runWithResponseAsync(String name, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.run(this.client.getEndpoint(), name, this.client.getApiVersion(), accept, context);
    }

    /**
     * Processes a private scheduled action.
     *
     * @param name Scheduled action 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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> runAsync(String name) {
        return runWithResponseAsync(name).flatMap(ignored -> Mono.empty());
    }

    /**
     * Processes a private scheduled action.
     *
     * @param name Scheduled action name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> runWithResponse(String name, Context context) {
        return runWithResponseAsync(name, context).block();
    }

    /**
     * Processes a private scheduled action.
     *
     * @param name Scheduled action 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void run(String name) {
        runWithResponse(name, Context.NONE);
    }

    /**
     * Runs a shared scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> runByScopeWithResponseAsync(String scope, String name) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .runByScope(
                            this.client.getEndpoint(), scope, name, this.client.getApiVersion(), accept, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Runs a shared scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Void>> runByScopeWithResponseAsync(String scope, String name, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service.runByScope(this.client.getEndpoint(), scope, name, this.client.getApiVersion(), accept, context);
    }

    /**
     * Runs a shared scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action 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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> runByScopeAsync(String scope, String name) {
        return runByScopeWithResponseAsync(scope, name).flatMap(ignored -> Mono.empty());
    }

    /**
     * Runs a shared scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> runByScopeWithResponse(String scope, String name, Context context) {
        return runByScopeWithResponseAsync(scope, name, context).block();
    }

    /**
     * Runs a shared scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param name Scheduled action 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void runByScope(String scope, String name) {
        runByScopeWithResponse(scope, name, Context.NONE);
    }

    /**
     * Checks availability and correctness of the name for a scheduled action.
     *
     * @param checkNameAvailabilityRequest Scheduled action to be created or 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 the check availability result along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CheckNameAvailabilityResponseInner>> checkNameAvailabilityWithResponseAsync(
        CheckNameAvailabilityRequest checkNameAvailabilityRequest) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (checkNameAvailabilityRequest == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter checkNameAvailabilityRequest is required and cannot be null."));
        } else {
            checkNameAvailabilityRequest.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .checkNameAvailability(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            checkNameAvailabilityRequest,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Checks availability and correctness of the name for a scheduled action.
     *
     * @param checkNameAvailabilityRequest Scheduled action to be created or 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 the check availability result along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CheckNameAvailabilityResponseInner>> checkNameAvailabilityWithResponseAsync(
        CheckNameAvailabilityRequest checkNameAvailabilityRequest, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (checkNameAvailabilityRequest == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter checkNameAvailabilityRequest is required and cannot be null."));
        } else {
            checkNameAvailabilityRequest.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .checkNameAvailability(
                this.client.getEndpoint(), this.client.getApiVersion(), checkNameAvailabilityRequest, accept, context);
    }

    /**
     * Checks availability and correctness of the name for a scheduled action.
     *
     * @param checkNameAvailabilityRequest Scheduled action to be created or 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 the check availability result on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CheckNameAvailabilityResponseInner> checkNameAvailabilityAsync(
        CheckNameAvailabilityRequest checkNameAvailabilityRequest) {
        return checkNameAvailabilityWithResponseAsync(checkNameAvailabilityRequest)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Checks availability and correctness of the name for a scheduled action.
     *
     * @param checkNameAvailabilityRequest Scheduled action to be created or 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 the check availability result along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CheckNameAvailabilityResponseInner> checkNameAvailabilityWithResponse(
        CheckNameAvailabilityRequest checkNameAvailabilityRequest, Context context) {
        return checkNameAvailabilityWithResponseAsync(checkNameAvailabilityRequest, context).block();
    }

    /**
     * Checks availability and correctness of the name for a scheduled action.
     *
     * @param checkNameAvailabilityRequest Scheduled action to be created or 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 the check availability result.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CheckNameAvailabilityResponseInner checkNameAvailability(
        CheckNameAvailabilityRequest checkNameAvailabilityRequest) {
        return checkNameAvailabilityWithResponse(checkNameAvailabilityRequest, Context.NONE).getValue();
    }

    /**
     * Checks availability and correctness of the name for a scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param checkNameAvailabilityRequest Scheduled action to be created or 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 the check availability result along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CheckNameAvailabilityResponseInner>> checkNameAvailabilityByScopeWithResponseAsync(
        String scope, CheckNameAvailabilityRequest checkNameAvailabilityRequest) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (checkNameAvailabilityRequest == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter checkNameAvailabilityRequest is required and cannot be null."));
        } else {
            checkNameAvailabilityRequest.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .checkNameAvailabilityByScope(
                            this.client.getEndpoint(),
                            scope,
                            this.client.getApiVersion(),
                            checkNameAvailabilityRequest,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Checks availability and correctness of the name for a scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param checkNameAvailabilityRequest Scheduled action to be created or 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 the check availability result along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CheckNameAvailabilityResponseInner>> checkNameAvailabilityByScopeWithResponseAsync(
        String scope, CheckNameAvailabilityRequest checkNameAvailabilityRequest, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (scope == null) {
            return Mono.error(new IllegalArgumentException("Parameter scope is required and cannot be null."));
        }
        if (checkNameAvailabilityRequest == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter checkNameAvailabilityRequest is required and cannot be null."));
        } else {
            checkNameAvailabilityRequest.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .checkNameAvailabilityByScope(
                this.client.getEndpoint(),
                scope,
                this.client.getApiVersion(),
                checkNameAvailabilityRequest,
                accept,
                context);
    }

    /**
     * Checks availability and correctness of the name for a scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param checkNameAvailabilityRequest Scheduled action to be created or 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 the check availability result on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CheckNameAvailabilityResponseInner> checkNameAvailabilityByScopeAsync(
        String scope, CheckNameAvailabilityRequest checkNameAvailabilityRequest) {
        return checkNameAvailabilityByScopeWithResponseAsync(scope, checkNameAvailabilityRequest)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Checks availability and correctness of the name for a scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param checkNameAvailabilityRequest Scheduled action to be created or 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 the check availability result along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CheckNameAvailabilityResponseInner> checkNameAvailabilityByScopeWithResponse(
        String scope, CheckNameAvailabilityRequest checkNameAvailabilityRequest, Context context) {
        return checkNameAvailabilityByScopeWithResponseAsync(scope, checkNameAvailabilityRequest, context).block();
    }

    /**
     * Checks availability and correctness of the name for a scheduled action within the given scope.
     *
     * @param scope The scope associated with scheduled action operations. This includes
     *     'subscriptions/{subscriptionId}' for subscription scope,
     *     'subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}' for resourceGroup scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}' for Billing Account scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/departments/{departmentId}' for Department
     *     scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/enrollmentAccounts/{enrollmentAccountId}' for
     *     EnrollmentAccount scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/billingProfiles/{billingProfileId}' for
     *     BillingProfile scope,
     *     'providers/Microsoft.Billing/billingAccounts/{billingAccountId}/invoiceSections/{invoiceSectionId}' for
     *     InvoiceSection scope,
     *     'providers/Microsoft.CostManagement/externalBillingAccounts/{externalBillingAccountName}' for External
     *     Billing Account scope and
     *     'providers/Microsoft.CostManagement/externalSubscriptions/{externalSubscriptionName}' for External
     *     Subscription scope. Note: Insight Alerts are only available on subscription scope.
     * @param checkNameAvailabilityRequest Scheduled action to be created or 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 the check availability result.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CheckNameAvailabilityResponseInner checkNameAvailabilityByScope(
        String scope, CheckNameAvailabilityRequest checkNameAvailabilityRequest) {
        return checkNameAvailabilityByScopeWithResponse(scope, checkNameAvailabilityRequest, 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 scheduled actions list result along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ScheduledActionInner>> listNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ScheduledActionInner>>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 scheduled actions list result along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ScheduledActionInner>> listNextSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * 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 scheduled actions list result along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ScheduledActionInner>> listByScopeNextSinglePageAsync(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.listByScopeNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ScheduledActionInner>>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 scheduled actions list result along with {@link PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ScheduledActionInner>> listByScopeNextSinglePageAsync(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
            .listByScopeNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
