LibrariesImpl.java

// 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.implementation;

import com.azure.analytics.synapse.artifacts.models.CloudErrorAutoGeneratedException;
import com.azure.analytics.synapse.artifacts.models.LibraryListResponse;
import com.azure.analytics.synapse.artifacts.models.LibraryResource;
import com.azure.analytics.synapse.artifacts.models.LibraryResourceInfo;
import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.Delete;
import com.azure.core.annotation.ExpectedResponses;
import com.azure.core.annotation.Get;
import com.azure.core.annotation.HeaderParam;
import com.azure.core.annotation.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.PagedFlux;
import com.azure.core.http.rest.PagedIterable;
import com.azure.core.http.rest.PagedResponse;
import com.azure.core.http.rest.PagedResponseBase;
import com.azure.core.http.rest.Response;
import com.azure.core.http.rest.RestProxy;
import com.azure.core.util.Context;
import com.azure.core.util.FluxUtil;
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 Libraries. */
public final class LibrariesImpl {
    /** The proxy service used to perform REST calls. */
    private final LibrariesService service;

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

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

    /**
     * The interface defining all the services for ArtifactsClientLibraries to be used by the proxy service to perform
     * REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "ArtifactsClientLibra")
    private interface LibrariesService {
        @Get("/libraries")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(CloudErrorAutoGeneratedException.class)
        Mono<Response<LibraryListResponse>> list(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @HeaderParam("Accept") String accept,
                Context context);

        @Post("/libraries/{libraryName}/flush")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(CloudErrorAutoGeneratedException.class)
        Mono<Response<LibraryResourceInfo>> flush(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("libraryName") String libraryName,
                @HeaderParam("Accept") String accept,
                Context context);

        @Get("/libraryOperationResults/{operationId}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(CloudErrorAutoGeneratedException.class)
        Mono<Response<LibraryResource>> getOperationResult(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("operationId") String operationId,
                @HeaderParam("Accept") String accept,
                Context context);

        @Delete("/libraries/{libraryName}")
        @ExpectedResponses({200, 202, 409})
        @UnexpectedResponseExceptionType(CloudErrorAutoGeneratedException.class)
        Mono<Response<LibraryResourceInfo>> delete(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("libraryName") String libraryName,
                @HeaderParam("Accept") String accept,
                Context context);

        @Get("/libraries/{libraryName}")
        @ExpectedResponses({200, 304})
        @UnexpectedResponseExceptionType(CloudErrorAutoGeneratedException.class)
        Mono<Response<LibraryResource>> get(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("libraryName") String libraryName,
                @HeaderParam("Accept") String accept,
                Context context);

        @Put("/libraries/{libraryName}")
        @ExpectedResponses({200, 202})
        @UnexpectedResponseExceptionType(CloudErrorAutoGeneratedException.class)
        Mono<Response<LibraryResourceInfo>> create(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("libraryName") String libraryName,
                @HeaderParam("Accept") String accept,
                Context context);

        @Put("/libraries/{libraryName}")
        @ExpectedResponses({201})
        @UnexpectedResponseExceptionType(CloudErrorAutoGeneratedException.class)
        Mono<Response<Void>> append(
                @HostParam("endpoint") String endpoint,
                @QueryParam("comp") String comp,
                @QueryParam("api-version") String apiVersion,
                @PathParam("libraryName") String libraryName,
                @HeaderParam("x-ms-blob-condition-appendpos") Long blobConditionAppendPosition,
                @BodyParam("application/octet-stream") Flux<ByteBuffer> content,
                @HeaderParam("Content-Length") long contentLength,
                @HeaderParam("Accept") String accept,
                Context context);

        @Get("{nextLink}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(CloudErrorAutoGeneratedException.class)
        Mono<Response<LibraryListResponse>> listNext(
                @PathParam(value = "nextLink", encoded = true) String nextLink,
                @HostParam("endpoint") String endpoint,
                @HeaderParam("Accept") String accept,
                Context context);
    }

    /**
     * Lists Library.
     *
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<LibraryResource>> listSinglePageAsync() {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return FluxUtil.withContext(context -> service.list(this.client.getEndpoint(), apiVersion, accept, context))
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }

    /**
     * Lists Library.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<LibraryResource>> listSinglePageAsync(Context context) {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return service.list(this.client.getEndpoint(), apiVersion, accept, context)
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }

    /**
     * Lists Library.
     *
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<LibraryResource> listAsync() {
        return new PagedFlux<>(() -> listSinglePageAsync(), nextLink -> listNextSinglePageAsync(nextLink));
    }

    /**
     * Lists Library.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedFlux<LibraryResource> listAsync(Context context) {
        return new PagedFlux<>(
                () -> listSinglePageAsync(context), nextLink -> listNextSinglePageAsync(nextLink, context));
    }

    /**
     * Lists Library.
     *
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<LibraryResource> list() {
        return new PagedIterable<>(listAsync());
    }

    /**
     * Lists Library.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.COLLECTION)
    public PagedIterable<LibraryResource> list(Context context) {
        return new PagedIterable<>(listAsync(context));
    }

    /**
     * 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 CloudErrorAutoGeneratedException 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 Mono<Response<LibraryResourceInfo>> flushWithResponseAsync(String libraryName) {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.flush(this.client.getEndpoint(), apiVersion, libraryName, accept, context));
    }

    /**
     * Flush Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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 Mono<Response<LibraryResourceInfo>> flushWithResponseAsync(String libraryName, Context context) {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return service.flush(this.client.getEndpoint(), apiVersion, libraryName, accept, context);
    }

    /**
     * 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 CloudErrorAutoGeneratedException 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 Mono<LibraryResourceInfo> flushAsync(String libraryName) {
        return flushWithResponseAsync(libraryName)
                .flatMap(
                        (Response<LibraryResourceInfo> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Flush Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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 Mono<LibraryResourceInfo> flushAsync(String libraryName, Context context) {
        return flushWithResponseAsync(libraryName, context)
                .flatMap(
                        (Response<LibraryResourceInfo> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * 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 CloudErrorAutoGeneratedException 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 LibraryResourceInfo flush(String libraryName) {
        return flushAsync(libraryName).block();
    }

    /**
     * Flush Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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 Response<LibraryResourceInfo> flushWithResponse(String libraryName, Context context) {
        return flushWithResponseAsync(libraryName, context).block();
    }

    /**
     * Get Operation result for Library.
     *
     * @param operationId operation id for which status is requested.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<LibraryResource>> getOperationResultWithResponseAsync(String operationId) {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.getOperationResult(
                                this.client.getEndpoint(), apiVersion, operationId, accept, context));
    }

    /**
     * Get Operation result for Library.
     *
     * @param operationId operation id for which status is requested.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<LibraryResource>> getOperationResultWithResponseAsync(String operationId, Context context) {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return service.getOperationResult(this.client.getEndpoint(), apiVersion, operationId, accept, context);
    }

    /**
     * Get Operation result for Library.
     *
     * @param operationId operation id for which status is requested.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<LibraryResource> getOperationResultAsync(String operationId) {
        return getOperationResultWithResponseAsync(operationId)
                .flatMap(
                        (Response<LibraryResource> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Get Operation result for Library.
     *
     * @param operationId operation id for which status is requested.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<LibraryResource> getOperationResultAsync(String operationId, Context context) {
        return getOperationResultWithResponseAsync(operationId, context)
                .flatMap(
                        (Response<LibraryResource> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Get Operation result for Library.
     *
     * @param operationId operation id for which status is requested.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public LibraryResource getOperationResult(String operationId) {
        return getOperationResultAsync(operationId).block();
    }

    /**
     * Get Operation result for Library.
     *
     * @param operationId operation id for which status is requested.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<LibraryResource> getOperationResultWithResponse(String operationId, Context context) {
        return getOperationResultWithResponseAsync(operationId, context).block();
    }

    /**
     * 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 CloudErrorAutoGeneratedException 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 Mono<Response<LibraryResourceInfo>> deleteWithResponseAsync(String libraryName) {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.delete(this.client.getEndpoint(), apiVersion, libraryName, accept, context));
    }

    /**
     * Delete Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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 Mono<Response<LibraryResourceInfo>> deleteWithResponseAsync(String libraryName, Context context) {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return service.delete(this.client.getEndpoint(), apiVersion, libraryName, accept, context);
    }

    /**
     * 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 CloudErrorAutoGeneratedException 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 Mono<LibraryResourceInfo> deleteAsync(String libraryName) {
        return deleteWithResponseAsync(libraryName)
                .flatMap(
                        (Response<LibraryResourceInfo> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Delete Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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 Mono<LibraryResourceInfo> deleteAsync(String libraryName, Context context) {
        return deleteWithResponseAsync(libraryName, context)
                .flatMap(
                        (Response<LibraryResourceInfo> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * 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 CloudErrorAutoGeneratedException 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 LibraryResourceInfo delete(String libraryName) {
        return deleteAsync(libraryName).block();
    }

    /**
     * Delete Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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 Response<LibraryResourceInfo> deleteWithResponse(String libraryName, Context context) {
        return deleteWithResponseAsync(libraryName, context).block();
    }

    /**
     * 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 CloudErrorAutoGeneratedException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return library.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<LibraryResource>> getWithResponseAsync(String libraryName) {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.get(this.client.getEndpoint(), apiVersion, libraryName, accept, context));
    }

    /**
     * Get Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return library.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<LibraryResource>> getWithResponseAsync(String libraryName, Context context) {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return service.get(this.client.getEndpoint(), apiVersion, libraryName, accept, context);
    }

    /**
     * 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 CloudErrorAutoGeneratedException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return library.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<LibraryResource> getAsync(String libraryName) {
        return getWithResponseAsync(libraryName)
                .flatMap(
                        (Response<LibraryResource> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * Get Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return library.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<LibraryResource> getAsync(String libraryName, Context context) {
        return getWithResponseAsync(libraryName, context)
                .flatMap(
                        (Response<LibraryResource> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * 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 CloudErrorAutoGeneratedException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return library.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public LibraryResource get(String libraryName) {
        return getAsync(libraryName).block();
    }

    /**
     * Get Library.
     *
     * @param libraryName file name to upload. Minimum length of the filename should be 1 excluding the extension
     *     length.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return library.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<LibraryResource> getWithResponse(String libraryName, Context context) {
        return getWithResponseAsync(libraryName, context).block();
    }

    /**
     * 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 CloudErrorAutoGeneratedException 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 Mono<Response<LibraryResourceInfo>> createWithResponseAsync(String libraryName) {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.create(this.client.getEndpoint(), apiVersion, libraryName, accept, context));
    }

    /**
     * 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.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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 Mono<Response<LibraryResourceInfo>> createWithResponseAsync(String libraryName, Context context) {
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return service.create(this.client.getEndpoint(), apiVersion, libraryName, accept, context);
    }

    /**
     * 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 CloudErrorAutoGeneratedException 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 Mono<LibraryResourceInfo> createAsync(String libraryName) {
        return createWithResponseAsync(libraryName)
                .flatMap(
                        (Response<LibraryResourceInfo> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * 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.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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 Mono<LibraryResourceInfo> createAsync(String libraryName, Context context) {
        return createWithResponseAsync(libraryName, context)
                .flatMap(
                        (Response<LibraryResourceInfo> res) -> {
                            if (res.getValue() != null) {
                                return Mono.just(res.getValue());
                            } else {
                                return Mono.empty();
                            }
                        });
    }

    /**
     * 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 CloudErrorAutoGeneratedException 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 LibraryResourceInfo create(String libraryName) {
        return createAsync(libraryName).block();
    }

    /**
     * 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.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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 Response<LibraryResourceInfo> createWithResponse(String libraryName, Context context) {
        return createWithResponseAsync(libraryName, context).block();
    }

    /**
     * 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 contentLength parameter.
     * @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 CloudErrorAutoGeneratedException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> appendWithResponseAsync(
            String libraryName, Flux<ByteBuffer> content, long contentLength, Long blobConditionAppendPosition) {
        final String comp = "appendblock";
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.append(
                                this.client.getEndpoint(),
                                comp,
                                apiVersion,
                                libraryName,
                                blobConditionAppendPosition,
                                content,
                                contentLength,
                                accept,
                                context));
    }

    /**
     * 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 contentLength parameter.
     * @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).
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<Void>> appendWithResponseAsync(
            String libraryName,
            Flux<ByteBuffer> content,
            long contentLength,
            Long blobConditionAppendPosition,
            Context context) {
        final String comp = "appendblock";
        final String apiVersion = "2020-12-01";
        final String accept = "application/json";
        return service.append(
                this.client.getEndpoint(),
                comp,
                apiVersion,
                libraryName,
                blobConditionAppendPosition,
                content,
                contentLength,
                accept,
                context);
    }

    /**
     * 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 contentLength parameter.
     * @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 CloudErrorAutoGeneratedException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> appendAsync(
            String libraryName, Flux<ByteBuffer> content, long contentLength, Long blobConditionAppendPosition) {
        return appendWithResponseAsync(libraryName, content, contentLength, blobConditionAppendPosition)
                .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * 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 contentLength parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> appendAsync(String libraryName, Flux<ByteBuffer> content, long contentLength) {
        final Long blobConditionAppendPosition = null;
        return appendWithResponseAsync(libraryName, content, contentLength, blobConditionAppendPosition)
                .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * 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 contentLength parameter.
     * @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).
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the completion.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> appendAsync(
            String libraryName,
            Flux<ByteBuffer> content,
            long contentLength,
            Long blobConditionAppendPosition,
            Context context) {
        return appendWithResponseAsync(libraryName, content, contentLength, blobConditionAppendPosition, context)
                .flatMap((Response<Void> res) -> Mono.empty());
    }

    /**
     * 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 contentLength parameter.
     * @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 CloudErrorAutoGeneratedException 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 append(
            String libraryName, Flux<ByteBuffer> content, long contentLength, Long blobConditionAppendPosition) {
        appendAsync(libraryName, content, contentLength, blobConditionAppendPosition).block();
    }

    /**
     * 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 contentLength parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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 append(String libraryName, Flux<ByteBuffer> content, long contentLength) {
        final Long blobConditionAppendPosition = null;
        appendAsync(libraryName, content, contentLength, blobConditionAppendPosition).block();
    }

    /**
     * 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 contentLength parameter.
     * @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).
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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 Response<Void> appendWithResponse(
            String libraryName,
            Flux<ByteBuffer> content,
            long contentLength,
            Long blobConditionAppendPosition,
            Context context) {
        return appendWithResponseAsync(libraryName, content, contentLength, blobConditionAppendPosition, context)
                .block();
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The nextLink parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<LibraryResource>> listNextSinglePageAsync(String nextLink) {
        final String accept = "application/json";
        return FluxUtil.withContext(context -> service.listNext(nextLink, this.client.getEndpoint(), accept, context))
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }

    /**
     * Get the next page of items.
     *
     * @param nextLink The nextLink parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws CloudErrorAutoGeneratedException 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.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PagedResponse<LibraryResource>> listNextSinglePageAsync(String nextLink, Context context) {
        final String accept = "application/json";
        return service.listNext(nextLink, this.client.getEndpoint(), accept, context)
                .map(
                        res ->
                                new PagedResponseBase<>(
                                        res.getRequest(),
                                        res.getStatusCode(),
                                        res.getHeaders(),
                                        res.getValue().getValue(),
                                        res.getValue().getNextLink(),
                                        null));
    }
}