// EN: EF Core configuration for leave_requests table.
// VI: Cau hinh EF Core cho bang leave_requests.

using MerchantService.Domain.AggregatesModel.LeaveRequestAggregate;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace MerchantService.Infrastructure.EntityConfigurations;

public class LeaveRequestEntityTypeConfiguration : IEntityTypeConfiguration<LeaveRequest>
{
    public void Configure(EntityTypeBuilder<LeaveRequest> builder)
    {
        builder.ToTable("leave_requests");
        builder.HasKey(l => l.Id);

        builder.Property(l => l.StaffId).HasColumnName("staff_id").HasField("_staffId").IsRequired();
        builder.Property(l => l.ShopId).HasColumnName("shop_id").HasField("_shopId").IsRequired();
        builder.Property(l => l.LeaveType).HasColumnName("leave_type").HasField("_leaveType").HasMaxLength(20).IsRequired();
        builder.Property(l => l.StartDate).HasColumnName("start_date").HasField("_startDate").IsRequired();
        builder.Property(l => l.EndDate).HasColumnName("end_date").HasField("_endDate").IsRequired();
        builder.Property(l => l.Reason).HasColumnName("reason").HasField("_reason").HasMaxLength(500);
        builder.Property(l => l.Status).HasColumnName("status").HasField("_status").HasMaxLength(20).IsRequired();
        builder.Property(l => l.ApprovedBy).HasColumnName("approved_by").HasField("_approvedBy");
        builder.Property(l => l.ApprovedAt).HasColumnName("approved_at").HasField("_approvedAt");
        builder.Property(l => l.RejectionReason).HasColumnName("rejection_reason").HasField("_rejectionReason").HasMaxLength(500);
        builder.Property(l => l.CreatedAt).HasColumnName("created_at").HasField("_createdAt").IsRequired();

        builder.Ignore(l => l.DomainEvents);
        builder.Ignore(l => l.Days);

        builder.HasIndex(l => l.StaffId).HasDatabaseName("ix_leave_requests_staff_id");
        builder.HasIndex(l => l.ShopId).HasDatabaseName("ix_leave_requests_shop_id");
        builder.HasIndex(l => l.Status).HasDatabaseName("ix_leave_requests_status");
    }
}
