using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using OmsorgCore.Domain.Entities;

namespace OmsorgCore.Infrastructure.Persistence.Configurations;

public class FacilityContactConfiguration : IEntityTypeConfiguration<FacilityContact>
{
    public void Configure(EntityTypeBuilder<FacilityContact> builder)
    {
        builder.ToTable("facility_contacts");
        builder.HasKey(c => c.Id);
        builder.Property(c => c.Name).IsRequired().HasMaxLength(200);
        builder.Property(c => c.Role).HasMaxLength(100);
        builder.Property(c => c.Department).HasMaxLength(100);
        builder.Property(c => c.PhoneNumber).HasMaxLength(50);
        builder.Property(c => c.Email).HasMaxLength(200);
        builder.Property(c => c.Notes).HasMaxLength(1000);

        builder.HasOne(c => c.Facility)
            .WithMany()
            .HasForeignKey(c => c.FacilityId)
            .OnDelete(DeleteBehavior.Restrict);

        // Soft-gelöschte Ansprechpartner sind für alle normalen Queries unsichtbar.
        builder.HasQueryFilter(c => !c.IsDeleted);
    }
}
