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

package com.azure.resourcemanager.paloaltonetworks.ngfw.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.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.management.polling.PollResult;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
import com.azure.core.util.polling.PollerFlux;
import com.azure.core.util.polling.SyncPoller;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.GlobalRulestacksClient;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.AdvSecurityObjectListResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.ChangelogInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.CountriesResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.GlobalRulestackResourceInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.ListAppIdResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.ListFirewallsResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.PredefinedUrlCategoriesResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.SecurityServicesResponseInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.AdvSecurityObjectTypeEnum;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.GlobalRulestackResourceListResult;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.GlobalRulestackResourceUpdate;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.SecurityServicesTypeEnum;
import java.nio.ByteBuffer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

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

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

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

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

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

        @Headers({"Content-Type: application/json"})
        @Put("/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @BodyParam("application/json") GlobalRulestackResourceInner resource,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch("/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<GlobalRulestackResourceInner>> update(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @BodyParam("application/json") GlobalRulestackResourceUpdate properties,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete("/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}")
        @ExpectedResponses({200, 202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> delete(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}/commit")
        @ExpectedResponses({202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> commit(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}/getChangeLog")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ChangelogInner>> getChangeLog(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}/listAdvancedSecurityObjects")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<AdvSecurityObjectListResponseInner>> listAdvancedSecurityObjects(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @QueryParam("skip") String skip,
            @QueryParam("top") Integer top,
            @QueryParam("type") AdvSecurityObjectTypeEnum type,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}/listAppIds")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ListAppIdResponseInner>> listAppIds(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @QueryParam("appIdVersion") String appIdVersion,
            @QueryParam("appPrefix") String appPrefix,
            @QueryParam("skip") String skip,
            @QueryParam("top") Integer top,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}/listCountries")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<CountriesResponseInner>> listCountries(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @QueryParam("skip") String skip,
            @QueryParam("top") Integer top,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}/listFirewalls")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ListFirewallsResponseInner>> listFirewalls(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}/listPredefinedUrlCategories")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<PredefinedUrlCategoriesResponseInner>> listPredefinedUrlCategories(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @QueryParam("skip") String skip,
            @QueryParam("top") Integer top,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}/listSecurityServices")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<SecurityServicesResponseInner>> listSecurityServices(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @QueryParam("skip") String skip,
            @QueryParam("top") Integer top,
            @QueryParam("type") SecurityServicesTypeEnum type,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post("/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}/revert")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Void>> revert(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("globalRulestackName") String globalRulestackName,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * List GlobalRulestackResource resources by Tenant.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response of a GlobalRulestackResource list operation along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<GlobalRulestackResourceInner>> listSinglePageAsync() {
        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(), accept, context))
            .<PagedResponse<GlobalRulestackResourceInner>>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 GlobalRulestackResource resources by Tenant.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response of a GlobalRulestackResource list operation along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<GlobalRulestackResourceInner>> listSinglePageAsync(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(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

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

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

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

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

    /**
     * Get a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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 GlobalRulestackResource along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<GlobalRulestackResourceInner>> getWithResponseAsync(String globalRulestackName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

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

    /**
     * Get a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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 GlobalRulestackResource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<GlobalRulestackResourceInner> getAsync(String globalRulestackName) {
        return getWithResponseAsync(globalRulestackName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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 a GlobalRulestackResource along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<GlobalRulestackResourceInner> getWithResponse(String globalRulestackName, Context context) {
        return getWithResponseAsync(globalRulestackName, context).block();
    }

    /**
     * Get a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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 GlobalRulestackResource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GlobalRulestackResourceInner get(String globalRulestackName) {
        return getWithResponse(globalRulestackName, Context.NONE).getValue();
    }

    /**
     * Create a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param resource Resource create parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return paloAltoNetworks GlobalRulestack along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String globalRulestackName, GlobalRulestackResourceInner resource) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        if (resource == null) {
            return Mono.error(new IllegalArgumentException("Parameter resource is required and cannot be null."));
        } else {
            resource.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            resource,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param resource Resource create parameters.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return paloAltoNetworks GlobalRulestack along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String globalRulestackName, GlobalRulestackResourceInner resource, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        if (resource == null) {
            return Mono.error(new IllegalArgumentException("Parameter resource is required and cannot be null."));
        } else {
            resource.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(), this.client.getApiVersion(), globalRulestackName, resource, accept, context);
    }

    /**
     * Create a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param resource Resource create parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of paloAltoNetworks GlobalRulestack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<GlobalRulestackResourceInner>, GlobalRulestackResourceInner> beginCreateOrUpdateAsync(
        String globalRulestackName, GlobalRulestackResourceInner resource) {
        Mono<Response<Flux<ByteBuffer>>> mono = createOrUpdateWithResponseAsync(globalRulestackName, resource);
        return this
            .client
            .<GlobalRulestackResourceInner, GlobalRulestackResourceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                GlobalRulestackResourceInner.class,
                GlobalRulestackResourceInner.class,
                this.client.getContext());
    }

    /**
     * Create a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param resource Resource create parameters.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of paloAltoNetworks GlobalRulestack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<GlobalRulestackResourceInner>, GlobalRulestackResourceInner> beginCreateOrUpdateAsync(
        String globalRulestackName, GlobalRulestackResourceInner resource, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = createOrUpdateWithResponseAsync(globalRulestackName, resource, context);
        return this
            .client
            .<GlobalRulestackResourceInner, GlobalRulestackResourceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                GlobalRulestackResourceInner.class,
                GlobalRulestackResourceInner.class,
                context);
    }

    /**
     * Create a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param resource Resource create parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of paloAltoNetworks GlobalRulestack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<GlobalRulestackResourceInner>, GlobalRulestackResourceInner> beginCreateOrUpdate(
        String globalRulestackName, GlobalRulestackResourceInner resource) {
        return this.beginCreateOrUpdateAsync(globalRulestackName, resource).getSyncPoller();
    }

    /**
     * Create a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param resource Resource create parameters.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of paloAltoNetworks GlobalRulestack.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<GlobalRulestackResourceInner>, GlobalRulestackResourceInner> beginCreateOrUpdate(
        String globalRulestackName, GlobalRulestackResourceInner resource, Context context) {
        return this.beginCreateOrUpdateAsync(globalRulestackName, resource, context).getSyncPoller();
    }

    /**
     * Create a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param resource Resource create parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return paloAltoNetworks GlobalRulestack on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<GlobalRulestackResourceInner> createOrUpdateAsync(
        String globalRulestackName, GlobalRulestackResourceInner resource) {
        return beginCreateOrUpdateAsync(globalRulestackName, resource)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param resource Resource create parameters.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return paloAltoNetworks GlobalRulestack on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<GlobalRulestackResourceInner> createOrUpdateAsync(
        String globalRulestackName, GlobalRulestackResourceInner resource, Context context) {
        return beginCreateOrUpdateAsync(globalRulestackName, resource, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param resource Resource create parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return paloAltoNetworks GlobalRulestack.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GlobalRulestackResourceInner createOrUpdate(
        String globalRulestackName, GlobalRulestackResourceInner resource) {
        return createOrUpdateAsync(globalRulestackName, resource).block();
    }

    /**
     * Create a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param resource Resource create parameters.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return paloAltoNetworks GlobalRulestack.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GlobalRulestackResourceInner createOrUpdate(
        String globalRulestackName, GlobalRulestackResourceInner resource, Context context) {
        return createOrUpdateAsync(globalRulestackName, resource, context).block();
    }

    /**
     * Update a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param properties The resource properties to be 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 paloAltoNetworks GlobalRulestack along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<GlobalRulestackResourceInner>> updateWithResponseAsync(
        String globalRulestackName, GlobalRulestackResourceUpdate properties) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        if (properties == null) {
            return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null."));
        } else {
            properties.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            properties,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Update a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param properties The resource properties to be 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 paloAltoNetworks GlobalRulestack along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<GlobalRulestackResourceInner>> updateWithResponseAsync(
        String globalRulestackName, GlobalRulestackResourceUpdate properties, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        if (properties == null) {
            return Mono.error(new IllegalArgumentException("Parameter properties is required and cannot be null."));
        } else {
            properties.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                globalRulestackName,
                properties,
                accept,
                context);
    }

    /**
     * Update a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param properties The resource properties to be 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 paloAltoNetworks GlobalRulestack on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<GlobalRulestackResourceInner> updateAsync(
        String globalRulestackName, GlobalRulestackResourceUpdate properties) {
        return updateWithResponseAsync(globalRulestackName, properties)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Update a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param properties The resource properties to be 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 paloAltoNetworks GlobalRulestack along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<GlobalRulestackResourceInner> updateWithResponse(
        String globalRulestackName, GlobalRulestackResourceUpdate properties, Context context) {
        return updateWithResponseAsync(globalRulestackName, properties, context).block();
    }

    /**
     * Update a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param properties The resource properties to be 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 paloAltoNetworks GlobalRulestack.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public GlobalRulestackResourceInner update(String globalRulestackName, GlobalRulestackResourceUpdate properties) {
        return updateWithResponse(globalRulestackName, properties, Context.NONE).getValue();
    }

    /**
     * Delete a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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<Flux<ByteBuffer>>> deleteWithResponseAsync(String globalRulestackName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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<Flux<ByteBuffer>>> deleteWithResponseAsync(String globalRulestackName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(this.client.getEndpoint(), this.client.getApiVersion(), globalRulestackName, accept, context);
    }

    /**
     * Delete a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(String globalRulestackName) {
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(globalRulestackName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Delete a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(String globalRulestackName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(globalRulestackName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Delete a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(String globalRulestackName) {
        return this.beginDeleteAsync(globalRulestackName).getSyncPoller();
    }

    /**
     * Delete a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(String globalRulestackName, Context context) {
        return this.beginDeleteAsync(globalRulestackName, context).getSyncPoller();
    }

    /**
     * Delete a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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 globalRulestackName) {
        return beginDeleteAsync(globalRulestackName).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String globalRulestackName, Context context) {
        return beginDeleteAsync(globalRulestackName, context).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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 globalRulestackName) {
        deleteAsync(globalRulestackName).block();
    }

    /**
     * Delete a GlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String globalRulestackName, Context context) {
        deleteAsync(globalRulestackName, context).block();
    }

    /**
     * Commit rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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<Flux<ByteBuffer>>> commitWithResponseAsync(String globalRulestackName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .commit(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Commit rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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<Flux<ByteBuffer>>> commitWithResponseAsync(String globalRulestackName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .commit(this.client.getEndpoint(), this.client.getApiVersion(), globalRulestackName, accept, context);
    }

    /**
     * Commit rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginCommitAsync(String globalRulestackName) {
        Mono<Response<Flux<ByteBuffer>>> mono = commitWithResponseAsync(globalRulestackName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Commit rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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 PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginCommitAsync(String globalRulestackName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = commitWithResponseAsync(globalRulestackName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Commit rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginCommit(String globalRulestackName) {
        return this.beginCommitAsync(globalRulestackName).getSyncPoller();
    }

    /**
     * Commit rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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 SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginCommit(String globalRulestackName, Context context) {
        return this.beginCommitAsync(globalRulestackName, context).getSyncPoller();
    }

    /**
     * Commit rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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> commitAsync(String globalRulestackName) {
        return beginCommitAsync(globalRulestackName).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Commit rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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 A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> commitAsync(String globalRulestackName, Context context) {
        return beginCommitAsync(globalRulestackName, context).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Commit rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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 commit(String globalRulestackName) {
        commitAsync(globalRulestackName).block();
    }

    /**
     * Commit rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void commit(String globalRulestackName, Context context) {
        commitAsync(globalRulestackName, context).block();
    }

    /**
     * Get changelog.
     *
     * @param globalRulestackName GlobalRulestack resource 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 changelog along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ChangelogInner>> getChangeLogWithResponseAsync(String globalRulestackName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getChangeLog(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get changelog.
     *
     * @param globalRulestackName GlobalRulestack resource 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 changelog along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ChangelogInner>> getChangeLogWithResponseAsync(String globalRulestackName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getChangeLog(this.client.getEndpoint(), this.client.getApiVersion(), globalRulestackName, accept, context);
    }

    /**
     * Get changelog.
     *
     * @param globalRulestackName GlobalRulestack resource 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 changelog on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ChangelogInner> getChangeLogAsync(String globalRulestackName) {
        return getChangeLogWithResponseAsync(globalRulestackName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get changelog.
     *
     * @param globalRulestackName GlobalRulestack resource 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 changelog along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ChangelogInner> getChangeLogWithResponse(String globalRulestackName, Context context) {
        return getChangeLogWithResponseAsync(globalRulestackName, context).block();
    }

    /**
     * Get changelog.
     *
     * @param globalRulestackName GlobalRulestack resource 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 changelog.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ChangelogInner getChangeLog(String globalRulestackName) {
        return getChangeLogWithResponse(globalRulestackName, Context.NONE).getValue();
    }

    /**
     * Get the list of advanced security objects.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param type The type parameter.
     * @param skip The skip parameter.
     * @param top The top parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of advanced security objects along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<AdvSecurityObjectListResponseInner>> listAdvancedSecurityObjectsWithResponseAsync(
        String globalRulestackName, AdvSecurityObjectTypeEnum type, String skip, Integer top) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        if (type == null) {
            return Mono.error(new IllegalArgumentException("Parameter type is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listAdvancedSecurityObjects(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            skip,
                            top,
                            type,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get the list of advanced security objects.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param type The type parameter.
     * @param skip The skip parameter.
     * @param top The top parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of advanced security objects along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<AdvSecurityObjectListResponseInner>> listAdvancedSecurityObjectsWithResponseAsync(
        String globalRulestackName, AdvSecurityObjectTypeEnum type, String skip, Integer top, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        if (type == null) {
            return Mono.error(new IllegalArgumentException("Parameter type is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listAdvancedSecurityObjects(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                globalRulestackName,
                skip,
                top,
                type,
                accept,
                context);
    }

    /**
     * Get the list of advanced security objects.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param type The type parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of advanced security objects on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<AdvSecurityObjectListResponseInner> listAdvancedSecurityObjectsAsync(
        String globalRulestackName, AdvSecurityObjectTypeEnum type) {
        final String skip = null;
        final Integer top = null;
        return listAdvancedSecurityObjectsWithResponseAsync(globalRulestackName, type, skip, top)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get the list of advanced security objects.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param type The type parameter.
     * @param skip The skip parameter.
     * @param top The top parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of advanced security objects along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<AdvSecurityObjectListResponseInner> listAdvancedSecurityObjectsWithResponse(
        String globalRulestackName, AdvSecurityObjectTypeEnum type, String skip, Integer top, Context context) {
        return listAdvancedSecurityObjectsWithResponseAsync(globalRulestackName, type, skip, top, context).block();
    }

    /**
     * Get the list of advanced security objects.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param type The type parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the list of advanced security objects.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public AdvSecurityObjectListResponseInner listAdvancedSecurityObjects(
        String globalRulestackName, AdvSecurityObjectTypeEnum type) {
        final String skip = null;
        final Integer top = null;
        return listAdvancedSecurityObjectsWithResponse(globalRulestackName, type, skip, top, Context.NONE).getValue();
    }

    /**
     * List of AppIds for GlobalRulestack ApiVersion.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param appIdVersion The appIdVersion parameter.
     * @param appPrefix The appPrefix parameter.
     * @param skip The skip parameter.
     * @param top The top parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ListAppIdResponseInner>> listAppIdsWithResponseAsync(
        String globalRulestackName, String appIdVersion, String appPrefix, String skip, Integer top) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listAppIds(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            appIdVersion,
                            appPrefix,
                            skip,
                            top,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List of AppIds for GlobalRulestack ApiVersion.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param appIdVersion The appIdVersion parameter.
     * @param appPrefix The appPrefix parameter.
     * @param skip The skip parameter.
     * @param top The top parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ListAppIdResponseInner>> listAppIdsWithResponseAsync(
        String globalRulestackName, String appIdVersion, String appPrefix, String skip, Integer top, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listAppIds(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                globalRulestackName,
                appIdVersion,
                appPrefix,
                skip,
                top,
                accept,
                context);
    }

    /**
     * List of AppIds for GlobalRulestack ApiVersion.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ListAppIdResponseInner> listAppIdsAsync(String globalRulestackName) {
        final String appIdVersion = null;
        final String appPrefix = null;
        final String skip = null;
        final Integer top = null;
        return listAppIdsWithResponseAsync(globalRulestackName, appIdVersion, appPrefix, skip, top)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * List of AppIds for GlobalRulestack ApiVersion.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param appIdVersion The appIdVersion parameter.
     * @param appPrefix The appPrefix parameter.
     * @param skip The skip parameter.
     * @param top The top parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ListAppIdResponseInner> listAppIdsWithResponse(
        String globalRulestackName, String appIdVersion, String appPrefix, String skip, Integer top, Context context) {
        return listAppIdsWithResponseAsync(globalRulestackName, appIdVersion, appPrefix, skip, top, context).block();
    }

    /**
     * List of AppIds for GlobalRulestack ApiVersion.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ListAppIdResponseInner listAppIds(String globalRulestackName) {
        final String appIdVersion = null;
        final String appPrefix = null;
        final String skip = null;
        final Integer top = null;
        return listAppIdsWithResponse(globalRulestackName, appIdVersion, appPrefix, skip, top, Context.NONE).getValue();
    }

    /**
     * List of countries for Rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param skip The skip parameter.
     * @param top The top 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 countries Response Object along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CountriesResponseInner>> listCountriesWithResponseAsync(
        String globalRulestackName, String skip, Integer top) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listCountries(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            skip,
                            top,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List of countries for Rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param skip The skip parameter.
     * @param top The top 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 countries Response Object along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<CountriesResponseInner>> listCountriesWithResponseAsync(
        String globalRulestackName, String skip, Integer top, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listCountries(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                globalRulestackName,
                skip,
                top,
                accept,
                context);
    }

    /**
     * List of countries for Rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource 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 countries Response Object on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<CountriesResponseInner> listCountriesAsync(String globalRulestackName) {
        final String skip = null;
        final Integer top = null;
        return listCountriesWithResponseAsync(globalRulestackName, skip, top)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * List of countries for Rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param skip The skip parameter.
     * @param top The top 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 countries Response Object along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<CountriesResponseInner> listCountriesWithResponse(
        String globalRulestackName, String skip, Integer top, Context context) {
        return listCountriesWithResponseAsync(globalRulestackName, skip, top, context).block();
    }

    /**
     * List of countries for Rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource 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 countries Response Object.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public CountriesResponseInner listCountries(String globalRulestackName) {
        final String skip = null;
        final Integer top = null;
        return listCountriesWithResponse(globalRulestackName, skip, top, Context.NONE).getValue();
    }

    /**
     * List of Firewalls associated with Rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource 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 list firewalls response along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ListFirewallsResponseInner>> listFirewallsWithResponseAsync(String globalRulestackName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listFirewalls(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List of Firewalls associated with Rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource 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 list firewalls response along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ListFirewallsResponseInner>> listFirewallsWithResponseAsync(
        String globalRulestackName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listFirewalls(
                this.client.getEndpoint(), this.client.getApiVersion(), globalRulestackName, accept, context);
    }

    /**
     * List of Firewalls associated with Rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource 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 list firewalls response on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ListFirewallsResponseInner> listFirewallsAsync(String globalRulestackName) {
        return listFirewallsWithResponseAsync(globalRulestackName).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * List of Firewalls associated with Rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource 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 list firewalls response along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ListFirewallsResponseInner> listFirewallsWithResponse(String globalRulestackName, Context context) {
        return listFirewallsWithResponseAsync(globalRulestackName, context).block();
    }

    /**
     * List of Firewalls associated with Rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource 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 list firewalls response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ListFirewallsResponseInner listFirewalls(String globalRulestackName) {
        return listFirewallsWithResponse(globalRulestackName, Context.NONE).getValue();
    }

    /**
     * List predefined URL categories for rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param skip The skip parameter.
     * @param top The top 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 predefined url categories response along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<PredefinedUrlCategoriesResponseInner>> listPredefinedUrlCategoriesWithResponseAsync(
        String globalRulestackName, String skip, Integer top) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listPredefinedUrlCategories(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            skip,
                            top,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List predefined URL categories for rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param skip The skip parameter.
     * @param top The top 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 predefined url categories response along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<PredefinedUrlCategoriesResponseInner>> listPredefinedUrlCategoriesWithResponseAsync(
        String globalRulestackName, String skip, Integer top, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listPredefinedUrlCategories(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                globalRulestackName,
                skip,
                top,
                accept,
                context);
    }

    /**
     * List predefined URL categories for rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource 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 predefined url categories response on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PredefinedUrlCategoriesResponseInner> listPredefinedUrlCategoriesAsync(String globalRulestackName) {
        final String skip = null;
        final Integer top = null;
        return listPredefinedUrlCategoriesWithResponseAsync(globalRulestackName, skip, top)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * List predefined URL categories for rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param skip The skip parameter.
     * @param top The top 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 predefined url categories response along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<PredefinedUrlCategoriesResponseInner> listPredefinedUrlCategoriesWithResponse(
        String globalRulestackName, String skip, Integer top, Context context) {
        return listPredefinedUrlCategoriesWithResponseAsync(globalRulestackName, skip, top, context).block();
    }

    /**
     * List predefined URL categories for rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource 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 predefined url categories response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PredefinedUrlCategoriesResponseInner listPredefinedUrlCategories(String globalRulestackName) {
        final String skip = null;
        final Integer top = null;
        return listPredefinedUrlCategoriesWithResponse(globalRulestackName, skip, top, Context.NONE).getValue();
    }

    /**
     * List the security services for rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param type The type parameter.
     * @param skip The skip parameter.
     * @param top The top 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 security services list response along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SecurityServicesResponseInner>> listSecurityServicesWithResponseAsync(
        String globalRulestackName, SecurityServicesTypeEnum type, String skip, Integer top) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        if (type == null) {
            return Mono.error(new IllegalArgumentException("Parameter type is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listSecurityServices(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            skip,
                            top,
                            type,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * List the security services for rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param type The type parameter.
     * @param skip The skip parameter.
     * @param top The top 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 security services list response along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<SecurityServicesResponseInner>> listSecurityServicesWithResponseAsync(
        String globalRulestackName, SecurityServicesTypeEnum type, String skip, Integer top, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        if (type == null) {
            return Mono.error(new IllegalArgumentException("Parameter type is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listSecurityServices(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                globalRulestackName,
                skip,
                top,
                type,
                accept,
                context);
    }

    /**
     * List the security services for rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param type The type 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 security services list response on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<SecurityServicesResponseInner> listSecurityServicesAsync(
        String globalRulestackName, SecurityServicesTypeEnum type) {
        final String skip = null;
        final Integer top = null;
        return listSecurityServicesWithResponseAsync(globalRulestackName, type, skip, top)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * List the security services for rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param type The type parameter.
     * @param skip The skip parameter.
     * @param top The top 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 security services list response along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<SecurityServicesResponseInner> listSecurityServicesWithResponse(
        String globalRulestackName, SecurityServicesTypeEnum type, String skip, Integer top, Context context) {
        return listSecurityServicesWithResponseAsync(globalRulestackName, type, skip, top, context).block();
    }

    /**
     * List the security services for rulestack.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param type The type 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 security services list response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public SecurityServicesResponseInner listSecurityServices(
        String globalRulestackName, SecurityServicesTypeEnum type) {
        final String skip = null;
        final Integer top = null;
        return listSecurityServicesWithResponse(globalRulestackName, type, skip, top, Context.NONE).getValue();
    }

    /**
     * Revert rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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>> revertWithResponseAsync(String globalRulestackName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .revert(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Revert rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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>> revertWithResponseAsync(String globalRulestackName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (globalRulestackName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter globalRulestackName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .revert(this.client.getEndpoint(), this.client.getApiVersion(), globalRulestackName, accept, context);
    }

    /**
     * Revert rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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> revertAsync(String globalRulestackName) {
        return revertWithResponseAsync(globalRulestackName).flatMap(ignored -> Mono.empty());
    }

    /**
     * Revert rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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> revertWithResponse(String globalRulestackName, Context context) {
        return revertWithResponseAsync(globalRulestackName, context).block();
    }

    /**
     * Revert rulestack configuration.
     *
     * @param globalRulestackName GlobalRulestack resource 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 revert(String globalRulestackName) {
        revertWithResponse(globalRulestackName, Context.NONE);
    }

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

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response of a GlobalRulestackResource list operation along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<GlobalRulestackResourceInner>> 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));
    }
}
