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

namespace OmsorgCore.Infrastructure.Persistence.Configurations;

public class FacilityQualificationRateConfiguration : IEntityTypeConfiguration<FacilityQualificationRate>
{
    public void Configure(EntityTypeBuilder<FacilityQualificationRate> builder)
    {
        builder.ToTable("facility_qualification_rates");
        builder.HasKey(r => r.Id);
        builder.Property(r => r.Qualification).IsRequired().HasMaxLength(200);
        builder.Property(r => r.Rate).IsRequired().HasColumnType("decimal(10,2)");

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

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