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

package com.azure.resourcemanager.healthcareapis.implementation;

import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.Headers;
import com.azure.core.annotation.Host;
import com.azure.core.annotation.HostParam;
import com.azure.core.annotation.PathParam;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.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.healthcareapis.fluent.IotConnectorFhirDestinationsClient;
import com.azure.resourcemanager.healthcareapis.fluent.models.IotFhirDestinationInner;
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 IotConnectorFhirDestinationsClient. */
public final class IotConnectorFhirDestinationsClientImpl implements IotConnectorFhirDestinationsClient {
    /** The proxy service used to perform REST calls. */
    private final IotConnectorFhirDestinationsService service;

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

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

    /**
     * The interface defining all the services for HealthcareApisManagementClientIotConnectorFhirDestinations to be used
     * by the proxy service to perform REST calls.
     */
    @Host("{$host}")
    @ServiceInterface(name = "HealthcareApisManage")
    private interface IotConnectorFhirDestinationsService {
        @Headers({"Content-Type: application/json"})
        @Get(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HealthcareApis"
                + "/workspaces/{workspaceName}/iotconnectors/{iotConnectorName}/fhirdestinations/{fhirDestinationName}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<IotFhirDestinationInner>> get(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("workspaceName") String workspaceName,
            @PathParam("iotConnectorName") String iotConnectorName,
            @PathParam("fhirDestinationName") String fhirDestinationName,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Put(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HealthcareApis"
                + "/workspaces/{workspaceName}/iotconnectors/{iotConnectorName}/fhirdestinations/{fhirDestinationName}")
        @ExpectedResponses({200, 201, 202})
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(
            @HostParam("$host") String endpoint,
            @PathParam("resourceGroupName") String resourceGroupName,
            @QueryParam("api-version") String apiVersion,
            @PathParam("subscriptionId") String subscriptionId,
            @PathParam("workspaceName") String workspaceName,
            @PathParam("iotConnectorName") String iotConnectorName,
            @PathParam("fhirDestinationName") String fhirDestinationName,
            @BodyParam("application/json") IotFhirDestinationInner iotFhirDestination,
            @HeaderParam("Accept") String accept,
            Context context);

        @Headers({"Content-Type: application/json"})
        @Delete(
            "/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.HealthcareApis"
                + "/workspaces/{workspaceName}/iotconnectors/{iotConnectorName}/fhirdestinations/{fhirDestinationName}")
        @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("workspaceName") String workspaceName,
            @PathParam("iotConnectorName") String iotConnectorName,
            @PathParam("fhirDestinationName") String fhirDestinationName,
            @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * Gets the properties of the specified Iot Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 properties of the specified Iot Connector FHIR destination along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<IotFhirDestinationInner>> getWithResponseAsync(
        String resourceGroupName, String workspaceName, String iotConnectorName, String fhirDestinationName) {
        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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName is required and cannot be null."));
        }
        if (iotConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter iotConnectorName is required and cannot be null."));
        }
        if (fhirDestinationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter fhirDestinationName is required and cannot be null."));
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .get(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            workspaceName,
                            iotConnectorName,
                            fhirDestinationName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Gets the properties of the specified Iot Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 properties of the specified Iot Connector FHIR destination along with {@link Response} on successful
     *     completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<IotFhirDestinationInner>> getWithResponseAsync(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName is required and cannot be null."));
        }
        if (iotConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter iotConnectorName is required and cannot be null."));
        }
        if (fhirDestinationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter fhirDestinationName is required and cannot be null."));
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .get(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                workspaceName,
                iotConnectorName,
                fhirDestinationName,
                accept,
                context);
    }

    /**
     * Gets the properties of the specified Iot Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 properties of the specified Iot Connector FHIR destination on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<IotFhirDestinationInner> getAsync(
        String resourceGroupName, String workspaceName, String iotConnectorName, String fhirDestinationName) {
        return getWithResponseAsync(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName)
            .flatMap(
                (Response<IotFhirDestinationInner> res) -> {
                    if (res.getValue() != null) {
                        return Mono.just(res.getValue());
                    } else {
                        return Mono.empty();
                    }
                });
    }

    /**
     * Gets the properties of the specified Iot Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 properties of the specified Iot Connector FHIR destination.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public IotFhirDestinationInner get(
        String resourceGroupName, String workspaceName, String iotConnectorName, String fhirDestinationName) {
        return getAsync(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName).block();
    }

    /**
     * Gets the properties of the specified Iot Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 properties of the specified Iot Connector FHIR destination along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<IotFhirDestinationInner> getWithResponse(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        Context context) {
        return getWithResponseAsync(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, context)
            .block();
    }

    /**
     * Creates or updates an IoT Connector FHIR destination resource with the specified parameters.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination resource.
     * @param iotFhirDestination The parameters for creating or updating an IoT Connector FHIR destination 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 ioT Connector FHIR destination definition along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        IotFhirDestinationInner iotFhirDestination) {
        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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName is required and cannot be null."));
        }
        if (iotConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter iotConnectorName is required and cannot be null."));
        }
        if (fhirDestinationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter fhirDestinationName is required and cannot be null."));
        }
        if (iotFhirDestination == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter iotFhirDestination is required and cannot be null."));
        } else {
            iotFhirDestination.validate();
        }
        final String accept = "application/json";
        return FluxUtil
            .withContext(
                context ->
                    service
                        .createOrUpdate(
                            this.client.getEndpoint(),
                            resourceGroupName,
                            this.client.getApiVersion(),
                            this.client.getSubscriptionId(),
                            workspaceName,
                            iotConnectorName,
                            fhirDestinationName,
                            iotFhirDestination,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Creates or updates an IoT Connector FHIR destination resource with the specified parameters.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination resource.
     * @param iotFhirDestination The parameters for creating or updating an IoT Connector FHIR destination 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 ioT Connector FHIR destination definition along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        IotFhirDestinationInner iotFhirDestination,
        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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName is required and cannot be null."));
        }
        if (iotConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter iotConnectorName is required and cannot be null."));
        }
        if (fhirDestinationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter fhirDestinationName is required and cannot be null."));
        }
        if (iotFhirDestination == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter iotFhirDestination is required and cannot be null."));
        } else {
            iotFhirDestination.validate();
        }
        final String accept = "application/json";
        context = this.client.mergeContext(context);
        return service
            .createOrUpdate(
                this.client.getEndpoint(),
                resourceGroupName,
                this.client.getApiVersion(),
                this.client.getSubscriptionId(),
                workspaceName,
                iotConnectorName,
                fhirDestinationName,
                iotFhirDestination,
                accept,
                context);
    }

    /**
     * Creates or updates an IoT Connector FHIR destination resource with the specified parameters.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination resource.
     * @param iotFhirDestination The parameters for creating or updating an IoT Connector FHIR destination 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 ioT Connector FHIR destination definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<IotFhirDestinationInner>, IotFhirDestinationInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        IotFhirDestinationInner iotFhirDestination) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, iotFhirDestination);
        return this
            .client
            .<IotFhirDestinationInner, IotFhirDestinationInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                IotFhirDestinationInner.class,
                IotFhirDestinationInner.class,
                this.client.getContext());
    }

    /**
     * Creates or updates an IoT Connector FHIR destination resource with the specified parameters.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination resource.
     * @param iotFhirDestination The parameters for creating or updating an IoT Connector FHIR destination 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 ioT Connector FHIR destination definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<IotFhirDestinationInner>, IotFhirDestinationInner> beginCreateOrUpdateAsync(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        IotFhirDestinationInner iotFhirDestination,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            createOrUpdateWithResponseAsync(
                resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, iotFhirDestination, context);
        return this
            .client
            .<IotFhirDestinationInner, IotFhirDestinationInner>getLroResult(
                mono,
                this.client.getHttpPipeline(),
                IotFhirDestinationInner.class,
                IotFhirDestinationInner.class,
                context);
    }

    /**
     * Creates or updates an IoT Connector FHIR destination resource with the specified parameters.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination resource.
     * @param iotFhirDestination The parameters for creating or updating an IoT Connector FHIR destination 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 ioT Connector FHIR destination definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<IotFhirDestinationInner>, IotFhirDestinationInner> beginCreateOrUpdate(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        IotFhirDestinationInner iotFhirDestination) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, iotFhirDestination)
            .getSyncPoller();
    }

    /**
     * Creates or updates an IoT Connector FHIR destination resource with the specified parameters.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination resource.
     * @param iotFhirDestination The parameters for creating or updating an IoT Connector FHIR destination 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 ioT Connector FHIR destination definition.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<IotFhirDestinationInner>, IotFhirDestinationInner> beginCreateOrUpdate(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        IotFhirDestinationInner iotFhirDestination,
        Context context) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, iotFhirDestination, context)
            .getSyncPoller();
    }

    /**
     * Creates or updates an IoT Connector FHIR destination resource with the specified parameters.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination resource.
     * @param iotFhirDestination The parameters for creating or updating an IoT Connector FHIR destination 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 ioT Connector FHIR destination definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<IotFhirDestinationInner> createOrUpdateAsync(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        IotFhirDestinationInner iotFhirDestination) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, iotFhirDestination)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates an IoT Connector FHIR destination resource with the specified parameters.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination resource.
     * @param iotFhirDestination The parameters for creating or updating an IoT Connector FHIR destination 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 ioT Connector FHIR destination definition on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<IotFhirDestinationInner> createOrUpdateAsync(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        IotFhirDestinationInner iotFhirDestination,
        Context context) {
        return beginCreateOrUpdateAsync(
                resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, iotFhirDestination, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Creates or updates an IoT Connector FHIR destination resource with the specified parameters.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination resource.
     * @param iotFhirDestination The parameters for creating or updating an IoT Connector FHIR destination 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 ioT Connector FHIR destination definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public IotFhirDestinationInner createOrUpdate(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        IotFhirDestinationInner iotFhirDestination) {
        return createOrUpdateAsync(
                resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, iotFhirDestination)
            .block();
    }

    /**
     * Creates or updates an IoT Connector FHIR destination resource with the specified parameters.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination resource.
     * @param iotFhirDestination The parameters for creating or updating an IoT Connector FHIR destination 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 ioT Connector FHIR destination definition.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public IotFhirDestinationInner createOrUpdate(
        String resourceGroupName,
        String workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        IotFhirDestinationInner iotFhirDestination,
        Context context) {
        return createOrUpdateAsync(
                resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, iotFhirDestination, context)
            .block();
    }

    /**
     * Deletes an IoT Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 workspaceName, String iotConnectorName, String fhirDestinationName) {
        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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName is required and cannot be null."));
        }
        if (iotConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter iotConnectorName is required and cannot be null."));
        }
        if (fhirDestinationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter fhirDestinationName 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,
                            workspaceName,
                            iotConnectorName,
                            fhirDestinationName,
                            accept,
                            context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Deletes an IoT Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        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 (workspaceName == null) {
            return Mono.error(new IllegalArgumentException("Parameter workspaceName is required and cannot be null."));
        }
        if (iotConnectorName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter iotConnectorName is required and cannot be null."));
        }
        if (fhirDestinationName == null) {
            return Mono
                .error(new IllegalArgumentException("Parameter fhirDestinationName 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,
                workspaceName,
                iotConnectorName,
                fhirDestinationName,
                accept,
                context);
    }

    /**
     * Deletes an IoT Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 workspaceName, String iotConnectorName, String fhirDestinationName) {
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName);
        return this
            .client
            .<Void, Void>getLroResult(
                mono, this.client.getHttpPipeline(), Void.class, Void.class, this.client.getContext());
    }

    /**
     * Deletes an IoT Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        Context context) {
        context = this.client.mergeContext(context);
        Mono<Response<Flux<ByteBuffer>>> mono =
            deleteWithResponseAsync(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, context);
        return this
            .client
            .<Void, Void>getLroResult(mono, this.client.getHttpPipeline(), Void.class, Void.class, context);
    }

    /**
     * Deletes an IoT Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 workspaceName, String iotConnectorName, String fhirDestinationName) {
        return beginDeleteAsync(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName)
            .getSyncPoller();
    }

    /**
     * Deletes an IoT Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        Context context) {
        return beginDeleteAsync(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, context)
            .getSyncPoller();
    }

    /**
     * Deletes an IoT Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 workspaceName, String iotConnectorName, String fhirDestinationName) {
        return beginDeleteAsync(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes an IoT Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        Context context) {
        return beginDeleteAsync(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, context)
            .last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Deletes an IoT Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 workspaceName, String iotConnectorName, String fhirDestinationName) {
        deleteAsync(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName).block();
    }

    /**
     * Deletes an IoT Connector FHIR destination.
     *
     * @param resourceGroupName The name of the resource group that contains the service instance.
     * @param workspaceName The name of workspace resource.
     * @param iotConnectorName The name of IoT Connector resource.
     * @param fhirDestinationName The name of IoT Connector FHIR destination 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 workspaceName,
        String iotConnectorName,
        String fhirDestinationName,
        Context context) {
        deleteAsync(resourceGroupName, workspaceName, iotConnectorName, fhirDestinationName, context).block();
    }
}
