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

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

namespace MerchantService.Infrastructure.EntityConfigurations;

public class AttendanceRecordEntityTypeConfiguration : IEntityTypeConfiguration<AttendanceRecord>
{
    public void Configure(EntityTypeBuilder<AttendanceRecord> builder)
    {
        builder.ToTable("attendance_records");
        builder.HasKey(a => a.Id);

        builder.Property(a => a.StaffId).HasColumnName("staff_id").HasField("_staffId").IsRequired();
        builder.Property(a => a.ShopId).HasColumnName("shop_id").HasField("_shopId").IsRequired();
        builder.Property(a => a.Date).HasColumnName("date").HasField("_date").IsRequired();
        builder.Property(a => a.CheckIn).HasColumnName("check_in").HasField("_checkIn");
        builder.Property(a => a.CheckOut).HasColumnName("check_out").HasField("_checkOut");
        builder.Property(a => a.HoursWorked).HasColumnName("hours_worked").HasField("_hoursWorked").HasPrecision(5, 2);
        builder.Property(a => a.Status).HasColumnName("status").HasField("_status").HasMaxLength(20).IsRequired();
        builder.Property(a => a.Notes).HasColumnName("notes").HasField("_notes").HasMaxLength(500);
        builder.Property(a => a.CreatedAt).HasColumnName("created_at").HasField("_createdAt").IsRequired();
        builder.Property<DateTime?>("_updatedAt").HasColumnName("updated_at");

        builder.Ignore(a => a.DomainEvents);

        builder.HasIndex(a => new { a.StaffId, a.Date }).IsUnique().HasDatabaseName("ix_attendance_staff_date");
        builder.HasIndex(a => new { a.ShopId, a.Date }).HasDatabaseName("ix_attendance_shop_date");
    }
}
