using Core.Entities; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace Data.Configurations { public class EventOccurrenceConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasKey(e => e.Id); // Indexes builder.HasIndex(e => e.StartTime); builder.HasIndex(e => e.EventDefinitionId); builder.HasIndex(e => e.SpecialEventType); // Foreign key relationship (optional) builder.HasOne(e => e.EventDefinition) .WithMany() .HasForeignKey(e => e.EventDefinitionId) .OnDelete(DeleteBehavior.Restrict); // Don't cascade delete if EventDefinition is deleted // Constraints builder.Property(e => e.Name) .IsRequired() .HasMaxLength(200); builder.Property(e => e.Time) .IsRequired() .HasMaxLength(100); builder.Property(e => e.Date) .IsRequired() .HasMaxLength(100); builder.Property(e => e.Location) .HasMaxLength(500); builder.Property(e => e.SpecialEventType) .HasMaxLength(50); // Validation: Either EventDefinitionId OR SpecialEventType must be set (enforced at application level) // EF Core doesn't support mutually exclusive constraints directly, so we'll handle this in validation attributes or service layer } } }