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

namespace ERPCore.Infra.Persistence.Configurations;

public sealed class WorkShiftConfiguration : IEntityTypeConfiguration<WorkShift>
{
    public void Configure(EntityTypeBuilder<WorkShift> builder)
    {
        builder.ToTable("hr_work_shifts");
        builder.HasKey(w => w.WorkShiftId);

        builder.Property(w => w.Code).IsRequired().HasMaxLength(20);
        builder.HasIndex(w => w.Code).IsUnique();
        builder.Property(w => w.Name).IsRequired().HasMaxLength(200);
        builder.Property(w => w.OtMultiplier).HasPrecision(6, 2);

        builder.Property(w => w.Status)
            .HasConversion<string>().HasMaxLength(20).IsRequired()
            .HasDefaultValue(EntityStatus.Active);

        builder.Property(w => w.CreatedAt).IsRequired();
        builder.Property(w => w.RowVersion).IsRowVersion();

        builder.HasIndex(w => w.Status);
    }
}
