using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; using ScadaLink.Commons.Entities.ExternalSystems; namespace ScadaLink.ConfigurationDatabase.Configurations; public class ExternalSystemDefinitionConfiguration : IEntityTypeConfiguration { 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); builder.Property(e => e.AuthConfiguration) .HasMaxLength(4000); builder.HasMany() .WithOne() .HasForeignKey(m => m.ExternalSystemDefinitionId) .OnDelete(DeleteBehavior.Cascade); builder.HasIndex(e => e.Name).IsUnique(); } } public class ExternalSystemMethodConfiguration : IEntityTypeConfiguration { 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 { public void Configure(EntityTypeBuilder builder) { builder.HasKey(d => d.Id); builder.Property(d => d.Name) .IsRequired() .HasMaxLength(200); builder.Property(d => d.ConnectionString) .IsRequired() .HasMaxLength(4000); builder.HasIndex(d => d.Name).IsUnique(); } }