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

package com.azure.analytics.synapse.artifacts;

import com.azure.analytics.synapse.artifacts.implementation.LibrariesImpl;
import com.azure.analytics.synapse.artifacts.models.CloudErrorException;
import com.azure.analytics.synapse.artifacts.models.LibraryResource;
import com.azure.analytics.synapse.artifacts.models.LibraryResourceInfo;
import com.azure.core.annotation.Generated;
import com.azure.core.annotation.ReturnType;
import com.azure.core.annotation.ServiceClient;
import com.azure.core.annotation.ServiceMethod;
import com.azure.core.http.rest.PagedFlux;
import com.azure.core.http.rest.Response;
import com.azure.core.util.BinaryData;
import java.nio.ByteBuffer;
import reactor.core.publisher.Flux;
import reactor.core.publisher.Mono;

/** Initializes a new instance of the asynchronous ArtifactsClient type. */
@ServiceClient(builder = ArtifactsClientBuilder.class, isAsync = true)
public final class LibraryAsyncClient {
    @Generated private final LibrariesImpl serviceClient;

    /**
     * Initializes an instance of LibraryAsyncClient class.
     *
     * @param serviceClient the service client implementation.
     */
    @Generated
    LibraryAsyncClient(LibrariesImpl serviceClient) {
        this.serviceClient = serviceClient;
    }

    /**
     * Lists Library.
     *
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return a list of Library resources as paginated response with {@link PagedFlux}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<LibraryResource> list() {
        return this.serviceClient.listAsync();
    }

    /**
     * Flush Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<LibraryResourceInfo>> flushWithResponse(String libraryName) {
        return this.serviceClient.flushWithResponseAsync(libraryName);
    }

    /**
     * Flush Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<LibraryResourceInfo> flush(String libraryName) {
        return this.serviceClient.flushAsync(libraryName);
    }

    /**
     * Get Operation result for Library.
     *
     * @param operationId operation id for which status is requested.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return operation result for Library along with {@link Response} on successful completion of {@link Mono}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<LibraryResource>> getOperationResultWithResponse(String operationId) {
        return this.serviceClient.getOperationResultWithResponseAsync(operationId);
    }

    /**
     * Get Operation result for Library.
     *
     * @param operationId operation id for which status is requested.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return operation result for Library on successful completion of {@link Mono}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<LibraryResource> getOperationResult(String operationId) {
        return this.serviceClient.getOperationResultAsync(operationId);
    }

    /**
     * Delete Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<LibraryResourceInfo>> deleteWithResponse(String libraryName) {
        return this.serviceClient.deleteWithResponseAsync(libraryName);
    }

    /**
     * Delete Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<LibraryResourceInfo> delete(String libraryName) {
        return this.serviceClient.deleteAsync(libraryName);
    }

    /**
     * Get Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return library along with {@link Response} on successful completion of {@link Mono}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<LibraryResource>> getWithResponse(String libraryName) {
        return this.serviceClient.getWithResponseAsync(libraryName);
    }

    /**
     * Get Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return library on successful completion of {@link Mono}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<LibraryResource> get(String libraryName) {
        return this.serviceClient.getAsync(libraryName);
    }

    /**
     * Creates a library with the library name.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<LibraryResourceInfo>> createWithResponse(String libraryName) {
        return this.serviceClient.createWithResponseAsync(libraryName);
    }

    /**
     * Creates a library with the library name.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<LibraryResourceInfo> create(String libraryName) {
        return this.serviceClient.createAsync(libraryName);
    }

    /**
     * Append the content to the library resource created using the create operation. The maximum content size is 4MiB.
     * Content larger than 4MiB must be appended in 4MiB chunks.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param content Library file chunk.
     * @param contentLength The Content-Length header for the request.
     * @param blobConditionAppendPosition Set this header to a byte offset at which the block is expected to be
     *     appended. The request succeeds only if the current offset matches this value. Otherwise, the request fails
     *     with the AppendPositionConditionNotMet error (HTTP status code 412 – Precondition Failed).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> appendWithResponse(
            String libraryName, Flux<ByteBuffer> content, long contentLength, Long blobConditionAppendPosition) {
        return this.serviceClient.appendWithResponseAsync(
                libraryName, content, contentLength, blobConditionAppendPosition);
    }

    /**
     * Append the content to the library resource created using the create operation. The maximum content size is 4MiB.
     * Content larger than 4MiB must be appended in 4MiB chunks.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param content Library file chunk.
     * @param contentLength The Content-Length header for the request.
     * @param blobConditionAppendPosition Set this header to a byte offset at which the block is expected to be
     *     appended. The request succeeds only if the current offset matches this value. Otherwise, the request fails
     *     with the AppendPositionConditionNotMet error (HTTP status code 412 – Precondition Failed).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> append(
            String libraryName, Flux<ByteBuffer> content, long contentLength, Long blobConditionAppendPosition) {
        return this.serviceClient.appendAsync(libraryName, content, contentLength, blobConditionAppendPosition);
    }

    /**
     * Append the content to the library resource created using the create operation. The maximum content size is 4MiB.
     * Content larger than 4MiB must be appended in 4MiB chunks.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param content Library file chunk.
     * @param contentLength The Content-Length header for the request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> append(String libraryName, Flux<ByteBuffer> content, long contentLength) {
        return this.serviceClient.appendAsync(libraryName, content, contentLength);
    }

    /**
     * Append the content to the library resource created using the create operation. The maximum content size is 4MiB.
     * Content larger than 4MiB must be appended in 4MiB chunks.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param content Library file chunk.
     * @param contentLength The Content-Length header for the request.
     * @param blobConditionAppendPosition Set this header to a byte offset at which the block is expected to be
     *     appended. The request succeeds only if the current offset matches this value. Otherwise, the request fails
     *     with the AppendPositionConditionNotMet error (HTTP status code 412 – Precondition Failed).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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}.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> appendWithResponse(
            String libraryName, BinaryData content, long contentLength, Long blobConditionAppendPosition) {
        return this.serviceClient.appendWithResponseAsync(
                libraryName, content, contentLength, blobConditionAppendPosition);
    }

    /**
     * Append the content to the library resource created using the create operation. The maximum content size is 4MiB.
     * Content larger than 4MiB must be appended in 4MiB chunks.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param content Library file chunk.
     * @param contentLength The Content-Length header for the request.
     * @param blobConditionAppendPosition Set this header to a byte offset at which the block is expected to be
     *     appended. The request succeeds only if the current offset matches this value. Otherwise, the request fails
     *     with the AppendPositionConditionNotMet error (HTTP status code 412 – Precondition Failed).
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> append(
            String libraryName, BinaryData content, long contentLength, Long blobConditionAppendPosition) {
        return this.serviceClient.appendAsync(libraryName, content, contentLength, blobConditionAppendPosition);
    }

    /**
     * Append the content to the library resource created using the create operation. The maximum content size is 4MiB.
     * Content larger than 4MiB must be appended in 4MiB chunks.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param content Library file chunk.
     * @param contentLength The Content-Length header for the request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorException 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.
     */
    @Generated
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> append(String libraryName, BinaryData content, long contentLength) {
        return this.serviceClient.appendAsync(libraryName, content, contentLength);
    }
}
