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

package com.azure.resourcemanager.security.models;

import com.azure.core.annotation.Fluent;
import com.azure.core.util.logging.ClientLogger;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonSubTypes;
import com.fasterxml.jackson.annotation.JsonTypeInfo;
import com.fasterxml.jackson.annotation.JsonTypeName;
import java.time.Duration;

/**
 * A custom alert rule that checks if the number of activities (depends on the custom alert type) in a time window is
 * within the given range.
 */
@JsonTypeInfo(
    use = JsonTypeInfo.Id.NAME,
    include = JsonTypeInfo.As.PROPERTY,
    property = "ruleType",
    defaultImpl = TimeWindowCustomAlertRule.class)
@JsonTypeName("TimeWindowCustomAlertRule")
@JsonSubTypes({
    @JsonSubTypes.Type(name = "ActiveConnectionsNotInAllowedRange", value = ActiveConnectionsNotInAllowedRange.class),
    @JsonSubTypes.Type(name = "AmqpC2DMessagesNotInAllowedRange", value = AmqpC2DMessagesNotInAllowedRange.class),
    @JsonSubTypes.Type(name = "MqttC2DMessagesNotInAllowedRange", value = MqttC2DMessagesNotInAllowedRange.class),
    @JsonSubTypes.Type(name = "HttpC2DMessagesNotInAllowedRange", value = HttpC2DMessagesNotInAllowedRange.class),
    @JsonSubTypes.Type(
        name = "AmqpC2DRejectedMessagesNotInAllowedRange",
        value = AmqpC2DRejectedMessagesNotInAllowedRange.class),
    @JsonSubTypes.Type(
        name = "MqttC2DRejectedMessagesNotInAllowedRange",
        value = MqttC2DRejectedMessagesNotInAllowedRange.class),
    @JsonSubTypes.Type(
        name = "HttpC2DRejectedMessagesNotInAllowedRange",
        value = HttpC2DRejectedMessagesNotInAllowedRange.class),
    @JsonSubTypes.Type(name = "AmqpD2CMessagesNotInAllowedRange", value = AmqpD2CMessagesNotInAllowedRange.class),
    @JsonSubTypes.Type(name = "MqttD2CMessagesNotInAllowedRange", value = MqttD2CMessagesNotInAllowedRange.class),
    @JsonSubTypes.Type(name = "HttpD2CMessagesNotInAllowedRange", value = HttpD2CMessagesNotInAllowedRange.class),
    @JsonSubTypes.Type(
        name = "DirectMethodInvokesNotInAllowedRange",
        value = DirectMethodInvokesNotInAllowedRange.class),
    @JsonSubTypes.Type(name = "FailedLocalLoginsNotInAllowedRange", value = FailedLocalLoginsNotInAllowedRange.class),
    @JsonSubTypes.Type(name = "FileUploadsNotInAllowedRange", value = FileUploadsNotInAllowedRange.class),
    @JsonSubTypes.Type(name = "QueuePurgesNotInAllowedRange", value = QueuePurgesNotInAllowedRange.class),
    @JsonSubTypes.Type(name = "TwinUpdatesNotInAllowedRange", value = TwinUpdatesNotInAllowedRange.class),
    @JsonSubTypes.Type(
        name = "UnauthorizedOperationsNotInAllowedRange",
        value = UnauthorizedOperationsNotInAllowedRange.class)
})
@Fluent
public class TimeWindowCustomAlertRule extends ThresholdCustomAlertRule {
    /*
     * The time window size in iso8601 format.
     */
    @JsonProperty(value = "timeWindowSize", required = true)
    private Duration timeWindowSize;

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

    /**
     * Get the timeWindowSize property: The time window size in iso8601 format.
     *
     * @return the timeWindowSize value.
     */
    public Duration timeWindowSize() {
        return this.timeWindowSize;
    }

    /**
     * Set the timeWindowSize property: The time window size in iso8601 format.
     *
     * @param timeWindowSize the timeWindowSize value to set.
     * @return the TimeWindowCustomAlertRule object itself.
     */
    public TimeWindowCustomAlertRule withTimeWindowSize(Duration timeWindowSize) {
        this.timeWindowSize = timeWindowSize;
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public TimeWindowCustomAlertRule withMinThreshold(int minThreshold) {
        super.withMinThreshold(minThreshold);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public TimeWindowCustomAlertRule withMaxThreshold(int maxThreshold) {
        super.withMaxThreshold(maxThreshold);
        return this;
    }

    /** {@inheritDoc} */
    @Override
    public TimeWindowCustomAlertRule withIsEnabled(boolean isEnabled) {
        super.withIsEnabled(isEnabled);
        return this;
    }

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

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