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

package tsptest.armresourceprovider.implementation;

import com.azure.core.annotation.BodyParam;
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 java.nio.ByteBuffer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;
import tsptest.armresourceprovider.fluent.LroNoBodiesClient;
import tsptest.armresourceprovider.models.ActionFinalResult;
import tsptest.armresourceprovider.models.ResourceLroNoBody;

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

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

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

    /**
     * The interface defining all the services for ArmClientLroNoBodies to be used by the proxy service to perform REST
     * calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "ArmClientLroNoBodies")
    public interface LroNoBodiesService {
        @Headers({ "Accept: application/json;q=0.9" })
        @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmResourceProvider/resourceLroNoBody/{resourceLroNoBodyName}")
        @ExpectedResponses({ 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> createOrUpdate(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("resourceLroNoBodyName") String resourceLroNoBodyName,
            @HeaderParam("Content-Type") String contentType, @BodyParam("application/json") ResourceLroNoBody resource,
            Context context);

        @Headers({ "Accept: application/json;q=0.9" })
        @Put("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmResourceProvider/resourceLroNoBody/{resourceLroNoBodyName}")
        @ExpectedResponses({ 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Response<BinaryData> createOrUpdateSync(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("resourceLroNoBodyName") String resourceLroNoBodyName,
            @HeaderParam("Content-Type") String contentType, @BodyParam("application/json") ResourceLroNoBody resource,
            Context context);

        @Headers({ "Content-Type: application/json" })
        @Post("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmResourceProvider/resourceLroNoBody/{resourceLroNoBodyName}/action")
        @ExpectedResponses({ 200, 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> action(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("resourceLroNoBodyName") String resourceLroNoBodyName, @HeaderParam("Accept") String accept,
            Context context);

        @Headers({ "Content-Type: application/json" })
        @Post("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/TspTest.ArmResourceProvider/resourceLroNoBody/{resourceLroNoBodyName}/action")
        @ExpectedResponses({ 200, 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Response<BinaryData> actionSync(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("resourceLroNoBodyName") String resourceLroNoBodyName, @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * Create a ResourceLroNoBody.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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 Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Flux<ByteBuffer>>> createOrUpdateWithResponseAsync(String resourceGroupName,
        String resourceLroNoBodyName, ResourceLroNoBody resource) {
        final String contentType = "application/json";
        return FluxUtil
            .withContext(context -> service.createOrUpdate(this.client.getEndpoint(), this.client.getApiVersion(),
                this.client.getSubscriptionId(), resourceGroupName, resourceLroNoBodyName, contentType, resource,
                context))
            .contextWrite(context -> context.putAll(FluxUtil.toReactorContext(this.client.getContext()).readOnly()));
    }

    /**
     * Create a ResourceLroNoBody.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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 response body along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Response<BinaryData> createOrUpdateWithResponse(String resourceGroupName, String resourceLroNoBodyName,
        ResourceLroNoBody resource) {
        final String contentType = "application/json";
        return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), resourceGroupName, resourceLroNoBodyName, contentType, resource,
            Context.NONE);
    }

    /**
     * Create a ResourceLroNoBody.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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 response body along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    private Response<BinaryData> createOrUpdateWithResponse(String resourceGroupName, String resourceLroNoBodyName,
        ResourceLroNoBody resource, Context context) {
        final String contentType = "application/json";
        return service.createOrUpdateSync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), resourceGroupName, resourceLroNoBodyName, contentType, resource, context);
    }

    /**
     * Create a ResourceLroNoBody.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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 long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public PollerFlux<PollResult<ResourceLroNoBody>, ResourceLroNoBody>
        beginCreateOrUpdateAsync(String resourceGroupName, String resourceLroNoBodyName, ResourceLroNoBody resource) {
        Mono<Response<Flux<ByteBuffer>>> mono
            = createOrUpdateWithResponseAsync(resourceGroupName, resourceLroNoBodyName, resource);
        return this.client.<ResourceLroNoBody, ResourceLroNoBody>getLroResult(mono, this.client.getHttpPipeline(),
            ResourceLroNoBody.class, ResourceLroNoBody.class, this.client.getContext());
    }

    /**
     * Create a ResourceLroNoBody.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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 long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ResourceLroNoBody>, ResourceLroNoBody> beginCreateOrUpdate(String resourceGroupName,
        String resourceLroNoBodyName, ResourceLroNoBody resource) {
        Response<BinaryData> response = createOrUpdateWithResponse(resourceGroupName, resourceLroNoBodyName, resource);
        return this.client.<ResourceLroNoBody, ResourceLroNoBody>getLroResult(response, ResourceLroNoBody.class,
            ResourceLroNoBody.class, Context.NONE);
    }

    /**
     * Create a ResourceLroNoBody.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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 long-running operation.
     */
    @ServiceMethod(returns = ReturnType.LONG_RUNNING_OPERATION)
    public SyncPoller<PollResult<ResourceLroNoBody>, ResourceLroNoBody> beginCreateOrUpdate(String resourceGroupName,
        String resourceLroNoBodyName, ResourceLroNoBody resource, Context context) {
        Response<BinaryData> response
            = createOrUpdateWithResponse(resourceGroupName, resourceLroNoBodyName, resource, context);
        return this.client.<ResourceLroNoBody, ResourceLroNoBody>getLroResult(response, ResourceLroNoBody.class,
            ResourceLroNoBody.class, context);
    }

    /**
     * Create a ResourceLroNoBody.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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 response body on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<ResourceLroNoBody> createOrUpdateAsync(String resourceGroupName, String resourceLroNoBodyName,
        ResourceLroNoBody resource) {
        return beginCreateOrUpdateAsync(resourceGroupName, resourceLroNoBodyName, resource).last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * Create a ResourceLroNoBody.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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 response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ResourceLroNoBody createOrUpdate(String resourceGroupName, String resourceLroNoBodyName,
        ResourceLroNoBody resource) {
        return beginCreateOrUpdate(resourceGroupName, resourceLroNoBodyName, resource).getFinalResult();
    }

    /**
     * Create a ResourceLroNoBody.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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 response.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public ResourceLroNoBody createOrUpdate(String resourceGroupName, String resourceLroNoBodyName,
        ResourceLroNoBody resource, Context context) {
        return beginCreateOrUpdate(resourceGroupName, resourceLroNoBodyName, resource, context).getFinalResult();
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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)
    public Mono<Response<Flux<ByteBuffer>>> actionWithResponseAsync(String resourceGroupName,
        String resourceLroNoBodyName) {
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.action(this.client.getEndpoint(), this.client.getApiVersion(),
                this.client.getSubscriptionId(), resourceGroupName, resourceLroNoBodyName, accept, 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 resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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> actionWithResponse(String resourceGroupName, String resourceLroNoBodyName) {
        final String accept = "application/json";
        return service.actionSync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), resourceGroupName, resourceLroNoBodyName, accept, Context.NONE);
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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> actionWithResponse(String resourceGroupName, String resourceLroNoBodyName,
        Context context) {
        final String accept = "application/json";
        return service.actionSync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), resourceGroupName, resourceLroNoBodyName, accept, context);
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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)
    public PollerFlux<PollResult<ActionFinalResult>, ActionFinalResult> beginActionAsync(String resourceGroupName,
        String resourceLroNoBodyName) {
        Mono<Response<Flux<ByteBuffer>>> mono = actionWithResponseAsync(resourceGroupName, resourceLroNoBodyName);
        return this.client.<ActionFinalResult, ActionFinalResult>getLroResult(mono, this.client.getHttpPipeline(),
            ActionFinalResult.class, ActionFinalResult.class, this.client.getContext());
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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<ActionFinalResult>, ActionFinalResult> beginAction(String resourceGroupName,
        String resourceLroNoBodyName) {
        Response<BinaryData> response = actionWithResponse(resourceGroupName, resourceLroNoBodyName);
        return this.client.<ActionFinalResult, ActionFinalResult>getLroResult(response, ActionFinalResult.class,
            ActionFinalResult.class, Context.NONE);
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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<ActionFinalResult>, ActionFinalResult> beginAction(String resourceGroupName,
        String resourceLroNoBodyName, Context context) {
        Response<BinaryData> response = actionWithResponse(resourceGroupName, resourceLroNoBodyName, context);
        return this.client.<ActionFinalResult, ActionFinalResult>getLroResult(response, ActionFinalResult.class,
            ActionFinalResult.class, context);
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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)
    public Mono<ActionFinalResult> actionAsync(String resourceGroupName, String resourceLroNoBodyName) {
        return beginActionAsync(resourceGroupName, resourceLroNoBodyName).last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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 ActionFinalResult action(String resourceGroupName, String resourceLroNoBodyName) {
        return beginAction(resourceGroupName, resourceLroNoBodyName).getFinalResult();
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param resourceLroNoBodyName The name of the ResourceLroNoBody.
     * @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 ActionFinalResult action(String resourceGroupName, String resourceLroNoBodyName, Context context) {
        return beginAction(resourceGroupName, resourceLroNoBodyName, context).getFinalResult();
    }
}
