using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using ZB.MOM.WW.ScadaBridge.Commons.Entities.Notifications; namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Configurations; public class NotificationListConfiguration : IEntityTypeConfiguration { /// Configures the EF Core mapping for . /// The entity type builder. public void Configure(EntityTypeBuilder builder) { builder.HasKey(n => n.Id); builder.Property(n => n.Name) .IsRequired() .HasMaxLength(200); builder.Property(n => n.Type) .HasConversion() .HasMaxLength(32) .IsRequired(); builder.HasMany(n => n.Recipients) .WithOne() .HasForeignKey(r => r.NotificationListId) .OnDelete(DeleteBehavior.Cascade); builder.HasIndex(n => n.Name).IsUnique(); } } public class NotificationRecipientConfiguration : IEntityTypeConfiguration { /// Configures the EF Core mapping for . /// The entity type builder. public void Configure(EntityTypeBuilder builder) { builder.HasKey(r => r.Id); builder.Property(r => r.Name) .IsRequired() .HasMaxLength(200); // EmailAddress is now nullable — an SMS-only recipient carries a PhoneNumber and no // email. The max length is unchanged from the original email-only mapping. builder.Property(r => r.EmailAddress) .IsRequired(false) .HasMaxLength(500); // PhoneNumber (E.164, e.g. +14155552671) — nullable, present only for SMS recipients. builder.Property(r => r.PhoneNumber) .IsRequired(false) .HasMaxLength(32); } } public class SmsConfigurationConfiguration : IEntityTypeConfiguration { /// public void Configure(EntityTypeBuilder builder) { builder.HasKey(s => s.Id); builder.Property(s => s.AccountSid) .IsRequired() .HasMaxLength(100); // Stored encrypted at rest (EncryptedStringConverter, wired in // ScadaBridgeDbContext.ApplySecretColumnEncryption). Ciphertext is larger than the // plaintext, so the column is sized generously to avoid truncation — mirrors // SmtpConfiguration.Credentials. builder.Property(s => s.AuthToken) .HasMaxLength(8000); // Optional: a Twilio Messaging-Service-only config has no From number (a valid // config carries a FromNumber and/or a MessagingServiceSid). builder.Property(s => s.FromNumber) .IsRequired(false) .HasMaxLength(32); builder.Property(s => s.MessagingServiceSid) .HasMaxLength(100); builder.Property(s => s.ApiBaseUrl) .HasMaxLength(500); // The non-parameter constructor seeds ConnectionTimeoutSeconds/MaxRetries/RetryDelay // with sensible defaults; mapping them as REQUIRED columns preserves round-trip // fidelity for those values (S1 review note). builder.Property(s => s.ConnectionTimeoutSeconds) .IsRequired(); builder.Property(s => s.MaxRetries) .IsRequired(); builder.Property(s => s.RetryDelay) .IsRequired(); } } public class SmtpConfigurationConfiguration : IEntityTypeConfiguration { /// Configures the EF Core mapping for . /// The entity type builder. public void Configure(EntityTypeBuilder builder) { builder.HasKey(s => s.Id); builder.Property(s => s.Host) .IsRequired() .HasMaxLength(500); builder.Property(s => s.AuthType) .IsRequired() .HasMaxLength(50); // Stored encrypted at rest (EncryptedStringConverter). Ciphertext is larger than // the plaintext, so the column is sized generously to avoid truncation. builder.Property(s => s.Credentials) .HasMaxLength(8000); builder.Property(s => s.TlsMode) .HasMaxLength(50); builder.Property(s => s.FromAddress) .IsRequired() .HasMaxLength(500); } }