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

package com.azure.resourcemanager.webpubsub.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.annotation.JsonProperty;

/** A setting defines which kinds of events should be sent to which endpoint. */
@Fluent
public final class EventListener {
    /*
     * A base class for event filter which determines whether an event should be sent to an event listener.
     */
    @JsonProperty(value = "filter", required = true)
    private EventListenerFilter filter;

    /*
     * An endpoint specifying where Web PubSub should send events to.
     */
    @JsonProperty(value = "endpoint", required = true)
    private EventListenerEndpoint endpoint;

    /** Creates an instance of EventListener class. */
    public EventListener() {
    }

    /**
     * Get the filter property: A base class for event filter which determines whether an event should be sent to an
     * event listener.
     *
     * @return the filter value.
     */
    public EventListenerFilter filter() {
        return this.filter;
    }

    /**
     * Set the filter property: A base class for event filter which determines whether an event should be sent to an
     * event listener.
     *
     * @param filter the filter value to set.
     * @return the EventListener object itself.
     */
    public EventListener withFilter(EventListenerFilter filter) {
        this.filter = filter;
        return this;
    }

    /**
     * Get the endpoint property: An endpoint specifying where Web PubSub should send events to.
     *
     * @return the endpoint value.
     */
    public EventListenerEndpoint endpoint() {
        return this.endpoint;
    }

    /**
     * Set the endpoint property: An endpoint specifying where Web PubSub should send events to.
     *
     * @param endpoint the endpoint value to set.
     * @return the EventListener object itself.
     */
    public EventListener withEndpoint(EventListenerEndpoint endpoint) {
        this.endpoint = endpoint;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (filter() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property filter in model EventListener"));
        } else {
            filter().validate();
        }
        if (endpoint() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException("Missing required property endpoint in model EventListener"));
        } else {
            endpoint().validate();
        }
    }

    private static final ClientLogger LOGGER = new ClientLogger(EventListener.class);
}
