// 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.PersonalizerPolicy;
import com.azure.ai.personalizer.models.ErrorResponseException;
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.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 Policies. */
public final class PoliciesImpl {
    /** The proxy service used to perform REST calls. */
    private final PoliciesService service;

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

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

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

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

        @Delete("/configurations/policy")
        @ExpectedResponses({200})
        @UnexpectedResponseExceptionType(HttpResponseException.class)
        Mono<Response<PersonalizerPolicy>> reset(
                @HostParam("Endpoint") String endpoint,
                @HostParam("ApiVersion") String apiVersion,
                @HeaderParam("Accept") String accept,
                Context context);
    }

    /**
     * Get Policy.
     *
     * <p>Get the Learning Settings currently used by the Personalizer service.
     *
     * @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 Learning Settings currently used by the Personalizer service along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<PersonalizerPolicy>> getWithResponseAsync() {
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.get(this.client.getEndpoint(), this.client.getApiVersion(), accept, context));
    }

    /**
     * Get Policy.
     *
     * <p>Get the Learning Settings currently used by the Personalizer service.
     *
     * @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 Learning Settings currently used by the Personalizer service along with {@link Response} on
     *     successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<PersonalizerPolicy>> getWithResponseAsync(Context context) {
        final String accept = "application/json";
        return service.get(this.client.getEndpoint(), this.client.getApiVersion(), accept, context);
    }

    /**
     * Get Policy.
     *
     * <p>Get the Learning Settings currently used by the Personalizer service.
     *
     * @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 Learning Settings currently used by the Personalizer service on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PersonalizerPolicy> getAsync() {
        return getWithResponseAsync().flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get Policy.
     *
     * <p>Get the Learning Settings currently used by the Personalizer service.
     *
     * @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 Learning Settings currently used by the Personalizer service on successful completion of {@link
     *     Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PersonalizerPolicy> getAsync(Context context) {
        return getWithResponseAsync(context).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Get Policy.
     *
     * <p>Get the Learning Settings currently used by the Personalizer service.
     *
     * @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 Learning Settings currently used by the Personalizer service.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PersonalizerPolicy get() {
        return getAsync().block();
    }

    /**
     * Get Policy.
     *
     * <p>Get the Learning Settings currently used by the Personalizer service.
     *
     * @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 Learning Settings currently used by the Personalizer service along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<PersonalizerPolicy> getWithResponse(Context context) {
        return getWithResponseAsync(context).block();
    }

    /**
     * Update Policy.
     *
     * <p>Update the Learning Settings that the Personalizer service will use to train models.
     *
     * @param policy The learning settings.
     * @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 learning settings specifying how to train the model along with {@link Response} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<PersonalizerPolicy>> updateWithResponseAsync(PersonalizerPolicy policy) {
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.update(
                                this.client.getEndpoint(), this.client.getApiVersion(), policy, accept, context));
    }

    /**
     * Update Policy.
     *
     * <p>Update the Learning Settings that the Personalizer service will use to train models.
     *
     * @param policy The learning settings.
     * @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 learning settings specifying how to train the model along with {@link Response} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<PersonalizerPolicy>> updateWithResponseAsync(PersonalizerPolicy policy, Context context) {
        final String accept = "application/json";
        return service.update(this.client.getEndpoint(), this.client.getApiVersion(), policy, accept, context);
    }

    /**
     * Update Policy.
     *
     * <p>Update the Learning Settings that the Personalizer service will use to train models.
     *
     * @param policy The learning settings.
     * @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 learning settings specifying how to train the model on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PersonalizerPolicy> updateAsync(PersonalizerPolicy policy) {
        return updateWithResponseAsync(policy).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Update Policy.
     *
     * <p>Update the Learning Settings that the Personalizer service will use to train models.
     *
     * @param policy The learning settings.
     * @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 learning settings specifying how to train the model on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PersonalizerPolicy> updateAsync(PersonalizerPolicy policy, Context context) {
        return updateWithResponseAsync(policy, context).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Update Policy.
     *
     * <p>Update the Learning Settings that the Personalizer service will use to train models.
     *
     * @param policy The learning settings.
     * @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 learning settings specifying how to train the model.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PersonalizerPolicy update(PersonalizerPolicy policy) {
        return updateAsync(policy).block();
    }

    /**
     * Update Policy.
     *
     * <p>Update the Learning Settings that the Personalizer service will use to train models.
     *
     * @param policy The learning settings.
     * @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 learning settings specifying how to train the model along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<PersonalizerPolicy> updateWithResponse(PersonalizerPolicy policy, Context context) {
        return updateWithResponseAsync(policy, context).block();
    }

    /**
     * Reset Policy.
     *
     * <p>Resets the learning settings of the Personalizer service to default.
     *
     * @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 learning settings specifying how to train the model along with {@link Response} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<PersonalizerPolicy>> resetWithResponseAsync() {
        final String accept = "application/json";
        return FluxUtil.withContext(
                context -> service.reset(this.client.getEndpoint(), this.client.getApiVersion(), accept, context));
    }

    /**
     * Reset Policy.
     *
     * <p>Resets the learning settings of the Personalizer service to default.
     *
     * @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 learning settings specifying how to train the model along with {@link Response} on successful completion
     *     of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<Response<PersonalizerPolicy>> resetWithResponseAsync(Context context) {
        final String accept = "application/json";
        return service.reset(this.client.getEndpoint(), this.client.getApiVersion(), accept, context);
    }

    /**
     * Reset Policy.
     *
     * <p>Resets the learning settings of the Personalizer service to default.
     *
     * @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 learning settings specifying how to train the model on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PersonalizerPolicy> resetAsync() {
        return resetWithResponseAsync().flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Reset Policy.
     *
     * <p>Resets the learning settings of the Personalizer service to default.
     *
     * @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 learning settings specifying how to train the model on successful completion of {@link Mono}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Mono<PersonalizerPolicy> resetAsync(Context context) {
        return resetWithResponseAsync(context).flatMap(res -> Mono.justOrEmpty(res.getValue()));
    }

    /**
     * Reset Policy.
     *
     * <p>Resets the learning settings of the Personalizer service to default.
     *
     * @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 learning settings specifying how to train the model.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public PersonalizerPolicy reset() {
        return resetAsync().block();
    }

    /**
     * Reset Policy.
     *
     * <p>Resets the learning settings of the Personalizer service to default.
     *
     * @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 learning settings specifying how to train the model along with {@link Response}.
     */
    @ServiceMethod(returns = ReturnType.SINGLE)
    public Response<PersonalizerPolicy> resetWithResponse(Context context) {
        return resetWithResponseAsync(context).block();
    }
}
