// 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.models.ErrorResponseException;
import com.azure.ai.personalizer.models.PersonalizerRewardOptions;
import com.azure.core.annotation.BodyParam;
import com.azure.core.annotation.ExpectedResponses;
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.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 Events. */
public final class EventsImpl {
    /** The proxy service used to perform REST calls. */
    private final EventsService service;

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

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

    /**
     * The interface defining all the services for PersonalizerClientV1Preview3Events to be used by the proxy service to
     * perform REST calls.
     */
    @Host("{Endpoint}/personalizer/{ApiVersion}")
    @ServiceInterface(name = "PersonalizerClientV1")
    public interface EventsService {
        @Post("/events/{eventId}/reward")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<Void>> reward(
                @HostParam("Endpoint") String endpoint,
                @HostParam("ApiVersion") String apiVersion,
                @PathParam("eventId") String eventId,
                @BodyParam("application/json") PersonalizerRewardOptions reward,
                @HeaderParam("Accept") String accept,
                Context context);

        @Post("/events/{eventId}/activate")
        @ExpectedResponses({204})
        @UnexpectedResponseExceptionType(ErrorResponseException.class)
        Mono<Response<Void>> activate(
                @HostParam("Endpoint") String endpoint,
                @HostParam("ApiVersion") String apiVersion,
                @PathParam("eventId") String eventId,
                @HeaderParam("Accept") String accept,
                Context context);
    }

    /**
     * Post Reward.
     *
     * <p>Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the
     * specified event.
     *
     * @param eventId The event id this reward applies to.
     * @param reward The reward should be a floating point number, typically between 0 and 1.
     * @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>> rewardWithResponseAsync(String eventId, PersonalizerRewardOptions reward) {
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.reward(
                                this.client.getEndpoint(),
                                this.client.getApiVersion(),
                                eventId,
                                reward,
                                accept,
                                context));
    }

    /**
     * Post Reward.
     *
     * <p>Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the
     * specified event.
     *
     * @param eventId The event id this reward applies to.
     * @param reward The reward should be a floating point number, typically between 0 and 1.
     * @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>> rewardWithResponseAsync(
            String eventId, PersonalizerRewardOptions reward, Context context) {
        final String accept = "application/json";
        return service.reward(this.client.getEndpoint(), this.client.getApiVersion(), eventId, reward, accept, context);
    }

    /**
     * Post Reward.
     *
     * <p>Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the
     * specified event.
     *
     * @param eventId The event id this reward applies to.
     * @param reward The reward should be a floating point number, typically between 0 and 1.
     * @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> rewardAsync(String eventId, PersonalizerRewardOptions reward) {
        return rewardWithResponseAsync(eventId, reward).flatMap(ignored -> Mono.empty());
    }

    /**
     * Post Reward.
     *
     * <p>Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the
     * specified event.
     *
     * @param eventId The event id this reward applies to.
     * @param reward The reward should be a floating point number, typically between 0 and 1.
     * @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> rewardAsync(String eventId, PersonalizerRewardOptions reward, Context context) {
        return rewardWithResponseAsync(eventId, reward, context).flatMap(ignored -> Mono.empty());
    }

    /**
     * Post Reward.
     *
     * <p>Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the
     * specified event.
     *
     * @param eventId The event id this reward applies to.
     * @param reward The reward should be a floating point number, typically between 0 and 1.
     * @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 reward(String eventId, PersonalizerRewardOptions reward) {
        rewardAsync(eventId, reward).block();
    }

    /**
     * Post Reward.
     *
     * <p>Report reward between 0 and 1 that resulted from using the action specified in rewardActionId, for the
     * specified event.
     *
     * @param eventId The event id this reward applies to.
     * @param reward The reward should be a floating point number, typically between 0 and 1.
     * @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> rewardWithResponse(String eventId, PersonalizerRewardOptions reward, Context context) {
        return rewardWithResponseAsync(eventId, reward, context).block();
    }

    /**
     * Activate Event.
     *
     * <p>Report that the specified event was actually used (e.g. by being displayed to the user) and a reward should be
     * expected for it.
     *
     * @param eventId The event ID to be activated.
     * @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>> activateWithResponseAsync(String eventId) {
        final String accept = "application/json";
        return FluxUtil.withContext(
                context ->
                        service.activate(
                                this.client.getEndpoint(), this.client.getApiVersion(), eventId, accept, context));
    }

    /**
     * Activate Event.
     *
     * <p>Report that the specified event was actually used (e.g. by being displayed to the user) and a reward should be
     * expected for it.
     *
     * @param eventId The event ID to be activated.
     * @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>> activateWithResponseAsync(String eventId, Context context) {
        final String accept = "application/json";
        return service.activate(this.client.getEndpoint(), this.client.getApiVersion(), eventId, accept, context);
    }

    /**
     * Activate Event.
     *
     * <p>Report that the specified event was actually used (e.g. by being displayed to the user) and a reward should be
     * expected for it.
     *
     * @param eventId The event ID to be activated.
     * @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> activateAsync(String eventId) {
        return activateWithResponseAsync(eventId).flatMap(ignored -> Mono.empty());
    }

    /**
     * Activate Event.
     *
     * <p>Report that the specified event was actually used (e.g. by being displayed to the user) and a reward should be
     * expected for it.
     *
     * @param eventId The event ID to be activated.
     * @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> activateAsync(String eventId, Context context) {
        return activateWithResponseAsync(eventId, context).flatMap(ignored -> Mono.empty());
    }

    /**
     * Activate Event.
     *
     * <p>Report that the specified event was actually used (e.g. by being displayed to the user) and a reward should be
     * expected for it.
     *
     * @param eventId The event ID to be activated.
     * @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 activate(String eventId) {
        activateAsync(eventId).block();
    }

    /**
     * Activate Event.
     *
     * <p>Report that the specified event was actually used (e.g. by being displayed to the user) and a reward should be
     * expected for it.
     *
     * @param eventId The event ID to be activated.
     * @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> activateWithResponse(String eventId, Context context) {
        return activateWithResponseAsync(eventId, context).block();
    }
}
