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

package azure.resourcemanager.largeheader.implementation;

import azure.resourcemanager.largeheader.fluent.LargeHeadersClient;
import azure.resourcemanager.largeheader.fluent.models.CancelResultInner;
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.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;

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

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

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

    /**
     * The interface defining all the services for LargeHeaderClientLargeHeaders to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "LargeHeaderClientLargeHeaders")
    public interface LargeHeadersService {
        @Headers({ "Content-Type: application/json" })
        @Post("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.LargeHeader/largeHeaders/{largeHeaderName}/two6k")
        @ExpectedResponses({ 200, 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Mono<Response<Flux<ByteBuffer>>> two6k(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("largeHeaderName") String largeHeaderName, @HeaderParam("Accept") String accept,
            Context context);

        @Headers({ "Content-Type: application/json" })
        @Post("/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Azure.ResourceManager.LargeHeader/largeHeaders/{largeHeaderName}/two6k")
        @ExpectedResponses({ 200, 202 })
        @UnexpectedResponseExceptionType(ManagementException.class)
        Response<BinaryData> two6kSync(@HostParam("endpoint") String endpoint,
            @QueryParam("api-version") String apiVersion, @PathParam("subscriptionId") String subscriptionId,
            @PathParam("resourceGroupName") String resourceGroupName,
            @PathParam("largeHeaderName") String largeHeaderName, @HeaderParam("Accept") String accept,
            Context context);
    }

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param largeHeaderName The name of the LargeHeader.
     * @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>>> two6kWithResponseAsync(String resourceGroupName, String largeHeaderName) {
        final String accept = "application/json";
        return FluxUtil
            .withContext(context -> service.two6k(this.client.getEndpoint(), this.client.getApiVersion(),
                this.client.getSubscriptionId(), resourceGroupName, largeHeaderName, 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 largeHeaderName The name of the LargeHeader.
     * @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> two6kWithResponse(String resourceGroupName, String largeHeaderName) {
        final String accept = "application/json";
        return service.two6kSync(this.client.getEndpoint(), this.client.getApiVersion(),
            this.client.getSubscriptionId(), resourceGroupName, largeHeaderName, accept, Context.NONE);
    }

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

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param largeHeaderName The name of the LargeHeader.
     * @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<CancelResultInner>, CancelResultInner> beginTwo6kAsync(String resourceGroupName,
        String largeHeaderName) {
        Mono<Response<Flux<ByteBuffer>>> mono = two6kWithResponseAsync(resourceGroupName, largeHeaderName);
        return this.client.<CancelResultInner, CancelResultInner>getLroResult(mono, this.client.getHttpPipeline(),
            CancelResultInner.class, CancelResultInner.class, this.client.getContext());
    }

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

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

    /**
     * A long-running resource action.
     * 
     * @param resourceGroupName The name of the resource group. The name is case insensitive.
     * @param largeHeaderName The name of the LargeHeader.
     * @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<CancelResultInner> two6kAsync(String resourceGroupName, String largeHeaderName) {
        return beginTwo6kAsync(resourceGroupName, largeHeaderName).last()
            .flatMap(this.client::getLroFinalResultOrError);
    }

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

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