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

package com.azure.resourcemanager.iothub.models;

import com.azure.core.annotation.Fluent;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;

/**
 * The routing related properties of the IoT hub. See:
 * https://docs.microsoft.com/azure/iot-hub/iot-hub-devguide-messaging.
 */
@Fluent
public final class RoutingProperties {
    /*
     * The properties related to the custom endpoints to which your IoT hub routes messages based on the routing rules.
     * A maximum of 10 custom endpoints are allowed across all endpoint types for paid hubs and only 1 custom endpoint
     * is allowed across all endpoint types for free hubs.
     */
    @JsonProperty(value = "endpoints")
    private RoutingEndpoints endpoints;

    /*
     * The list of user-provided routing rules that the IoT hub uses to route messages to built-in and custom
     * endpoints. A maximum of 100 routing rules are allowed for paid hubs and a maximum of 5 routing rules are allowed
     * for free hubs.
     */
    @JsonProperty(value = "routes")
    private List<RouteProperties> routes;

    /*
     * The properties of the route that is used as a fall-back route when none of the conditions specified in the
     * 'routes' section are met. This is an optional parameter. When this property is not set, the messages which do
     * not meet any of the conditions specified in the 'routes' section get routed to the built-in eventhub endpoint.
     */
    @JsonProperty(value = "fallbackRoute")
    private FallbackRouteProperties fallbackRoute;

    /*
     * The list of user-provided enrichments that the IoT hub applies to messages to be delivered to built-in and
     * custom endpoints. See: https://aka.ms/telemetryoneventgrid
     */
    @JsonProperty(value = "enrichments")
    private List<EnrichmentProperties> enrichments;

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

    /**
     * Get the endpoints property: The properties related to the custom endpoints to which your IoT hub routes messages
     * based on the routing rules. A maximum of 10 custom endpoints are allowed across all endpoint types for paid hubs
     * and only 1 custom endpoint is allowed across all endpoint types for free hubs.
     *
     * @return the endpoints value.
     */
    public RoutingEndpoints endpoints() {
        return this.endpoints;
    }

    /**
     * Set the endpoints property: The properties related to the custom endpoints to which your IoT hub routes messages
     * based on the routing rules. A maximum of 10 custom endpoints are allowed across all endpoint types for paid hubs
     * and only 1 custom endpoint is allowed across all endpoint types for free hubs.
     *
     * @param endpoints the endpoints value to set.
     * @return the RoutingProperties object itself.
     */
    public RoutingProperties withEndpoints(RoutingEndpoints endpoints) {
        this.endpoints = endpoints;
        return this;
    }

    /**
     * Get the routes property: The list of user-provided routing rules that the IoT hub uses to route messages to
     * built-in and custom endpoints. A maximum of 100 routing rules are allowed for paid hubs and a maximum of 5
     * routing rules are allowed for free hubs.
     *
     * @return the routes value.
     */
    public List<RouteProperties> routes() {
        return this.routes;
    }

    /**
     * Set the routes property: The list of user-provided routing rules that the IoT hub uses to route messages to
     * built-in and custom endpoints. A maximum of 100 routing rules are allowed for paid hubs and a maximum of 5
     * routing rules are allowed for free hubs.
     *
     * @param routes the routes value to set.
     * @return the RoutingProperties object itself.
     */
    public RoutingProperties withRoutes(List<RouteProperties> routes) {
        this.routes = routes;
        return this;
    }

    /**
     * Get the fallbackRoute property: The properties of the route that is used as a fall-back route when none of the
     * conditions specified in the 'routes' section are met. This is an optional parameter. When this property is not
     * set, the messages which do not meet any of the conditions specified in the 'routes' section get routed to the
     * built-in eventhub endpoint.
     *
     * @return the fallbackRoute value.
     */
    public FallbackRouteProperties fallbackRoute() {
        return this.fallbackRoute;
    }

    /**
     * Set the fallbackRoute property: The properties of the route that is used as a fall-back route when none of the
     * conditions specified in the 'routes' section are met. This is an optional parameter. When this property is not
     * set, the messages which do not meet any of the conditions specified in the 'routes' section get routed to the
     * built-in eventhub endpoint.
     *
     * @param fallbackRoute the fallbackRoute value to set.
     * @return the RoutingProperties object itself.
     */
    public RoutingProperties withFallbackRoute(FallbackRouteProperties fallbackRoute) {
        this.fallbackRoute = fallbackRoute;
        return this;
    }

    /**
     * Get the enrichments property: The list of user-provided enrichments that the IoT hub applies to messages to be
     * delivered to built-in and custom endpoints. See: https://aka.ms/telemetryoneventgrid.
     *
     * @return the enrichments value.
     */
    public List<EnrichmentProperties> enrichments() {
        return this.enrichments;
    }

    /**
     * Set the enrichments property: The list of user-provided enrichments that the IoT hub applies to messages to be
     * delivered to built-in and custom endpoints. See: https://aka.ms/telemetryoneventgrid.
     *
     * @param enrichments the enrichments value to set.
     * @return the RoutingProperties object itself.
     */
    public RoutingProperties withEnrichments(List<EnrichmentProperties> enrichments) {
        this.enrichments = enrichments;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (endpoints() != null) {
            endpoints().validate();
        }
        if (routes() != null) {
            routes().forEach(e -> e.validate());
        }
        if (fallbackRoute() != null) {
            fallbackRoute().validate();
        }
        if (enrichments() != null) {
            enrichments().forEach(e -> e.validate());
        }
    }
}
