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

namespace ERPCore.Infra.Persistence.Configurations;

public sealed class AttendanceUploadBatchConfiguration : IEntityTypeConfiguration<AttendanceUploadBatch>
{
    public void Configure(EntityTypeBuilder<AttendanceUploadBatch> builder)
    {
        builder.ToTable("hr_attendance_upload_batches");
        builder.HasKey(b => b.AttendanceUploadBatchId);

        builder.Property(b => b.DocNo).IsRequired().HasMaxLength(30);
        builder.HasIndex(b => b.DocNo).IsUnique();
        builder.Property(b => b.OriginalFileName).HasMaxLength(260);

        builder.Property(b => b.SourceType).HasConversion<string>().HasMaxLength(20).IsRequired();
        builder.Property(b => b.Status).HasConversion<string>().HasMaxLength(20).IsRequired();

        builder.Property(b => b.UploadedAt).IsRequired();
        builder.Property(b => b.RowVersion).IsRowVersion();

        builder.HasIndex(b => b.Status);
        builder.HasIndex(b => new { b.PeriodStart, b.PeriodEnd });
    }
}
