using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using ZB.MOM.WW.ScadaBridge.Commons.Entities.ExternalSystems; namespace ZB.MOM.WW.ScadaBridge.ConfigurationDatabase.Configurations; public class ExternalSystemDefinitionConfiguration : IEntityTypeConfiguration { /// Applies the EF Core entity type configuration for . /// The entity type builder to configure. public void Configure(EntityTypeBuilder builder) { builder.HasKey(e => e.Id); builder.Property(e => e.Name) .IsRequired() .HasMaxLength(200); builder.Property(e => e.EndpointUrl) .IsRequired() .HasMaxLength(2000); builder.Property(e => e.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(e => e.AuthConfiguration) .HasMaxLength(8000); builder.Property(e => e.TimeoutSeconds).HasDefaultValue(0); builder.HasMany() .WithOne() .HasForeignKey(m => m.ExternalSystemDefinitionId) .OnDelete(DeleteBehavior.Cascade); builder.HasIndex(e => e.Name).IsUnique(); } } public class ExternalSystemMethodConfiguration : IEntityTypeConfiguration { /// Applies the EF Core entity type configuration for . /// The entity type builder to configure. public void Configure(EntityTypeBuilder builder) { builder.HasKey(m => m.Id); builder.Property(m => m.Name) .IsRequired() .HasMaxLength(200); builder.Property(m => m.HttpMethod) .IsRequired() .HasMaxLength(10); builder.Property(m => m.Path) .IsRequired() .HasMaxLength(2000); builder.Property(m => m.ParameterDefinitions) .HasMaxLength(4000); builder.Property(m => m.ReturnDefinition) .HasMaxLength(4000); builder.HasIndex(m => new { m.ExternalSystemDefinitionId, m.Name }).IsUnique(); } } public class DatabaseConnectionDefinitionConfiguration : IEntityTypeConfiguration { /// Applies the EF Core entity type configuration for . /// The entity type builder to configure. public void Configure(EntityTypeBuilder builder) { builder.HasKey(d => d.Id); builder.Property(d => d.Name) .IsRequired() .HasMaxLength(200); // Stored encrypted at rest (EncryptedStringConverter). Ciphertext is larger than // the plaintext, so the column is sized generously to avoid truncation. builder.Property(d => d.ConnectionString) .IsRequired() .HasMaxLength(8000); builder.HasIndex(d => d.Name).IsUnique(); } }