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

namespace OmsorgCore.Infrastructure.Persistence.Configurations;

public class FacilityConfiguration : IEntityTypeConfiguration<Facility>
{
    public void Configure(EntityTypeBuilder<Facility> builder)
    {
        builder.ToTable("facilities");
        builder.HasKey(f => f.Id);
        builder.Property(f => f.Name).IsRequired().HasMaxLength(300);
        builder.Property(f => f.FacilityType).HasMaxLength(100);
        builder.Property(f => f.Website).HasMaxLength(300);
        builder.Property(f => f.Street).HasMaxLength(200);
        builder.Property(f => f.PostalCode).HasMaxLength(10);
        builder.Property(f => f.City).HasMaxLength(100);
        builder.Property(f => f.Country).HasMaxLength(100);
        builder.Property(f => f.BillingStreet).HasMaxLength(200);
        builder.Property(f => f.BillingPostalCode).HasMaxLength(10);
        builder.Property(f => f.BillingCity).HasMaxLength(100);
        builder.Property(f => f.BillingCountry).HasMaxLength(100);
        builder.Property(f => f.CrmStatus).IsRequired().HasMaxLength(50);

        builder.Property(f => f.BillingRate).HasColumnType("decimal(10,2)");
        builder.Property(f => f.NightSurchargePercent).HasColumnType("decimal(5,2)");
        builder.Property(f => f.SaturdaySurchargePercent).HasColumnType("decimal(5,2)");
        builder.Property(f => f.SundaySurchargePercent).HasColumnType("decimal(5,2)");
        builder.Property(f => f.HolidaySurchargePercent).HasColumnType("decimal(5,2)");
        builder.Property(f => f.TravelCostRate).HasColumnType("decimal(10,2)");
        builder.Property(f => f.TravelCostMode).IsRequired().HasMaxLength(20);
        builder.Property(f => f.TravelCostPerKm).HasColumnType("decimal(10,2)");
        builder.Property(f => f.MealAllowanceRate).HasColumnType("decimal(10,2)");
        builder.Property(f => f.MinimumHours).HasColumnType("decimal(5,2)");
        builder.Property(f => f.BillingInterval).HasMaxLength(50);
        builder.Property(f => f.IndividualAgreements).HasMaxLength(2000);

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