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

package azure.resourcemanager.operationtemplates.implementation;

import azure.resourcemanager.operationtemplates.fluent.LroesClient;
import azure.resourcemanager.operationtemplates.fluent.models.ExportResultInner;
import azure.resourcemanager.operationtemplates.fluent.models.OrderInner;
import azure.resourcemanager.operationtemplates.models.ExportRequest;
import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
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.Post;
import com.azure.core.annotation.Put;
import com.azure.core.annotation.QueryParam;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceInterface;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.annotation.UnexpectedResponseExceptionType;
import com.azure.core.http.rest.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.BinaryData;
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.core.util.serializer.TypeReference;
import java.nio.ByteBuffer;
import java.util.List;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for OperationTemplatesClientLroes to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "OperationTemplatesClientLroes")
    public interface LroesService {
        @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.OperationTemplates/orders/{orderName}")
        @ExpectedResponses({ 200, 201 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrReplace(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName, @PathParam("orderName") String orderName,
            @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
            @BodyParam("application/json") OrderInner resource, Context context);

        @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.OperationTemplates/orders/{orderName}")
        @ExpectedResponses({ 200, 201 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Response<BinaryData> createOrReplaceSync(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName, @PathParam("orderName") String orderName,
            @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
            @BodyParam("application/json") OrderInner resource, Context context);

        @Post("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.OperationTemplates/orders/{orderName}/export")
        @ExpectedResponses({ 200, 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> export(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName, @PathParam("orderName") String orderName,
            @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
            @BodyParam("application/json") ExportRequest body, Context context);

        @Post("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.OperationTemplates/orders/{orderName}/export")
        @ExpectedResponses({ 200, 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Response<BinaryData> exportSync(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName, @PathParam("orderName") String orderName,
            @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
            @BodyParam("application/json") ExportRequest body, Context context);

        @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" })
        @Delete("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.OperationTemplates/orders/{orderName}")
        @ExpectedResponses({ 202, 204 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> delete(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName, @PathParam("orderName") String orderName,
            Context context);

        @Headers({ "Accept: application/json;q=0.9", "Content-Type: application/json" })
        @Delete("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.OperationTemplates/orders/{orderName}")
        @ExpectedResponses({ 202, 204 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Response<BinaryData> deleteSync(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName, @PathParam("orderName") String orderName,
            Context context);

        @Post("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.OperationTemplates/exportArray")
        @ExpectedResponses({ 200, 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> exportArray(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
            @BodyParam("application/json") ExportRequest body, Context context);

        @Post("/subscriptions/{subscriptionId}/providers/Azure.ResourceManager.OperationTemplates/exportArray")
        @ExpectedResponses({ 200, 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Response<BinaryData> exportArraySync(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @HeaderParam("Content-Type") String contentType, @HeaderParam("Accept") String accept,
            @BodyParam("application/json") ExportRequest body, Context context);
    }

    /**
     * Create a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param resource Resource create parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return concrete tracked resource types can be created by aliasing this type using a specific property type along
     * with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> createOrReplaceWithResponseAsync(String resourceGroupName,
        String orderName, OrderInner resource) {
        final String contentType = "application/json";
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.createOrReplace(this.client.getEndpoint(), this.client.getApiVersion(),
                this.client.getSubscriptionId(), resourceGroupName, orderName, contentType, accept, resource, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param resource Resource create parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return concrete tracked resource types can be created by aliasing this type using a specific property type along
     * with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Response<BinaryData> createOrReplaceWithResponse(String resourceGroupName, String orderName,
        OrderInner resource) {
        final String contentType = "application/json";
        final String accept = "application/json";
        return service.createOrReplaceSync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), resourceGroupName, orderName, contentType, accept, resource, Context.NONE);
    }

    /**
     * Create a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param resource Resource create parameters.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return concrete tracked resource types can be created by aliasing this type using a specific property type along
     * with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Response<BinaryData> createOrReplaceWithResponse(String resourceGroupName, String orderName,
        OrderInner resource, Context context) {
        final String contentType = "application/json";
        final String accept = "application/json";
        return service.createOrReplaceSync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), resourceGroupName, orderName, contentType, accept, resource, context);
    }

    /**
     * Create a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param resource Resource create parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link PollerFlux} for polling of concrete tracked resource types can be created by aliasing this
     * type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    private PollerFlux<PollResult<OrderInner>, OrderInner> beginCreateOrReplaceAsync(String resourceGroupName,
        String orderName, OrderInner resource) {
        Mono<Response<Flux<ByteBuffer>>> mono
            = createOrReplaceWithResponseAsync(resourceGroupName, orderName, resource);
        return this.client.<OrderInner, OrderInner>getLroResult(mono, this.client.getHttpPipeline(), OrderInner.class,
            OrderInner.class, this.client.getContext());
    }

    /**
     * Create a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param resource Resource create parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of concrete tracked resource types can be created by aliasing this
     * type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<OrderInner>, OrderInner> beginCreateOrReplace(String resourceGroupName,
        String orderName, OrderInner resource) {
        Response<BinaryData> response = createOrReplaceWithResponse(resourceGroupName, orderName, resource);
        return this.client.<OrderInner, OrderInner>getLroResult(response, OrderInner.class, OrderInner.class,
            Context.NONE);
    }

    /**
     * Create a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param resource Resource create parameters.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the {@link SyncPoller} for polling of concrete tracked resource types can be created by aliasing this
     * type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<OrderInner>, OrderInner> beginCreateOrReplace(String resourceGroupName,
        String orderName, OrderInner resource, Context context) {
        Response<BinaryData> response = createOrReplaceWithResponse(resourceGroupName, orderName, resource, context);
        return this.client.<OrderInner, OrderInner>getLroResult(response, OrderInner.class, OrderInner.class, context);
    }

    /**
     * Create a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param resource Resource create parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return concrete tracked resource types can be created by aliasing this type using a specific property type on
     * successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<OrderInner> createOrReplaceAsync(String resourceGroupName, String orderName, OrderInner resource) {
        return beginCreateOrReplaceAsync(resourceGroupName, orderName, resource).last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param resource Resource create parameters.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return concrete tracked resource types can be created by aliasing this type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public OrderInner createOrReplace(String resourceGroupName, String orderName, OrderInner resource) {
        return beginCreateOrReplace(resourceGroupName, orderName, resource).getFinalResult();
    }

    /**
     * Create a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param resource Resource create parameters.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return concrete tracked resource types can be created by aliasing this type using a specific property type.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public OrderInner createOrReplace(String resourceGroupName, String orderName, OrderInner resource,
        Context context) {
        return beginCreateOrReplace(resourceGroupName, orderName, resource, context).getFinalResult();
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param body The content of the action request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> exportWithResponseAsync(String resourceGroupName, String orderName,
        ExportRequest body) {
        final String contentType = "application/json";
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.export(this.client.getEndpoint(), this.client.getApiVersion(),
                this.client.getSubscriptionId(), resourceGroupName, orderName, contentType, accept, body, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param body The content of the action request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Response<BinaryData> exportWithResponse(String resourceGroupName, String orderName, ExportRequest body) {
        final String contentType = "application/json";
        final String accept = "application/json";
        return service.exportSync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), resourceGroupName, orderName, contentType, accept, body, Context.NONE);
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param body The content of the action request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Response<BinaryData> exportWithResponse(String resourceGroupName, String orderName, ExportRequest body,
        Context context) {
        final String contentType = "application/json";
        final String accept = "application/json";
        return service.exportSync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), resourceGroupName, orderName, contentType, accept, body, context);
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param body The content of the action request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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<ExportResultInner>, ExportResultInner> beginExportAsync(String resourceGroupName,
        String orderName, ExportRequest body) {
        Mono<Response<Flux<ByteBuffer>>> mono = exportWithResponseAsync(resourceGroupName, orderName, body);
        return this.client.<ExportResultInner, ExportResultInner>getLroResult(mono, this.client.getHttpPipeline(),
            ExportResultInner.class, ExportResultInner.class, this.client.getContext());
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param body The content of the action request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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<ExportResultInner>, ExportResultInner> beginExport(String resourceGroupName,
        String orderName, ExportRequest body) {
        Response<BinaryData> response = exportWithResponse(resourceGroupName, orderName, body);
        return this.client.<ExportResultInner, ExportResultInner>getLroResult(response, ExportResultInner.class,
            ExportResultInner.class, Context.NONE);
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param body The content of the action request.
     * @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<ExportResultInner>, ExportResultInner> beginExport(String resourceGroupName,
        String orderName, ExportRequest body, Context context) {
        Response<BinaryData> response = exportWithResponse(resourceGroupName, orderName, body, context);
        return this.client.<ExportResultInner, ExportResultInner>getLroResult(response, ExportResultInner.class,
            ExportResultInner.class, context);
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param body The content of the action request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<ExportResultInner> exportAsync(String resourceGroupName, String orderName, ExportRequest body) {
        return beginExportAsync(resourceGroupName, orderName, body).last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param body The content of the action request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ExportResultInner export(String resourceGroupName, String orderName, ExportRequest body) {
        return beginExport(resourceGroupName, orderName, body).getFinalResult();
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param body The content of the action request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ExportResultInner export(String resourceGroupName, String orderName, ExportRequest body, Context context) {
        return beginExport(resourceGroupName, orderName, body, context).getFinalResult();
    }

    /**
     * Delete a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 orderName) {
        return FluxUtil
            .withContext(context -> service.delete(this.client.getEndpoint(), this.client.getApiVersion(),
                this.client.getSubscriptionId(), resourceGroupName, orderName, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Delete a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Response<BinaryData> deleteWithResponse(String resourceGroupName, String orderName) {
        return service.deleteSync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), resourceGroupName, orderName, Context.NONE);
    }

    /**
     * Delete a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Response<BinaryData> deleteWithResponse(String resourceGroupName, String orderName, Context context) {
        return service.deleteSync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), resourceGroupName, orderName, context);
    }

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

    /**
     * Delete a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 orderName) {
        Response<BinaryData> response = deleteWithResponse(resourceGroupName, orderName);
        return this.client.<Void, Void>getLroResult(response, Void.class, Void.class, Context.NONE);
    }

    /**
     * Delete a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @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 orderName, Context context) {
        Response<BinaryData> response = deleteWithResponse(resourceGroupName, orderName, context);
        return this.client.<Void, Void>getLroResult(response, Void.class, Void.class, context);
    }

    /**
     * Delete a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 orderName) {
        return beginDeleteAsync(resourceGroupName, orderName).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Delete a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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 orderName) {
        beginDelete(resourceGroupName, orderName).getFinalResult();
    }

    /**
     * Delete a Order.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param orderName The name of the Order.
     * @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 orderName, Context context) {
        beginDelete(resourceGroupName, orderName, context).getFinalResult();
    }

    /**
     * The exportArray operation.
     * 
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<Response<Flux<ByteBuffer>>> exportArrayWithResponseAsync(ExportRequest body) {
        final String contentType = "application/json";
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.exportArray(this.client.getEndpoint(), this.client.getApiVersion(),
                this.client.getSubscriptionId(), contentType, accept, body, context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * The exportArray operation.
     * 
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Response<BinaryData> exportArrayWithResponse(ExportRequest body) {
        final String contentType = "application/json";
        final String accept = "application/json";
        return service.exportArraySync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), contentType, accept, body, Context.NONE);
    }

    /**
     * The exportArray operation.
     * 
     * @param body The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Response<BinaryData> exportArrayWithResponse(ExportRequest body, Context context) {
        final String contentType = "application/json";
        final String accept = "application/json";
        return service.exportArraySync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), contentType, accept, body, context);
    }

    /**
     * The exportArray operation.
     * 
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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<List<ExportResultInner>>, List<ExportResultInner>>
        beginExportArrayAsync(ExportRequest body) {
        Mono<Response<Flux<ByteBuffer>>> mono = exportArrayWithResponseAsync(body);
        return this.client.<List<ExportResultInner>, List<ExportResultInner>>getLroResult(mono,
            this.client.getHttpPipeline(), new TypeReference<List<ExportResultInner>>() {
            }.getJavaType(), new TypeReference<List<ExportResultInner>>() {
            }.getJavaType(), this.client.getContext());
    }

    /**
     * The exportArray operation.
     * 
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @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<List<ExportResultInner>>, List<ExportResultInner>>
        beginExportArray(ExportRequest body) {
        Response<BinaryData> response = exportArrayWithResponse(body);
        return this.client.<List<ExportResultInner>, List<ExportResultInner>>getLroResult(response,
            new TypeReference<List<ExportResultInner>>() {
            }.getJavaType(), new TypeReference<List<ExportResultInner>>() {
            }.getJavaType(), Context.NONE);
    }

    /**
     * The exportArray operation.
     * 
     * @param body The request body.
     * @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<List<ExportResultInner>>, List<ExportResultInner>> beginExportArray(ExportRequest body,
        Context context) {
        Response<BinaryData> response = exportArrayWithResponse(body, context);
        return this.client.<List<ExportResultInner>, List<ExportResultInner>>getLroResult(response,
            new TypeReference<List<ExportResultInner>>() {
            }.getJavaType(), new TypeReference<List<ExportResultInner>>() {
            }.getJavaType(), context);
    }

    /**
     * The exportArray operation.
     * 
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response body on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Mono<List<ExportResultInner>> exportArrayAsync(ExportRequest body) {
        return beginExportArrayAsync(body).last().flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * The exportArray operation.
     * 
     * @param body The request body.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public List<ExportResultInner> exportArray(ExportRequest body) {
        return beginExportArray(body).getFinalResult();
    }

    /**
     * The exportArray operation.
     * 
     * @param body The request body.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ManagementException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public List<ExportResultInner> exportArray(ExportRequest body, Context context) {
        return beginExportArray(body, context).getFinalResult();
    }

    private static final TypeReference<List<ExportResultInner>> TYPE_REFERENCE_LIST_EXPORT_RESULT_INNER
        = new TypeReference<List<ExportResultInner>>() {
        };
}
