using System.Text.RegularExpressions; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Authinator.Backend.Database.Tables; public class ACL { public int Id { get; } public string Name { get; set; } = null!; public bool Enabled { get; set; } = true; public string Target { get; set; } = null!; public bool TargetIsRegex { get; set; } public List Users { get; set; } = new(); public List Groups { get; set; } = new(); public List Networks { get; set; } = new(); public class Configuration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder acl) { acl.ToTable("ACLs"); acl.HasKey(p => p.Id); acl.Property(b => b.Name).HasColumnName("Name").IsRequired(); acl.Property(p => p.Target).HasColumnName("Target").IsRequired(); acl.Property(p => p.Enabled).HasColumnName("Enabled").IsRequired(); acl.Property(p => p.TargetIsRegex).HasColumnName("TargetIsRegex").HasDefaultValue(false); acl.HasMany(p => p.Networks).WithMany(); acl.HasMany(p => p.Groups).WithMany(); acl.HasMany(p => p.Users).WithMany(); } } private bool Equals(ACL other) => Id == other.Id; public override bool Equals(object? obj) { if (ReferenceEquals(null, obj)) return false; if (ReferenceEquals(this, obj)) return true; return obj.GetType() == GetType() && Equals((ACL)obj); } public override int GetHashCode() => Id; public static bool operator ==(ACL? left, ACL? right) => Equals(left, right); public static bool operator !=(ACL? left, ACL? right) => !Equals(left, right); }