using App.Core.Entities.Maintenance; using Microsoft.EntityFrameworkCore; using Microsoft.EntityFrameworkCore.Metadata.Builders; namespace App.Infrastructure.Data.Configurations; public class WorkOrderConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.Property(w => w.GeneratedForOccurrenceKey).HasMaxLength(50); // Anti-doublon de génération du MaintenanceSchedulingEngine : un seul OT par occurrence // d'une gamme donnée, quel que soit son statut. Filtré (pas d'index sur les OT curatifs, // qui ont MaintenancePlanId = null). builder.HasIndex(w => new { w.MaintenancePlanId, w.GeneratedForOccurrenceKey }) .IsUnique() .HasFilter("MaintenancePlanId IS NOT NULL"); builder.HasIndex(w => new { w.Status, w.ScheduledDate }); // vue calendrier / dashboard builder.HasOne() .WithMany() .HasForeignKey(w => w.AssignedTechnicianUserId) .OnDelete(DeleteBehavior.Restrict); builder.HasMany(w => w.TaskResults) .WithOne(r => r.WorkOrder) .HasForeignKey(r => r.WorkOrderId) .OnDelete(DeleteBehavior.Cascade); builder.HasMany(w => w.PartsUsed) .WithOne() .HasForeignKey(p => p.WorkOrderId) .OnDelete(DeleteBehavior.Cascade); } } public class WorkOrderTaskResultConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasOne() .WithMany() .HasForeignKey(r => r.MaintenanceTaskId) .OnDelete(DeleteBehavior.Restrict); } } public class WorkOrderPartUsedConfiguration : IEntityTypeConfiguration { public void Configure(EntityTypeBuilder builder) { builder.HasOne() .WithMany() .HasForeignKey(p => p.PartId) .OnDelete(DeleteBehavior.Restrict); } }