// 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.ErrorContractException;
import com.azure.analytics.synapse.artifacts.models.MetastoreRegisterObject;
import com.azure.analytics.synapse.artifacts.models.MetastoreRegistrationResponse;
import com.azure.analytics.synapse.artifacts.models.MetastoreRequestSuccessResponse;
import com.azure.analytics.synapse.artifacts.models.MetastoreUpdateObject;
import com.azure.analytics.synapse.artifacts.models.MetastoreUpdationResponse;
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.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.util.Context;
import com.azure.core.util.FluxUtil;
import reactor.core.publisher.Mono;

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

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

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

    /**
     * The interface defining all the services for ArtifactsClientMetastores to be used by the proxy service to perform
     * REST calls.
     */
    @Host("{endpoint}")
    @ServiceInterface(name = "ArtifactsClientMetas")
    public interface MetastoresService {
        @Put("/metastore/create-database-operations/{id}")
        @ExpectedResponses({201})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<MetastoreRegistrationResponse>> register(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("id") String id,
                @BodyParam("application/json") MetastoreRegisterObject registerBody,
                @HeaderParam("Accept") String accept,
                Context context);

        @Get("/metastore/create-database-operations/{id}")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<MetastoreRequestSuccessResponse>> getDatabaseOperations(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("id") String id,
                @HeaderParam("Accept") String accept,
                Context context);

        @Put("/metastore/update-database-operations/{id}")
        @ExpectedResponses({201})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<MetastoreUpdationResponse>> update(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("id") String id,
                @BodyParam("application/json") MetastoreUpdateObject updateBody,
                @HeaderParam("Accept") String accept,
                Context context);

        @Delete("/metastore/databases/{id}")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorContractException.class)
        Mono<Response<Void>> delete(
                @HostParam("endpoint") String endpoint,
                @QueryParam("api-version") String apiVersion,
                @PathParam("id") String id,
                @HeaderParam("Accept") String accept,
                Context context);
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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<MetastoreRegistrationResponse>> registerWithResponseAsync(
            String id, MetastoreRegisterObject registerBody) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.register(this.client.getEndpoint(), apiVersion, id, registerBody, accept, context));
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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<MetastoreRegistrationResponse>> registerWithResponseAsync(
            String id, MetastoreRegisterObject registerBody, Context context) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return service.register(this.client.getEndpoint(), apiVersion, id, registerBody, accept, context);
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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<MetastoreRegistrationResponse> registerAsync(String id, MetastoreRegisterObject registerBody) {
        return registerWithResponseAsync(id, registerBody).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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<MetastoreRegistrationResponse> registerAsync(
            String id, MetastoreRegisterObject registerBody, Context context) {
        return registerWithResponseAsync(id, registerBody, context).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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)
    public Response<MetastoreRegistrationResponse> registerWithResponse(
            String id, MetastoreRegisterObject registerBody, Context context) {
        return registerWithResponseAsync(id, registerBody, context).block();
    }

    /**
     * Register files in Syms.
     *
     * @param id The name of the database to be created. The name can contain only alphanumeric characters and should
     *     not exceed 24 characters.
     * @param registerBody The body for the register request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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 MetastoreRegistrationResponse register(String id, MetastoreRegisterObject registerBody) {
        return registerWithResponse(id, registerBody, Context.NONE).getValue();
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<MetastoreRequestSuccessResponse>> getDatabaseOperationsWithResponseAsync(String id) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.getDatabaseOperations(this.client.getEndpoint(), apiVersion, id, accept, context));
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<MetastoreRequestSuccessResponse>> getDatabaseOperationsWithResponseAsync(
            String id, Context context) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return service.getDatabaseOperations(this.client.getEndpoint(), apiVersion, id, accept, context);
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<MetastoreRequestSuccessResponse> getDatabaseOperationsAsync(String id) {
        return getDatabaseOperationsWithResponseAsync(id).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<MetastoreRequestSuccessResponse> getDatabaseOperationsAsync(String id, Context context) {
        return getDatabaseOperationsWithResponseAsync(id, context).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<MetastoreRequestSuccessResponse> getDatabaseOperationsWithResponse(String id, Context context) {
        return getDatabaseOperationsWithResponseAsync(id, context).block();
    }

    /**
     * Gets status of the database.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return status of the database.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public MetastoreRequestSuccessResponse getDatabaseOperations(String id) {
        return getDatabaseOperationsWithResponse(id, Context.NONE).getValue();
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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<MetastoreUpdationResponse>> updateWithResponseAsync(
            String id, MetastoreUpdateObject updateBody) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.update(this.client.getEndpoint(), apiVersion, id, updateBody, accept, context));
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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<MetastoreUpdationResponse>> updateWithResponseAsync(
            String id, MetastoreUpdateObject updateBody, Context context) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return service.update(this.client.getEndpoint(), apiVersion, id, updateBody, accept, context);
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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<MetastoreUpdationResponse> updateAsync(String id, MetastoreUpdateObject updateBody) {
        return updateWithResponseAsync(id, updateBody).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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<MetastoreUpdationResponse> updateAsync(String id, MetastoreUpdateObject updateBody, Context context) {
        return updateWithResponseAsync(id, updateBody, context).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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)
    public Response<MetastoreUpdationResponse> updateWithResponse(
            String id, MetastoreUpdateObject updateBody, Context context) {
        return updateWithResponseAsync(id, updateBody, context).block();
    }

    /**
     * Update files in Syms.
     *
     * @param id The name of the database to be updated.
     * @param updateBody The body for the update request.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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 MetastoreUpdationResponse update(String id, MetastoreUpdateObject updateBody) {
        return updateWithResponse(id, updateBody, Context.NONE).getValue();
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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<Void>> deleteWithResponseAsync(String id) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.delete(this.client.getEndpoint(), apiVersion, id, accept, context));
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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<Void>> deleteWithResponseAsync(String id, Context context) {
        final String apiVersion = "2021-07-01-preview";
        final String accept = "application/json";
        return service.delete(this.client.getEndpoint(), apiVersion, id, accept, context);
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> deleteAsync(String id) {
        return deleteWithResponseAsync(id).flatMap(ignored -> Mono.empty());
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return A {@link Mono} that completes when a successful response is received.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Void> deleteAsync(String id, Context context) {
        return deleteWithResponseAsync(id, context).flatMap(ignored -> Mono.empty());
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException 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}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<Void> deleteWithResponse(String id, Context context) {
        return deleteWithResponseAsync(id, context).block();
    }

    /**
     * Remove files in Syms.
     *
     * @param id The id parameter.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorContractException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public void delete(String id) {
        deleteWithResponse(id, Context.NONE);
    }
}
