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

namespace OmsorgCore.Infrastructure.Persistence.Configurations;

public class ContractConfiguration : IEntityTypeConfiguration<Contract>
{
    public void Configure(EntityTypeBuilder<Contract> builder)
    {
        builder.ToTable("contracts");
        builder.HasKey(c => c.Id);
        builder.Property(c => c.ContractType).IsRequired().HasMaxLength(100);
        builder.Property(c => c.Status).IsRequired().HasMaxLength(50);
        builder.Property(c => c.AllowancesDescription).HasMaxLength(500);
        builder.Property(c => c.OvertimeRules).HasMaxLength(500);
        builder.Property(c => c.WeeklyHours).HasPrecision(10, 2);
        builder.Property(c => c.HourlyWage).HasPrecision(10, 2);

        builder.HasOne(c => c.Employee)
            .WithMany()
            .HasForeignKey(c => c.EmployeeId)
            .OnDelete(DeleteBehavior.Restrict);

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

        builder.HasQueryFilter(c => !c.IsDeleted);
    }
}
