// 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;
import java.util.List;

/** Properties of event handler. */
@Fluent
public final class EventHandler {
    /*
     * Gets or sets the EventHandler URL template. You can use a predefined parameter {hub} and {event} inside the
     * template, the value of the EventHandler URL is dynamically calculated when the client request comes in.
     * For example, UrlTemplate can be `http://example.com/api/{hub}/{event}`. The host part can't contains parameters.
     */
    @JsonProperty(value = "urlTemplate", required = true)
    private String urlTemplate;

    /*
     * Gets or sets the matching pattern for event names.
     * There are 3 kinds of patterns supported:
     * 1. "*", it matches any event name
     * 2. Combine multiple events with ",", for example "event1,event2", it matches event "event1" and "event2"
     * 3. A single event name, for example, "event1", it matches "event1"
     */
    @JsonProperty(value = "userEventPattern")
    private String userEventPattern;

    /*
     * Gets or sets the list of system events.
     */
    @JsonProperty(value = "systemEvents")
    private List<String> systemEvents;

    /*
     * Upstream auth settings. If not set, no auth is used for upstream messages.
     */
    @JsonProperty(value = "auth")
    private UpstreamAuthSettings auth;

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

    /**
     * Get the urlTemplate property: Gets or sets the EventHandler URL template. You can use a predefined parameter
     * {hub} and {event} inside the template, the value of the EventHandler URL is dynamically calculated when the
     * client request comes in. For example, UrlTemplate can be `http://example.com/api/{hub}/{event}`. The host part
     * can't contains parameters.
     *
     * @return the urlTemplate value.
     */
    public String urlTemplate() {
        return this.urlTemplate;
    }

    /**
     * Set the urlTemplate property: Gets or sets the EventHandler URL template. You can use a predefined parameter
     * {hub} and {event} inside the template, the value of the EventHandler URL is dynamically calculated when the
     * client request comes in. For example, UrlTemplate can be `http://example.com/api/{hub}/{event}`. The host part
     * can't contains parameters.
     *
     * @param urlTemplate the urlTemplate value to set.
     * @return the EventHandler object itself.
     */
    public EventHandler withUrlTemplate(String urlTemplate) {
        this.urlTemplate = urlTemplate;
        return this;
    }

    /**
     * Get the userEventPattern property: Gets or sets the matching pattern for event names. There are 3 kinds of
     * patterns supported: 1. "*", it matches any event name 2. Combine multiple events with ",", for example
     * "event1,event2", it matches event "event1" and "event2" 3. A single event name, for example, "event1", it matches
     * "event1".
     *
     * @return the userEventPattern value.
     */
    public String userEventPattern() {
        return this.userEventPattern;
    }

    /**
     * Set the userEventPattern property: Gets or sets the matching pattern for event names. There are 3 kinds of
     * patterns supported: 1. "*", it matches any event name 2. Combine multiple events with ",", for example
     * "event1,event2", it matches event "event1" and "event2" 3. A single event name, for example, "event1", it matches
     * "event1".
     *
     * @param userEventPattern the userEventPattern value to set.
     * @return the EventHandler object itself.
     */
    public EventHandler withUserEventPattern(String userEventPattern) {
        this.userEventPattern = userEventPattern;
        return this;
    }

    /**
     * Get the systemEvents property: Gets or sets the list of system events.
     *
     * @return the systemEvents value.
     */
    public List<String> systemEvents() {
        return this.systemEvents;
    }

    /**
     * Set the systemEvents property: Gets or sets the list of system events.
     *
     * @param systemEvents the systemEvents value to set.
     * @return the EventHandler object itself.
     */
    public EventHandler withSystemEvents(List<String> systemEvents) {
        this.systemEvents = systemEvents;
        return this;
    }

    /**
     * Get the auth property: Upstream auth settings. If not set, no auth is used for upstream messages.
     *
     * @return the auth value.
     */
    public UpstreamAuthSettings auth() {
        return this.auth;
    }

    /**
     * Set the auth property: Upstream auth settings. If not set, no auth is used for upstream messages.
     *
     * @param auth the auth value to set.
     * @return the EventHandler object itself.
     */
    public EventHandler withAuth(UpstreamAuthSettings auth) {
        this.auth = auth;
        return this;
    }

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

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