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

namespace ERPCore.Infra.Persistence.Configurations;

public sealed class PayslipConfiguration : IEntityTypeConfiguration<Payslip>
{
    public void Configure(EntityTypeBuilder<Payslip> builder)
    {
        builder.ToTable("hr_payslips");
        builder.HasKey(p => p.PayslipId);

        builder.HasOne(p => p.PayrollLine).WithOne()
            .HasForeignKey<Payslip>(p => p.PayrollLineId).OnDelete(DeleteBehavior.Cascade);
        builder.HasIndex(p => p.PayrollLineId).IsUnique();

        builder.Property(p => p.GeneratedAt).IsRequired();
    }
}
