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

package com.azure.ai.personalizer.implementation;

import com.azure.ai.personalizer.administration.models.PersonalizerPolicyReferenceOptions;
import com.azure.ai.personalizer.administration.models.PersonalizerServiceProperties;
import com.azure.ai.personalizer.models.ErrorResponseException;
import com.azure.core.annotation.BodyParam;
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.Post;
import com.azure.core.annotation.Put;
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.exception.HttpResponseException;
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 ServiceConfigurations. */
public final class ServiceConfigurationsImpl {
    /** The proxy service used to perform REST calls. */
    private final ServiceConfigurationsService service;

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

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

    /**
     * The interface defining all the services for PersonalizerClientV1Preview3ServiceConfigurations to be used by the
     * proxy service to perform REST calls.
     */
    @Host("{Endpoint}/personalizer/{ApiVersion}")
    @ServiceInterface(name = "PersonalizerClientV1")
    public interface ServiceConfigurationsService {
        @Get("/configurations/service")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(HttpResponseException.class)
        Mono<Response<PersonalizerServiceProperties>> get(
                @HostParam("Endpoint") String endpoint,
                @HostParam("ApiVersion") String apiVersion,
                @HeaderParam("Accept") String accept,
                Context context);

        @Put("/configurations/service")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<PersonalizerServiceProperties>> update(
                @HostParam("Endpoint") String endpoint,
                @HostParam("ApiVersion") String apiVersion,
                @BodyParam("application/json") PersonalizerServiceProperties config,
                @HeaderParam("Accept") String accept,
                Context context);

        @Post("/configurations/applyFromEvaluation")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<Void>> applyFromEvaluation(
                @HostParam("Endpoint") String endpoint,
                @HostParam("ApiVersion") String apiVersion,
                @BodyParam("application/json") PersonalizerPolicyReferenceOptions body,
                @HeaderParam("Accept") String accept,
                Context context);
    }

    /**
     * Get Service Configuration.
     *
     * <p>Get the Personalizer service configuration.
     *
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Personalizer service configuration along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<PersonalizerServiceProperties>> getWithResponseAsync() {
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.get(this.client.getEndpoint(), this.client.getApiVersion(), accept, context));
    }

    /**
     * Get Service Configuration.
     *
     * <p>Get the Personalizer service configuration.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Personalizer service configuration along with {@link Response} on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<PersonalizerServiceProperties>> getWithResponseAsync(Context context) {
        final String accept = "application/json";
        return service.get(this.client.getEndpoint(), this.client.getApiVersion(), accept, context);
    }

    /**
     * Get Service Configuration.
     *
     * <p>Get the Personalizer service configuration.
     *
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Personalizer service configuration on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PersonalizerServiceProperties> getAsync() {
        return getWithResponseAsync().flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get Service Configuration.
     *
     * <p>Get the Personalizer service configuration.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Personalizer service configuration on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PersonalizerServiceProperties> getAsync(Context context) {
        return getWithResponseAsync(context).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get Service Configuration.
     *
     * <p>Get the Personalizer service configuration.
     *
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Personalizer service configuration.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PersonalizerServiceProperties get() {
        return getAsync().block();
    }

    /**
     * Get Service Configuration.
     *
     * <p>Get the Personalizer service configuration.
     *
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws HttpResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the Personalizer service configuration along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<PersonalizerServiceProperties> getWithResponse(Context context) {
        return getWithResponseAsync(context).block();
    }

    /**
     * Update Service Configuration.
     *
     * <p>Update the Personalizer service configuration.
     *
     * @param config The personalizer service configuration.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the configuration of the service along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<PersonalizerServiceProperties>> updateWithResponseAsync(PersonalizerServiceProperties config) {
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.update(
                                this.client.getEndpoint(), this.client.getApiVersion(), config, accept, context));
    }

    /**
     * Update Service Configuration.
     *
     * <p>Update the Personalizer service configuration.
     *
     * @param config The personalizer service configuration.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the configuration of the service along with {@link Response} on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<PersonalizerServiceProperties>> updateWithResponseAsync(
            PersonalizerServiceProperties config, Context context) {
        final String accept = "application/json";
        return service.update(this.client.getEndpoint(), this.client.getApiVersion(), config, accept, context);
    }

    /**
     * Update Service Configuration.
     *
     * <p>Update the Personalizer service configuration.
     *
     * @param config The personalizer service configuration.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the configuration of the service on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PersonalizerServiceProperties> updateAsync(PersonalizerServiceProperties config) {
        return updateWithResponseAsync(config).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Update Service Configuration.
     *
     * <p>Update the Personalizer service configuration.
     *
     * @param config The personalizer service configuration.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the configuration of the service on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PersonalizerServiceProperties> updateAsync(PersonalizerServiceProperties config, Context context) {
        return updateWithResponseAsync(config, context).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Update Service Configuration.
     *
     * <p>Update the Personalizer service configuration.
     *
     * @param config The personalizer service configuration.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the configuration of the service.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PersonalizerServiceProperties update(PersonalizerServiceProperties config) {
        return updateAsync(config).block();
    }

    /**
     * Update Service Configuration.
     *
     * <p>Update the Personalizer service configuration.
     *
     * @param config The personalizer service configuration.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException thrown if the request is rejected by server.
     * @throws RuntimeException all other wrapped checked exceptions if the request fails to be sent.
     * @return the configuration of the service along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<PersonalizerServiceProperties> updateWithResponse(
            PersonalizerServiceProperties config, Context context) {
        return updateWithResponseAsync(config, context).block();
    }

    /**
     * Apply Learning Settings and model from a pre-existing Offline Evaluation, making them the current online Learning
     * Settings and model and replacing the previous ones.
     *
     * @param body Reference to the policy within the evaluation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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>> applyFromEvaluationWithResponseAsync(PersonalizerPolicyReferenceOptions body) {
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.applyFromEvaluation(
                                this.client.getEndpoint(), this.client.getApiVersion(), body, accept, context));
    }

    /**
     * Apply Learning Settings and model from a pre-existing Offline Evaluation, making them the current online Learning
     * Settings and model and replacing the previous ones.
     *
     * @param body Reference to the policy within the evaluation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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>> applyFromEvaluationWithResponseAsync(
            PersonalizerPolicyReferenceOptions body, Context context) {
        final String accept = "application/json";
        return service.applyFromEvaluation(
                this.client.getEndpoint(), this.client.getApiVersion(), body, accept, context);
    }

    /**
     * Apply Learning Settings and model from a pre-existing Offline Evaluation, making them the current online Learning
     * Settings and model and replacing the previous ones.
     *
     * @param body Reference to the policy within the evaluation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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> applyFromEvaluationAsync(PersonalizerPolicyReferenceOptions body) {
        return applyFromEvaluationWithResponseAsync(body).flatMap(ignored -> Mono.empty());
    }

    /**
     * Apply Learning Settings and model from a pre-existing Offline Evaluation, making them the current online Learning
     * Settings and model and replacing the previous ones.
     *
     * @param body Reference to the policy within the evaluation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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> applyFromEvaluationAsync(PersonalizerPolicyReferenceOptions body, Context context) {
        return applyFromEvaluationWithResponseAsync(body, context).flatMap(ignored -> Mono.empty());
    }

    /**
     * Apply Learning Settings and model from a pre-existing Offline Evaluation, making them the current online Learning
     * Settings and model and replacing the previous ones.
     *
     * @param body Reference to the policy within the evaluation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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 applyFromEvaluation(PersonalizerPolicyReferenceOptions body) {
        applyFromEvaluationAsync(body).block();
    }

    /**
     * Apply Learning Settings and model from a pre-existing Offline Evaluation, making them the current online Learning
     * Settings and model and replacing the previous ones.
     *
     * @param body Reference to the policy within the evaluation.
     * @param context The context to associate with this operation.
     * @throws IllegalArgumentException thrown if parameters fail the validation.
     * @throws ErrorResponseException 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> applyFromEvaluationWithResponse(PersonalizerPolicyReferenceOptions body, Context context) {
        return applyFromEvaluationWithResponseAsync(body, context).block();
    }
}
