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

package com.azure.resourcemanager.communication.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.communication.fluent.DomainsClient;
import com.azure.resourcemanager.communication.fluent.models.DomainResourceInner;
import com.azure.resourcemanager.communication.models.DomainResourceList;
import com.azure.resourcemanager.communication.models.UpdateDomainRequestParameters;
import com.azure.resourcemanager.communication.models.VerificationParameter;
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 DomainsClient. */
public final class DomainsClientImpl implements DomainsClient {
    /** The proxy service used to perform REST calls. */
    private final DomainsService service;

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

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

    /**
     * The interface defining all the services for CommunicationServiceManagementClientDomains to be used by the proxy
     * service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "CommunicationService")
    public interface DomainsService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Communication/emailServices/{emailServiceName}/domains/{domainName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<DomainResourceInner>> get(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("emailServiceName") String emailServiceName,
            @PathParam("domainName") String domainName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Communication/emailServices/{emailServiceName}/domains/{domainName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("emailServiceName") String emailServiceName,
            @PathParam("domainName") String domainName,
            @BodyParam("application/json") DomainResourceInner parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Communication/emailServices/{emailServiceName}/domains/{domainName}")
        @ExpectedResponses({200, 202, 204})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> delete(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("emailServiceName") String emailServiceName,
            @PathParam("domainName") String domainName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Communication/emailServices/{emailServiceName}/domains/{domainName}")
        @ExpectedResponses({200, 201})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> update(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("emailServiceName") String emailServiceName,
            @PathParam("domainName") String domainName,
            @BodyParam("application/json") UpdateDomainRequestParameters parameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Communication/emailServices/{emailServiceName}/domains/{domainName}/initiateVerification")
        @ExpectedResponses({202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> initiateVerification(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("emailServiceName") String emailServiceName,
            @PathParam("domainName") String domainName,
            @BodyParam("application/json") VerificationParameter parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Post(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Communication/emailServices/{emailServiceName}/domains/{domainName}/cancelVerification")
        @ExpectedResponses({202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> cancelVerification(
            @HostParam("$host") String endpoint,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("emailServiceName") String emailServiceName,
            @PathParam("domainName") String domainName,
            @BodyParam("application/json") VerificationParameter parameters,
            @HeaderParam("Accept") String accept,
            Context context);

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

    /**
     * Get
     *
     * <p>Get the Domains resource and its properties.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Domains resource and its properties along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<DomainResourceInner>> getWithResponseAsync(
        String resourceGroupName, String emailServiceName, String domainName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            emailServiceName,
                            domainName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Get
     *
     * <p>Get the Domains resource and its properties.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @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 Domains resource and its properties along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<DomainResourceInner>> getWithResponseAsync(
        String resourceGroupName, String emailServiceName, String domainName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName 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(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                emailServiceName,
                domainName,
                accept,
                context);
    }

    /**
     * Get
     *
     * <p>Get the Domains resource and its properties.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Domains resource and its properties on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DomainResourceInner> getAsync(String resourceGroupName, String emailServiceName, String domainName) {
        return getWithResponseAsync(resourceGroupName, emailServiceName, domainName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get
     *
     * <p>Get the Domains resource and its properties.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @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 Domains resource and its properties along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<DomainResourceInner> getWithResponse(
        String resourceGroupName, String emailServiceName, String domainName, Context context) {
        return getWithResponseAsync(resourceGroupName, emailServiceName, domainName, context).block();
    }

    /**
     * Get
     *
     * <p>Get the Domains resource and its properties.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 Domains resource and its properties.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DomainResourceInner get(String resourceGroupName, String emailServiceName, String domainName) {
        return getWithResponse(resourceGroupName, emailServiceName, domainName, Context.NONE).getValue();
    }

    /**
     * Create Or Update
     *
     * <p>Add a new Domains resource under the parent EmailService resource or update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the create or update 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 class representing a Domains resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String emailServiceName, String domainName, DomainResourceInner parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            emailServiceName,
                            domainName,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create Or Update
     *
     * <p>Add a new Domains resource under the parent EmailService resource or update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the create or update operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a class representing a Domains resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        DomainResourceInner parameters,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                emailServiceName,
                domainName,
                parameters,
                accept,
                context);
    }

    /**
     * Create Or Update
     *
     * <p>Add a new Domains resource under the parent EmailService resource or update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the create or update 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 a class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DomainResourceInner>, DomainResourceInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String emailServiceName, String domainName, DomainResourceInner parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, emailServiceName, domainName, parameters);
        return this
            .client
            .<DomainResourceInner, DomainResourceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DomainResourceInner.class,
                DomainResourceInner.class,
                this.client.getContext());
    }

    /**
     * Create Or Update
     *
     * <p>Add a new Domains resource under the parent EmailService resource or update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the create or update operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of a class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DomainResourceInner>, DomainResourceInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        DomainResourceInner parameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, emailServiceName, domainName, parameters, context);
        return this
            .client
            .<DomainResourceInner, DomainResourceInner>getLroResult(
                mono, this.client.getHttpPipeline(), DomainResourceInner.class, DomainResourceInner.class, context);
    }

    /**
     * Create Or Update
     *
     * <p>Add a new Domains resource under the parent EmailService resource or update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the create or update 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 a class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DomainResourceInner>, DomainResourceInner> beginCreateOrUpdate(
        String resourceGroupName, String emailServiceName, String domainName, DomainResourceInner parameters) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, emailServiceName, domainName, parameters)
            .getSyncPoller();
    }

    /**
     * Create Or Update
     *
     * <p>Add a new Domains resource under the parent EmailService resource or update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the create or update operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of a class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DomainResourceInner>, DomainResourceInner> beginCreateOrUpdate(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        DomainResourceInner parameters,
        Context context) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, emailServiceName, domainName, parameters, context)
            .getSyncPoller();
    }

    /**
     * Create Or Update
     *
     * <p>Add a new Domains resource under the parent EmailService resource or update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the create or update 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 class representing a Domains resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DomainResourceInner> createOrUpdateAsync(
        String resourceGroupName, String emailServiceName, String domainName, DomainResourceInner parameters) {
        return beginCreateOrUpdateAsync(resourceGroupName, emailServiceName, domainName, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create Or Update
     *
     * <p>Add a new Domains resource under the parent EmailService resource or update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the create or update operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a class representing a Domains resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DomainResourceInner> createOrUpdateAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        DomainResourceInner parameters,
        Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, emailServiceName, domainName, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create Or Update
     *
     * <p>Add a new Domains resource under the parent EmailService resource or update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the create or update 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 class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DomainResourceInner createOrUpdate(
        String resourceGroupName, String emailServiceName, String domainName, DomainResourceInner parameters) {
        return createOrUpdateAsync(resourceGroupName, emailServiceName, domainName, parameters).block();
    }

    /**
     * Create Or Update
     *
     * <p>Add a new Domains resource under the parent EmailService resource or update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the create or update operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DomainResourceInner createOrUpdate(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        DomainResourceInner parameters,
        Context context) {
        return createOrUpdateAsync(resourceGroupName, emailServiceName, domainName, parameters, context).block();
    }

    /**
     * Delete
     *
     * <p>Operation to delete a Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 resourceGroupName, String emailServiceName, String domainName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            emailServiceName,
                            domainName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete
     *
     * <p>Operation to delete a Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @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 resourceGroupName, String emailServiceName, String domainName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName 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(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                emailServiceName,
                domainName,
                accept,
                context);
    }

    /**
     * Delete
     *
     * <p>Operation to delete a Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 resourceGroupName, String emailServiceName, String domainName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, emailServiceName, domainName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Delete
     *
     * <p>Operation to delete a Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @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 resourceGroupName, String emailServiceName, String domainName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, emailServiceName, domainName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Delete
     *
     * <p>Operation to delete a Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 resourceGroupName, String emailServiceName, String domainName) {
        return this.beginDeleteAsync(resourceGroupName, emailServiceName, domainName).getSyncPoller();
    }

    /**
     * Delete
     *
     * <p>Operation to delete a Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @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 resourceGroupName, String emailServiceName, String domainName, Context context) {
        return this.beginDeleteAsync(resourceGroupName, emailServiceName, domainName, context).getSyncPoller();
    }

    /**
     * Delete
     *
     * <p>Operation to delete a Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String emailServiceName, String domainName) {
        return beginDeleteAsync(resourceGroupName, emailServiceName, domainName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete
     *
     * <p>Operation to delete a Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @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 resourceGroupName, String emailServiceName, String domainName, Context context) {
        return beginDeleteAsync(resourceGroupName, emailServiceName, domainName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete
     *
     * <p>Operation to delete a Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String emailServiceName, String domainName) {
        deleteAsync(resourceGroupName, emailServiceName, domainName).block();
    }

    /**
     * Delete
     *
     * <p>Operation to delete a Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @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 resourceGroupName, String emailServiceName, String domainName, Context context) {
        deleteAsync(resourceGroupName, emailServiceName, domainName, context).block();
    }

    /**
     * Update
     *
     * <p>Operation to update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the update 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 class representing a Domains resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        UpdateDomainRequestParameters parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .update(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            emailServiceName,
                            domainName,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Update
     *
     * <p>Operation to update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the update operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a class representing a Domains resource along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateWithResponseAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        UpdateDomainRequestParameters parameters,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .update(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                emailServiceName,
                domainName,
                parameters,
                accept,
                context);
    }

    /**
     * Update
     *
     * <p>Operation to update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the update 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 a class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DomainResourceInner>, DomainResourceInner> beginUpdateAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        UpdateDomainRequestParameters parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, emailServiceName, domainName, parameters);
        return this
            .client
            .<DomainResourceInner, DomainResourceInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                DomainResourceInner.class,
                DomainResourceInner.class,
                this.client.getContext());
    }

    /**
     * Update
     *
     * <p>Operation to update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the update operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of a class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<DomainResourceInner>, DomainResourceInner> beginUpdateAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        UpdateDomainRequestParameters parameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateWithResponseAsync(resourceGroupName, emailServiceName, domainName, parameters, context);
        return this
            .client
            .<DomainResourceInner, DomainResourceInner>getLroResult(
                mono, this.client.getHttpPipeline(), DomainResourceInner.class, DomainResourceInner.class, context);
    }

    /**
     * Update
     *
     * <p>Operation to update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the update 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 a class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DomainResourceInner>, DomainResourceInner> beginUpdate(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        UpdateDomainRequestParameters parameters) {
        return this.beginUpdateAsync(resourceGroupName, emailServiceName, domainName, parameters).getSyncPoller();
    }

    /**
     * Update
     *
     * <p>Operation to update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the update operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of a class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<DomainResourceInner>, DomainResourceInner> beginUpdate(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        UpdateDomainRequestParameters parameters,
        Context context) {
        return this
            .beginUpdateAsync(resourceGroupName, emailServiceName, domainName, parameters, context)
            .getSyncPoller();
    }

    /**
     * Update
     *
     * <p>Operation to update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the update 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 class representing a Domains resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DomainResourceInner> updateAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        UpdateDomainRequestParameters parameters) {
        return beginUpdateAsync(resourceGroupName, emailServiceName, domainName, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Update
     *
     * <p>Operation to update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the update operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a class representing a Domains resource on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<DomainResourceInner> updateAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        UpdateDomainRequestParameters parameters,
        Context context) {
        return beginUpdateAsync(resourceGroupName, emailServiceName, domainName, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Update
     *
     * <p>Operation to update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the update 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 class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DomainResourceInner update(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        UpdateDomainRequestParameters parameters) {
        return updateAsync(resourceGroupName, emailServiceName, domainName, parameters).block();
    }

    /**
     * Update
     *
     * <p>Operation to update an existing Domains resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Parameters for the update operation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a class representing a Domains resource.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public DomainResourceInner update(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        UpdateDomainRequestParameters parameters,
        Context context) {
        return updateAsync(resourceGroupName, emailServiceName, domainName, parameters, context).block();
    }

    /**
     * List by EmailService
     *
     * <p>Handles requests to list all Domains resources under the parent EmailServices resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return object that includes an array of Domains resource and a possible link for next set along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DomainResourceInner>> listByEmailServiceResourceSinglePageAsync(
        String resourceGroupName, String emailServiceName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByEmailServiceResource(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            emailServiceName,
                            accept,
                            context))
            .<PagedResponse<DomainResourceInner>>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 by EmailService
     *
     * <p>Handles requests to list all Domains resources under the parent EmailServices resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @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 object that includes an array of Domains resource and a possible link for next set along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DomainResourceInner>> listByEmailServiceResourceSinglePageAsync(
        String resourceGroupName, String emailServiceName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByEmailServiceResource(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                emailServiceName,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * List by EmailService
     *
     * <p>Handles requests to list all Domains resources under the parent EmailServices resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return object that includes an array of Domains resource and a possible link for next set as paginated response
     *     with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<DomainResourceInner> listByEmailServiceResourceAsync(
        String resourceGroupName, String emailServiceName) {
        return new PagedFlux<>(
            () -> listByEmailServiceResourceSinglePageAsync(resourceGroupName, emailServiceName),
            nextLink -> listByEmailServiceResourceNextSinglePageAsync(nextLink));
    }

    /**
     * List by EmailService
     *
     * <p>Handles requests to list all Domains resources under the parent EmailServices resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @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 object that includes an array of Domains resource and a possible link for next set as paginated response
     *     with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<DomainResourceInner> listByEmailServiceResourceAsync(
        String resourceGroupName, String emailServiceName, Context context) {
        return new PagedFlux<>(
            () -> listByEmailServiceResourceSinglePageAsync(resourceGroupName, emailServiceName, context),
            nextLink -> listByEmailServiceResourceNextSinglePageAsync(nextLink, context));
    }

    /**
     * List by EmailService
     *
     * <p>Handles requests to list all Domains resources under the parent EmailServices resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return object that includes an array of Domains resource and a possible link for next set as paginated response
     *     with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<DomainResourceInner> listByEmailServiceResource(
        String resourceGroupName, String emailServiceName) {
        return new PagedIterable<>(listByEmailServiceResourceAsync(resourceGroupName, emailServiceName));
    }

    /**
     * List by EmailService
     *
     * <p>Handles requests to list all Domains resources under the parent EmailServices resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @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 object that includes an array of Domains resource and a possible link for next set as paginated response
     *     with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<DomainResourceInner> listByEmailServiceResource(
        String resourceGroupName, String emailServiceName, Context context) {
        return new PagedIterable<>(listByEmailServiceResourceAsync(resourceGroupName, emailServiceName, context));
    }

    /**
     * Initiate Verification
     *
     * <p>Initiate verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be initiated.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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>>> initiateVerificationWithResponseAsync(
        String resourceGroupName, String emailServiceName, String domainName, VerificationParameter parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .initiateVerification(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            emailServiceName,
                            domainName,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Initiate Verification
     *
     * <p>Initiate verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be initiated.
     * @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>>> initiateVerificationWithResponseAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        VerificationParameter parameters,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .initiateVerification(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                emailServiceName,
                domainName,
                parameters,
                accept,
                context);
    }

    /**
     * Initiate Verification
     *
     * <p>Initiate verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be initiated.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> beginInitiateVerificationAsync(
        String resourceGroupName, String emailServiceName, String domainName, VerificationParameter parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            initiateVerificationWithResponseAsync(resourceGroupName, emailServiceName, domainName, parameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Initiate Verification
     *
     * <p>Initiate verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be initiated.
     * @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> beginInitiateVerificationAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        VerificationParameter parameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            initiateVerificationWithResponseAsync(resourceGroupName, emailServiceName, domainName, parameters, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Initiate Verification
     *
     * <p>Initiate verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be initiated.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> beginInitiateVerification(
        String resourceGroupName, String emailServiceName, String domainName, VerificationParameter parameters) {
        return this
            .beginInitiateVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters)
            .getSyncPoller();
    }

    /**
     * Initiate Verification
     *
     * <p>Initiate verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be initiated.
     * @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> beginInitiateVerification(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        VerificationParameter parameters,
        Context context) {
        return this
            .beginInitiateVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters, context)
            .getSyncPoller();
    }

    /**
     * Initiate Verification
     *
     * <p>Initiate verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be initiated.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> initiateVerificationAsync(
        String resourceGroupName, String emailServiceName, String domainName, VerificationParameter parameters) {
        return beginInitiateVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Initiate Verification
     *
     * <p>Initiate verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be initiated.
     * @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> initiateVerificationAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        VerificationParameter parameters,
        Context context) {
        return beginInitiateVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Initiate Verification
     *
     * <p>Initiate verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be initiated.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 initiateVerification(
        String resourceGroupName, String emailServiceName, String domainName, VerificationParameter parameters) {
        initiateVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters).block();
    }

    /**
     * Initiate Verification
     *
     * <p>Initiate verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be initiated.
     * @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 initiateVerification(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        VerificationParameter parameters,
        Context context) {
        initiateVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters, context).block();
    }

    /**
     * Cancel Verification
     *
     * <p>Cancel verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be canceled.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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>>> cancelVerificationWithResponseAsync(
        String resourceGroupName, String emailServiceName, String domainName, VerificationParameter parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .cancelVerification(
                            this.client.getEndpoint(),
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            resourceGroupName,
                            emailServiceName,
                            domainName,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Cancel Verification
     *
     * <p>Cancel verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be canceled.
     * @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>>> cancelVerificationWithResponseAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        VerificationParameter parameters,
        Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (emailServiceName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter emailServiceName is required and cannot be null."));
        }
        if (domainName == null) {
            return Mono.error(new IllegalArgumentException("Parameter domainName is required and cannot be null."));
        }
        if (parameters == null) {
            return Mono.error(new IllegalArgumentException("Parameter parameters is required and cannot be null."));
        } else {
            parameters.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .cancelVerification(
                this.client.getEndpoint(),
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                resourceGroupName,
                emailServiceName,
                domainName,
                parameters,
                accept,
                context);
    }

    /**
     * Cancel Verification
     *
     * <p>Cancel verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be canceled.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> beginCancelVerificationAsync(
        String resourceGroupName, String emailServiceName, String domainName, VerificationParameter parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            cancelVerificationWithResponseAsync(resourceGroupName, emailServiceName, domainName, parameters);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Cancel Verification
     *
     * <p>Cancel verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be canceled.
     * @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> beginCancelVerificationAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        VerificationParameter parameters,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            cancelVerificationWithResponseAsync(resourceGroupName, emailServiceName, domainName, parameters, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Cancel Verification
     *
     * <p>Cancel verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be canceled.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> beginCancelVerification(
        String resourceGroupName, String emailServiceName, String domainName, VerificationParameter parameters) {
        return this
            .beginCancelVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters)
            .getSyncPoller();
    }

    /**
     * Cancel Verification
     *
     * <p>Cancel verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be canceled.
     * @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> beginCancelVerification(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        VerificationParameter parameters,
        Context context) {
        return this
            .beginCancelVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters, context)
            .getSyncPoller();
    }

    /**
     * Cancel Verification
     *
     * <p>Cancel verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be canceled.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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> cancelVerificationAsync(
        String resourceGroupName, String emailServiceName, String domainName, VerificationParameter parameters) {
        return beginCancelVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Cancel Verification
     *
     * <p>Cancel verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be canceled.
     * @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> cancelVerificationAsync(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        VerificationParameter parameters,
        Context context) {
        return beginCancelVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Cancel Verification
     *
     * <p>Cancel verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be canceled.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 cancelVerification(
        String resourceGroupName, String emailServiceName, String domainName, VerificationParameter parameters) {
        cancelVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters).block();
    }

    /**
     * Cancel Verification
     *
     * <p>Cancel verification of DNS record.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param emailServiceName The name of the EmailService resource.
     * @param domainName The name of the Domains resource.
     * @param parameters Type of verification to be canceled.
     * @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 cancelVerification(
        String resourceGroupName,
        String emailServiceName,
        String domainName,
        VerificationParameter parameters,
        Context context) {
        cancelVerificationAsync(resourceGroupName, emailServiceName, domainName, parameters, 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 object that includes an array of Domains resource and a possible link for next set along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DomainResourceInner>> listByEmailServiceResourceNextSinglePageAsync(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.listByEmailServiceResourceNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<DomainResourceInner>>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 object that includes an array of Domains resource and a possible link for next set along with {@link
     *     PagedResponse} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<DomainResourceInner>> listByEmailServiceResourceNextSinglePageAsync(
        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
            .listByEmailServiceResourceNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
