//----------------------------------------------------------------------- // // Copyright (c) aliasvault. All rights reserved. // Licensed under the AGPLv3 license. See LICENSE.md file in the project root for full license information. // //----------------------------------------------------------------------- namespace AliasServerDb; using System; using System.ComponentModel.DataAnnotations; using System.ComponentModel.DataAnnotations.Schema; using Microsoft.EntityFrameworkCore; /// /// A rate-limit / quota rule used by the API to throttle different types of usage. /// - set = per-user, /// - set = per-tier, /// - else global (most specific wins). /// - 0 = global maximum (all-time). > 0 = max allowed within a rolling window. /// - 0 = unlimited. /// [Index(nameof(LimitType), nameof(Enabled))] [Index(nameof(UserId))] [Index(nameof(Tier))] public class RateLimit { /// /// Gets or sets the unique identifier for the rule. /// [Key] public Guid Id { get; set; } /// /// Gets or sets the action this rule governs. /// public RateLimitType LimitType { get; set; } = RateLimitType.AliasCreation; /// /// Gets or sets the user this rule applies to (per-user override). Null for tier-level and global rules. /// [StringLength(255)] public string? UserId { get; set; } /// /// Gets or sets the navigation property to the user this rule applies to. /// [ForeignKey(nameof(UserId))] public virtual AliasVaultUser? User { get; set; } /// /// Gets or sets the account tier this rule applies to. Null for per-user and global rules. /// public AccountTier? Tier { get; set; } /// /// Gets or sets the rolling window length in seconds (0 = absolute cap on currently-held aliases). /// public int WindowSeconds { get; set; } /// /// Gets or sets the maximum allowed count for the window (0 = unlimited). /// public int MaxCount { get; set; } /// /// Gets or sets the account age (in days) below which the rule applies; null = applies regardless of age. /// Used to restrict new accounts more tightly (the limit lifts once the account is older). /// public int? AppliesToAccountAgeMaxDays { get; set; } /// /// Gets or sets a value indicating whether this rule is enforced. Disabled rules are retained for auditing. /// public bool Enabled { get; set; } = true; /// /// Gets or sets an optional note describing why the rule exists. /// [MaxLength(1000)] public string? Notes { get; set; } /// /// Gets or sets an optional UTC timestamp before which the rule is not enforced. /// public DateTime? EffectiveFrom { get; set; } /// /// Gets or sets an optional UTC timestamp after which the rule is no longer enforced. /// public DateTime? EffectiveUntil { get; set; } /// /// Gets or sets an optional identifier of who created the rule. /// [MaxLength(255)] public string? CreatedBy { get; set; } /// /// Gets or sets the creation date of the rule. /// public DateTime CreatedAt { get; set; } /// /// Gets or sets the last update date of the rule. /// public DateTime UpdatedAt { get; set; } }