// 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.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.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.FqdnListGlobalRulestacksClient;
import com.azure.resourcemanager.paloaltonetworks.ngfw.fluent.models.FqdnListGlobalRulestackResourceInner;
import com.azure.resourcemanager.paloaltonetworks.ngfw.models.FqdnListGlobalRulestackResourceListResult;
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 FqdnListGlobalRulestacksClient. */
public final class FqdnListGlobalRulestacksClientImpl implements FqdnListGlobalRulestacksClient {
    /** The proxy service used to perform REST calls. */
    private final FqdnListGlobalRulestacksService service;

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

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

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

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

        @Headers({"Content-Type: application/json"})
        @Delete("/providers/PaloAltoNetworks.Cloudngfw/globalRulestacks/{globalRulestackName}/fqdnlists/{name}")
        @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,
            @PathParam("name") String name,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * List FqdnListGlobalRulestackResource resources by Tenant.
     *
     * @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 of a FqdnListGlobalRulestackResource list operation along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<FqdnListGlobalRulestackResourceInner>> listSinglePageAsync(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
                        .list(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            globalRulestackName,
                            accept,
                            context))
            .<PagedResponse<FqdnListGlobalRulestackResourceInner>>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 FqdnListGlobalRulestackResource resources by Tenant.
     *
     * @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 response of a FqdnListGlobalRulestackResource list operation along with {@link PagedResponse} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<FqdnListGlobalRulestackResourceInner>> listSinglePageAsync(
        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
            .list(this.client.getEndpoint(), this.client.getApiVersion(), globalRulestackName, accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List FqdnListGlobalRulestackResource resources by Tenant.
     *
     * @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 of a FqdnListGlobalRulestackResource list operation as paginated response with {@link
     *     PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<FqdnListGlobalRulestackResourceInner> listAsync(String globalRulestackName) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(globalRulestackName), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * List FqdnListGlobalRulestackResource resources by Tenant.
     *
     * @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 response of a FqdnListGlobalRulestackResource list operation as paginated response with {@link
     *     PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<FqdnListGlobalRulestackResourceInner> listAsync(String globalRulestackName, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(globalRulestackName, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * List FqdnListGlobalRulestackResource resources by Tenant.
     *
     * @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 of a FqdnListGlobalRulestackResource list operation as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<FqdnListGlobalRulestackResourceInner> list(String globalRulestackName) {
        return new PagedIterable<>(listAsync(globalRulestackName));
    }

    /**
     * List FqdnListGlobalRulestackResource resources by Tenant.
     *
     * @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 response of a FqdnListGlobalRulestackResource list operation as paginated response with {@link
     *     PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<FqdnListGlobalRulestackResourceInner> list(String globalRulestackName, Context context) {
        return new PagedIterable<>(listAsync(globalRulestackName, context));
    }

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

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

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

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

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

    /**
     * Create a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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 globalRulestack fqdnList along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String globalRulestackName, String name, FqdnListGlobalRulestackResourceInner 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 (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name 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,
                            name,
                            resource,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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 globalRulestack fqdnList along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String globalRulestackName, String name, FqdnListGlobalRulestackResourceInner 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 (name == null) {
            return Mono.error(new IllegalArgumentException("Parameter name 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,
                name,
                resource,
                accept,
                context);
    }

    /**
     * Create a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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 globalRulestack fqdnList.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<FqdnListGlobalRulestackResourceInner>, FqdnListGlobalRulestackResourceInner>
        beginCreateOrUpdateAsync(
            String globalRulestackName, String name, FqdnListGlobalRulestackResourceInner resource) {
        Mono<Response<Flux<ByteBuffer>>> mono = createOrUpdateWithResponseAsync(globalRulestackName, name, resource);
        return this
            .client
            .<FqdnListGlobalRulestackResourceInner, FqdnListGlobalRulestackResourceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                FqdnListGlobalRulestackResourceInner.class,
                FqdnListGlobalRulestackResourceInner.class,
                this.client.getContext());
    }

    /**
     * Create a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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 globalRulestack fqdnList.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<FqdnListGlobalRulestackResourceInner>, FqdnListGlobalRulestackResourceInner>
        beginCreateOrUpdateAsync(
            String globalRulestackName, String name, FqdnListGlobalRulestackResourceInner resource, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(globalRulestackName, name, resource, context);
        return this
            .client
            .<FqdnListGlobalRulestackResourceInner, FqdnListGlobalRulestackResourceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                FqdnListGlobalRulestackResourceInner.class,
                FqdnListGlobalRulestackResourceInner.class,
                context);
    }

    /**
     * Create a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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 globalRulestack fqdnList.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<FqdnListGlobalRulestackResourceInner>, FqdnListGlobalRulestackResourceInner>
        beginCreateOrUpdate(String globalRulestackName, String name, FqdnListGlobalRulestackResourceInner resource) {
        return this.beginCreateOrUpdateAsync(globalRulestackName, name, resource).getSyncPoller();
    }

    /**
     * Create a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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 globalRulestack fqdnList.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<FqdnListGlobalRulestackResourceInner>, FqdnListGlobalRulestackResourceInner>
        beginCreateOrUpdate(
            String globalRulestackName, String name, FqdnListGlobalRulestackResourceInner resource, Context context) {
        return this.beginCreateOrUpdateAsync(globalRulestackName, name, resource, context).getSyncPoller();
    }

    /**
     * Create a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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 globalRulestack fqdnList on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<FqdnListGlobalRulestackResourceInner> createOrUpdateAsync(
        String globalRulestackName, String name, FqdnListGlobalRulestackResourceInner resource) {
        return beginCreateOrUpdateAsync(globalRulestackName, name, resource)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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 globalRulestack fqdnList on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<FqdnListGlobalRulestackResourceInner> createOrUpdateAsync(
        String globalRulestackName, String name, FqdnListGlobalRulestackResourceInner resource, Context context) {
        return beginCreateOrUpdateAsync(globalRulestackName, name, resource, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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 globalRulestack fqdnList.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public FqdnListGlobalRulestackResourceInner createOrUpdate(
        String globalRulestackName, String name, FqdnListGlobalRulestackResourceInner resource) {
        return createOrUpdateAsync(globalRulestackName, name, resource).block();
    }

    /**
     * Create a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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 globalRulestack fqdnList.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public FqdnListGlobalRulestackResourceInner createOrUpdate(
        String globalRulestackName, String name, FqdnListGlobalRulestackResourceInner resource, Context context) {
        return createOrUpdateAsync(globalRulestackName, name, resource, context).block();
    }

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

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

    /**
     * Delete a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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, String name) {
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(globalRulestackName, name);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Delete a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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, String name, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(globalRulestackName, name, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Delete a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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, String name) {
        return this.beginDeleteAsync(globalRulestackName, name).getSyncPoller();
    }

    /**
     * Delete a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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, String name, Context context) {
        return this.beginDeleteAsync(globalRulestackName, name, context).getSyncPoller();
    }

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

    /**
     * Delete a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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, String name, Context context) {
        return beginDeleteAsync(globalRulestackName, name, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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, String name) {
        deleteAsync(globalRulestackName, name).block();
    }

    /**
     * Delete a FqdnListGlobalRulestackResource.
     *
     * @param globalRulestackName GlobalRulestack resource name.
     * @param name fqdn list 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, String name, Context context) {
        deleteAsync(globalRulestackName, name, context).block();
    }

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