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

package com.azure.resourcemanager.securityinsights.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.annotation.JsonProperty;
import java.time.OffsetDateTime;
import java.util.List;

/** Describes automation rule triggering logic. */
@Fluent
public final class AutomationRuleTriggeringLogic {
    /*
     * Determines whether the automation rule is enabled or disabled.
     */
    @JsonProperty(value = "isEnabled", required = true)
    private boolean isEnabled;

    /*
     * Determines when the automation rule should automatically expire and be disabled.
     */
    @JsonProperty(value = "expirationTimeUtc")
    private OffsetDateTime expirationTimeUtc;

    /*
     * The triggersOn property.
     */
    @JsonProperty(value = "triggersOn", required = true)
    private TriggersOn triggersOn;

    /*
     * The triggersWhen property.
     */
    @JsonProperty(value = "triggersWhen", required = true)
    private TriggersWhen triggersWhen;

    /*
     * The conditions to evaluate to determine if the automation rule should be triggered on a given object.
     */
    @JsonProperty(value = "conditions")
    private List<AutomationRuleCondition> conditions;

    /**
     * Get the isEnabled property: Determines whether the automation rule is enabled or disabled.
     *
     * @return the isEnabled value.
     */
    public boolean isEnabled() {
        return this.isEnabled;
    }

    /**
     * Set the isEnabled property: Determines whether the automation rule is enabled or disabled.
     *
     * @param isEnabled the isEnabled value to set.
     * @return the AutomationRuleTriggeringLogic object itself.
     */
    public AutomationRuleTriggeringLogic withIsEnabled(boolean isEnabled) {
        this.isEnabled = isEnabled;
        return this;
    }

    /**
     * Get the expirationTimeUtc property: Determines when the automation rule should automatically expire and be
     * disabled.
     *
     * @return the expirationTimeUtc value.
     */
    public OffsetDateTime expirationTimeUtc() {
        return this.expirationTimeUtc;
    }

    /**
     * Set the expirationTimeUtc property: Determines when the automation rule should automatically expire and be
     * disabled.
     *
     * @param expirationTimeUtc the expirationTimeUtc value to set.
     * @return the AutomationRuleTriggeringLogic object itself.
     */
    public AutomationRuleTriggeringLogic withExpirationTimeUtc(OffsetDateTime expirationTimeUtc) {
        this.expirationTimeUtc = expirationTimeUtc;
        return this;
    }

    /**
     * Get the triggersOn property: The triggersOn property.
     *
     * @return the triggersOn value.
     */
    public TriggersOn triggersOn() {
        return this.triggersOn;
    }

    /**
     * Set the triggersOn property: The triggersOn property.
     *
     * @param triggersOn the triggersOn value to set.
     * @return the AutomationRuleTriggeringLogic object itself.
     */
    public AutomationRuleTriggeringLogic withTriggersOn(TriggersOn triggersOn) {
        this.triggersOn = triggersOn;
        return this;
    }

    /**
     * Get the triggersWhen property: The triggersWhen property.
     *
     * @return the triggersWhen value.
     */
    public TriggersWhen triggersWhen() {
        return this.triggersWhen;
    }

    /**
     * Set the triggersWhen property: The triggersWhen property.
     *
     * @param triggersWhen the triggersWhen value to set.
     * @return the AutomationRuleTriggeringLogic object itself.
     */
    public AutomationRuleTriggeringLogic withTriggersWhen(TriggersWhen triggersWhen) {
        this.triggersWhen = triggersWhen;
        return this;
    }

    /**
     * Get the conditions property: The conditions to evaluate to determine if the automation rule should be triggered
     * on a given object.
     *
     * @return the conditions value.
     */
    public List<AutomationRuleCondition> conditions() {
        return this.conditions;
    }

    /**
     * Set the conditions property: The conditions to evaluate to determine if the automation rule should be triggered
     * on a given object.
     *
     * @param conditions the conditions value to set.
     * @return the AutomationRuleTriggeringLogic object itself.
     */
    public AutomationRuleTriggeringLogic withConditions(List<AutomationRuleCondition> conditions) {
        this.conditions = conditions;
        return this;
    }

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

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