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

package com.azure.resourcemanager.orbital.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.Patch;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.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.orbital.fluent.ContactProfilesClient;
import com.azure.resourcemanager.orbital.fluent.models.ContactProfileInner;
import com.azure.resourcemanager.orbital.models.ContactProfileListResult;
import com.azure.resourcemanager.orbital.models.TagsObject;
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 ContactProfilesClient. */
public final class ContactProfilesClientImpl implements ContactProfilesClient {
    /** The proxy service used to perform REST calls. */
    private final ContactProfilesService service;

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

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

    /**
     * The interface defining all the services for AzureOrbitalContactProfiles to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "AzureOrbitalContactP")
    public interface ContactProfilesService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Orbital/contactProfiles/{contactProfileName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ContactProfileInner>> getByResourceGroup(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("contactProfileName") String contactProfileName,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

        @Headers({"Content-Type: application/json"})
        @Patch(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Orbital/contactProfiles/{contactProfileName}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> updateTags(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @PathParam("contactProfileName") String contactProfileName,
            @BodyParam("application/json") TagsObject parameters,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Get("/subscriptions/{subscriptionId}/providers/Microsoft.Orbital/contactProfiles")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<ContactProfileListResult>> list(
            @HostParam("$host") String endpoint,
            @PathParam("subscriptionId") String subscriptionId,
            @QueryParam("api-version") String apiVersion,
            @QueryParam("$skiptoken") String skiptoken,
            @HeaderParam("Accept") String accept,
            Context context);

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

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

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

    /**
     * Gets the specified contact Profile in a specified resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the specified contact Profile in a specified resource group along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ContactProfileInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String contactProfileName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (contactProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter contactProfileName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .getByResourceGroup(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            contactProfileName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets the specified contact Profile in a specified resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the specified contact Profile in a specified resource group along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<ContactProfileInner>> getByResourceGroupWithResponseAsync(
        String resourceGroupName, String contactProfileName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (contactProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter contactProfileName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .getByResourceGroup(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                contactProfileName,
                accept,
                context);
    }

    /**
     * Gets the specified contact Profile in a specified resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the specified contact Profile in a specified resource group on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ContactProfileInner> getByResourceGroupAsync(String resourceGroupName, String contactProfileName) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, contactProfileName)
            .flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets the specified contact Profile in a specified resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the specified contact Profile in a specified resource group along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<ContactProfileInner> getByResourceGroupWithResponse(
        String resourceGroupName, String contactProfileName, Context context) {
        return getByResourceGroupWithResponseAsync(resourceGroupName, contactProfileName, context).block();
    }

    /**
     * Gets the specified contact Profile in a specified resource group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the specified contact Profile in a specified resource group.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ContactProfileInner getByResourceGroup(String resourceGroupName, String contactProfileName) {
        return getByResourceGroupWithResponse(resourceGroupName, contactProfileName, Context.NONE).getValue();
    }

    /**
     * Creates or updates a contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters The parameters to provide for the created Contact Profile.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String contactProfileName, ContactProfileInner parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (contactProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter contactProfileName 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(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            contactProfileName,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates a contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters The parameters to provide for the created Contact Profile.
     * @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 customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName, String contactProfileName, ContactProfileInner parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (contactProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter contactProfileName 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(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                contactProfileName,
                parameters,
                accept,
                context);
    }

    /**
     * Creates or updates a contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters The parameters to provide for the created Contact Profile.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 customer creates a Contact Profile Resource, which will contain all
     *     of the configurations required for scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ContactProfileInner>, ContactProfileInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String contactProfileName, ContactProfileInner parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, contactProfileName, parameters);
        return this
            .client
            .<ContactProfileInner, ContactProfileInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ContactProfileInner.class,
                ContactProfileInner.class,
                this.client.getContext());
    }

    /**
     * Creates or updates a contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters The parameters to provide for the created Contact Profile.
     * @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 customer creates a Contact Profile Resource, which will contain all
     *     of the configurations required for scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ContactProfileInner>, ContactProfileInner> beginCreateOrUpdateAsync(
        String resourceGroupName, String contactProfileName, ContactProfileInner parameters, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(resourceGroupName, contactProfileName, parameters, context);
        return this
            .client
            .<ContactProfileInner, ContactProfileInner>getLroResult(
                mono, this.client.getHttpPipeline(), ContactProfileInner.class, ContactProfileInner.class, context);
    }

    /**
     * Creates or updates a contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters The parameters to provide for the created Contact Profile.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 customer creates a Contact Profile Resource, which will contain all
     *     of the configurations required for scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ContactProfileInner>, ContactProfileInner> beginCreateOrUpdate(
        String resourceGroupName, String contactProfileName, ContactProfileInner parameters) {
        return this.beginCreateOrUpdateAsync(resourceGroupName, contactProfileName, parameters).getSyncPoller();
    }

    /**
     * Creates or updates a contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters The parameters to provide for the created Contact Profile.
     * @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 customer creates a Contact Profile Resource, which will contain all
     *     of the configurations required for scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ContactProfileInner>, ContactProfileInner> beginCreateOrUpdate(
        String resourceGroupName, String contactProfileName, ContactProfileInner parameters, Context context) {
        return this
            .beginCreateOrUpdateAsync(resourceGroupName, contactProfileName, parameters, context)
            .getSyncPoller();
    }

    /**
     * Creates or updates a contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters The parameters to provide for the created Contact Profile.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ContactProfileInner> createOrUpdateAsync(
        String resourceGroupName, String contactProfileName, ContactProfileInner parameters) {
        return beginCreateOrUpdateAsync(resourceGroupName, contactProfileName, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates a contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters The parameters to provide for the created Contact Profile.
     * @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 customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ContactProfileInner> createOrUpdateAsync(
        String resourceGroupName, String contactProfileName, ContactProfileInner parameters, Context context) {
        return beginCreateOrUpdateAsync(resourceGroupName, contactProfileName, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates a contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters The parameters to provide for the created Contact Profile.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ContactProfileInner createOrUpdate(
        String resourceGroupName, String contactProfileName, ContactProfileInner parameters) {
        return createOrUpdateAsync(resourceGroupName, contactProfileName, parameters).block();
    }

    /**
     * Creates or updates a contact profile.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters The parameters to provide for the created Contact Profile.
     * @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 customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ContactProfileInner createOrUpdate(
        String resourceGroupName, String contactProfileName, ContactProfileInner parameters, Context context) {
        return createOrUpdateAsync(resourceGroupName, contactProfileName, parameters, context).block();
    }

    /**
     * Deletes a specified contact profile resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String contactProfileName) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (contactProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter contactProfileName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .delete(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            contactProfileName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes a specified contact profile resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> deleteWithResponseAsync(
        String resourceGroupName, String contactProfileName, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (contactProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter contactProfileName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .delete(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                contactProfileName,
                accept,
                context);
    }

    /**
     * Deletes a specified contact profile resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(String resourceGroupName, String contactProfileName) {
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(resourceGroupName, contactProfileName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Deletes a specified contact profile resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<Void>, Void> beginDeleteAsync(
        String resourceGroupName, String contactProfileName, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono = deleteWithResponseAsync(resourceGroupName, contactProfileName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Deletes a specified contact profile resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(String resourceGroupName, String contactProfileName) {
        return this.beginDeleteAsync(resourceGroupName, contactProfileName).getSyncPoller();
    }

    /**
     * Deletes a specified contact profile resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<Void>, Void> beginDelete(
        String resourceGroupName, String contactProfileName, Context context) {
        return this.beginDeleteAsync(resourceGroupName, contactProfileName, context).getSyncPoller();
    }

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

    /**
     * Deletes a specified contact profile resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Void> deleteAsync(String resourceGroupName, String contactProfileName, Context context) {
        return beginDeleteAsync(resourceGroupName, contactProfileName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes a specified contact profile resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String contactProfileName) {
        deleteAsync(resourceGroupName, contactProfileName).block();
    }

    /**
     * Deletes a specified contact profile resource.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String resourceGroupName, String contactProfileName, Context context) {
        deleteAsync(resourceGroupName, contactProfileName, context).block();
    }

    /**
     * Updates the specified contact profile tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters Parameters supplied to update contact profile tags.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateTagsWithResponseAsync(
        String resourceGroupName, String contactProfileName, TagsObject parameters) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (contactProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter contactProfileName 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
                        .updateTags(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            contactProfileName,
                            parameters,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Updates the specified contact profile tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters Parameters supplied to update contact profile tags.
     * @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 customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> updateTagsWithResponseAsync(
        String resourceGroupName, String contactProfileName, TagsObject parameters, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName 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 (contactProfileName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter contactProfileName 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
            .updateTags(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                contactProfileName,
                parameters,
                accept,
                context);
    }

    /**
     * Updates the specified contact profile tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters Parameters supplied to update contact profile tags.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 customer creates a Contact Profile Resource, which will contain all
     *     of the configurations required for scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ContactProfileInner>, ContactProfileInner> beginUpdateTagsAsync(
        String resourceGroupName, String contactProfileName, TagsObject parameters) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateTagsWithResponseAsync(resourceGroupName, contactProfileName, parameters);
        return this
            .client
            .<ContactProfileInner, ContactProfileInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                ContactProfileInner.class,
                ContactProfileInner.class,
                this.client.getContext());
    }

    /**
     * Updates the specified contact profile tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters Parameters supplied to update contact profile tags.
     * @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 customer creates a Contact Profile Resource, which will contain all
     *     of the configurations required for scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<ContactProfileInner>, ContactProfileInner> beginUpdateTagsAsync(
        String resourceGroupName, String contactProfileName, TagsObject parameters, Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            updateTagsWithResponseAsync(resourceGroupName, contactProfileName, parameters, context);
        return this
            .client
            .<ContactProfileInner, ContactProfileInner>getLroResult(
                mono, this.client.getHttpPipeline(), ContactProfileInner.class, ContactProfileInner.class, context);
    }

    /**
     * Updates the specified contact profile tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters Parameters supplied to update contact profile tags.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws 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 customer creates a Contact Profile Resource, which will contain all
     *     of the configurations required for scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ContactProfileInner>, ContactProfileInner> beginUpdateTags(
        String resourceGroupName, String contactProfileName, TagsObject parameters) {
        return this.beginUpdateTagsAsync(resourceGroupName, contactProfileName, parameters).getSyncPoller();
    }

    /**
     * Updates the specified contact profile tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters Parameters supplied to update contact profile tags.
     * @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 customer creates a Contact Profile Resource, which will contain all
     *     of the configurations required for scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ContactProfileInner>, ContactProfileInner> beginUpdateTags(
        String resourceGroupName, String contactProfileName, TagsObject parameters, Context context) {
        return this.beginUpdateTagsAsync(resourceGroupName, contactProfileName, parameters, context).getSyncPoller();
    }

    /**
     * Updates the specified contact profile tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters Parameters supplied to update contact profile tags.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ContactProfileInner> updateTagsAsync(
        String resourceGroupName, String contactProfileName, TagsObject parameters) {
        return beginUpdateTagsAsync(resourceGroupName, contactProfileName, parameters)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates the specified contact profile tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters Parameters supplied to update contact profile tags.
     * @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 customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ContactProfileInner> updateTagsAsync(
        String resourceGroupName, String contactProfileName, TagsObject parameters, Context context) {
        return beginUpdateTagsAsync(resourceGroupName, contactProfileName, parameters, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Updates the specified contact profile tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters Parameters supplied to update contact profile tags.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ContactProfileInner updateTags(String resourceGroupName, String contactProfileName, TagsObject parameters) {
        return updateTagsAsync(resourceGroupName, contactProfileName, parameters).block();
    }

    /**
     * Updates the specified contact profile tags.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param contactProfileName Contact Profile name.
     * @param parameters Parameters supplied to update contact profile tags.
     * @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 customer creates a Contact Profile Resource, which will contain all of the configurations required for
     *     scheduling a contact.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ContactProfileInner updateTags(
        String resourceGroupName, String contactProfileName, TagsObject parameters, Context context) {
        return updateTagsAsync(resourceGroupName, contactProfileName, parameters, context).block();
    }

    /**
     * Returns list of contact profiles by Subscription.
     *
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response for the ListContactProfiles API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ContactProfileInner>> listSinglePageAsync(String skiptoken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .list(
                            this.client.getEndpoint(),
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            skiptoken,
                            accept,
                            context))
            .<PagedResponse<ContactProfileInner>>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()));
    }

    /**
     * Returns list of contact profiles by Subscription.
     *
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListContactProfiles API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ContactProfileInner>> listSinglePageAsync(String skiptoken, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .list(
                this.client.getEndpoint(),
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                skiptoken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Returns list of contact profiles by Subscription.
     *
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response for the ListContactProfiles API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ContactProfileInner> listAsync(String skiptoken) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(skiptoken), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Returns list of contact profiles by Subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response for the ListContactProfiles API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ContactProfileInner> listAsync() {
        final String skiptoken = null;
        return new PagedFlux<>(
            () -> listSinglePageAsync(skiptoken), nextLink -> listBySubscriptionNextSinglePageAsync(nextLink));
    }

    /**
     * Returns list of contact profiles by Subscription.
     *
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListContactProfiles API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ContactProfileInner> listAsync(String skiptoken, Context context) {
        return new PagedFlux<>(
            () -> listSinglePageAsync(skiptoken, context),
            nextLink -> listBySubscriptionNextSinglePageAsync(nextLink, context));
    }

    /**
     * Returns list of contact profiles by Subscription.
     *
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response for the ListContactProfiles API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ContactProfileInner> list() {
        final String skiptoken = null;
        return new PagedIterable<>(listAsync(skiptoken));
    }

    /**
     * Returns list of contact profiles by Subscription.
     *
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListContactProfiles API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ContactProfileInner> list(String skiptoken, Context context) {
        return new PagedIterable<>(listAsync(skiptoken, context));
    }

    /**
     * Returns list of contact profiles by Resource Group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response for the ListContactProfiles API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ContactProfileInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, String skiptoken) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .listByResourceGroup(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getSubscriptionId(),
                            this.client.getApiVersion(),
                            skiptoken,
                            accept,
                            context))
            .<PagedResponse<ContactProfileInner>>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()));
    }

    /**
     * Returns list of contact profiles by Resource Group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListContactProfiles API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ContactProfileInner>> listByResourceGroupSinglePageAsync(
        String resourceGroupName, String skiptoken, Context context) {
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        if (resourceGroupName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter resourceGroupName is required and cannot be null."));
        }
        if (this.client.getSubscriptionId() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getSubscriptionId() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listByResourceGroup(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getSubscriptionId(),
                this.client.getApiVersion(),
                skiptoken,
                accept,
                context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }

    /**
     * Returns list of contact profiles by Resource Group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response for the ListContactProfiles API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ContactProfileInner> listByResourceGroupAsync(String resourceGroupName, String skiptoken) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, skiptoken),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Returns list of contact profiles by Resource Group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response for the ListContactProfiles API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ContactProfileInner> listByResourceGroupAsync(String resourceGroupName) {
        final String skiptoken = null;
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, skiptoken),
            nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Returns list of contact profiles by Resource Group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListContactProfiles API service call as paginated response with {@link PagedFlux}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    private PagedFlux<ContactProfileInner> listByResourceGroupAsync(
        String resourceGroupName, String skiptoken, Context context) {
        return new PagedFlux<>(
            () -> listByResourceGroupSinglePageAsync(resourceGroupName, skiptoken, context),
            nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Returns list of contact profiles by Resource Group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response for the ListContactProfiles API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ContactProfileInner> listByResourceGroup(String resourceGroupName) {
        final String skiptoken = null;
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, skiptoken));
    }

    /**
     * Returns list of contact profiles by Resource Group.
     *
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param skiptoken An opaque string that the resource provider uses to skip over previously-returned results. This
     *     is used when a previous list operation call returned a partial result. If a previous response contains a
     *     nextLink element, the value of the nextLink element will include a skiptoken parameter that specifies a
     *     starting point to use for subsequent calls.
     * @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 response for the ListContactProfiles API service call as paginated response with {@link PagedIterable}.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<ContactProfileInner> listByResourceGroup(
        String resourceGroupName, String skiptoken, Context context) {
        return new PagedIterable<>(listByResourceGroupAsync(resourceGroupName, skiptoken, context));
    }

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

    /**
     * Get the next page of items.
     *
     * @param nextLink The URL to get the next list of items
     *     <p>The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return response for the ListContactProfiles API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ContactProfileInner>> listNextSinglePageAsync(String nextLink) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context))
            .<PagedResponse<ContactProfileInner>>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 response for the ListContactProfiles API service call along with {@link PagedResponse} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<PagedResponse<ContactProfileInner>> listNextSinglePageAsync(String nextLink, Context context) {
        if (nextLink == null) {
            return Mono.error(new IllegalArgumentException("Parameter nextLink is required and cannot be null."));
        }
        if (this.client.getEndpoint() == null) {
            return Mono
                .error(
                    new IllegalArgumentException(
                        "Parameter this.client.getEndpoint() is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .listNext(nextLink, this.client.getEndpoint(), accept, context)
            .map(
                res ->
                    new PagedResponseBase<>(
                        res.getRequest(),
                        res.getStatusCode(),
                        res.getHeaders(),
                        res.getValue().value(),
                        res.getValue().nextLink(),
                        null));
    }
}
