// 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.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.util.List;

/** Network Rule Set Properties of IotHub. */
@Fluent
public final class NetworkRuleSetProperties {
    /*
     * Default Action for Network Rule Set
     */
    @JsonProperty(value = "defaultAction")
    private DefaultAction defaultAction;

    /*
     * If True, then Network Rule Set is also applied to BuiltIn EventHub EndPoint of IotHub
     */
    @JsonProperty(value = "applyToBuiltInEventHubEndpoint", required = true)
    private boolean applyToBuiltInEventHubEndpoint;

    /*
     * List of IP Rules
     */
    @JsonProperty(value = "ipRules", required = true)
    private List<NetworkRuleSetIpRule> ipRules;

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

    /**
     * Get the defaultAction property: Default Action for Network Rule Set.
     *
     * @return the defaultAction value.
     */
    public DefaultAction defaultAction() {
        return this.defaultAction;
    }

    /**
     * Set the defaultAction property: Default Action for Network Rule Set.
     *
     * @param defaultAction the defaultAction value to set.
     * @return the NetworkRuleSetProperties object itself.
     */
    public NetworkRuleSetProperties withDefaultAction(DefaultAction defaultAction) {
        this.defaultAction = defaultAction;
        return this;
    }

    /**
     * Get the applyToBuiltInEventHubEndpoint property: If True, then Network Rule Set is also applied to BuiltIn
     * EventHub EndPoint of IotHub.
     *
     * @return the applyToBuiltInEventHubEndpoint value.
     */
    public boolean applyToBuiltInEventHubEndpoint() {
        return this.applyToBuiltInEventHubEndpoint;
    }

    /**
     * Set the applyToBuiltInEventHubEndpoint property: If True, then Network Rule Set is also applied to BuiltIn
     * EventHub EndPoint of IotHub.
     *
     * @param applyToBuiltInEventHubEndpoint the applyToBuiltInEventHubEndpoint value to set.
     * @return the NetworkRuleSetProperties object itself.
     */
    public NetworkRuleSetProperties withApplyToBuiltInEventHubEndpoint(boolean applyToBuiltInEventHubEndpoint) {
        this.applyToBuiltInEventHubEndpoint = applyToBuiltInEventHubEndpoint;
        return this;
    }

    /**
     * Get the ipRules property: List of IP Rules.
     *
     * @return the ipRules value.
     */
    public List<NetworkRuleSetIpRule> ipRules() {
        return this.ipRules;
    }

    /**
     * Set the ipRules property: List of IP Rules.
     *
     * @param ipRules the ipRules value to set.
     * @return the NetworkRuleSetProperties object itself.
     */
    public NetworkRuleSetProperties withIpRules(List<NetworkRuleSetIpRule> ipRules) {
        this.ipRules = ipRules;
        return this;
    }

    /**
     * Validates the instance.
     *
     * @throws IllegalArgumentException thrown if the instance is not valid.
     */
    public void validate() {
        if (ipRules() == null) {
            throw LOGGER
                .logExceptionAsError(
                    new IllegalArgumentException(
                        "Missing required property ipRules in model NetworkRuleSetProperties"));
        } else {
            ipRules().forEach(e -> e.validate());
        }
    }

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