using Heimdall.Domain.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Heimdall.Infrastructure.Data.Configurations; public class CameraConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.ToTable("cameras"); builder.HasKey(c => c.Id); builder.Property(c => c.Name) .HasMaxLength(200) .IsRequired(); builder.Property(c => c.Manufacturer) .HasMaxLength(100); builder.Property(c => c.Model) .HasMaxLength(100); builder.Property(c => c.RtspUrl) .HasMaxLength(1000); builder.Property(c => c.Status) .HasConversion() .HasMaxLength(20) .IsRequired(); builder.Property(c => c.CreatedAt) .HasDefaultValueSql("NOW()"); builder.Property(c => c.UpdatedAt) .HasDefaultValueSql("NOW()"); // Indexes builder.HasIndex(c => c.SiteId); builder.HasIndex(c => c.AgentId); // Relationships builder.HasOne(c => c.Site) .WithMany(s => s.Cameras) .HasForeignKey(c => c.SiteId) .OnDelete(DeleteBehavior.Restrict); builder.HasOne(c => c.Agent) .WithMany(a => a.Cameras) .HasForeignKey(c => c.AgentId) .OnDelete(DeleteBehavior.SetNull); // One-to-one with credentials builder.HasOne(c => c.Credentials) .WithOne(cr => cr.Camera) .HasForeignKey(cr => cr.CameraId) .OnDelete(DeleteBehavior.Cascade); // One-to-one with detection profile builder.HasOne(c => c.DetectionProfile) .WithOne(dp => dp.Camera) .HasForeignKey(dp => dp.CameraId) .OnDelete(DeleteBehavior.Cascade); } }