using Lada.Framework.Data.Domains.Hr;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Lada.Framework.Data.Mappings.EntityMappings.Hr
{
    public class AttendanceMap : IEntityMappingConfiguration<Attendance>
    {
        public void Map(EntityTypeBuilder<Attendance> builder)
        {
            builder.HasKey(a => a.Id);

            // UserId là khóa ngoại
            builder.HasOne(a => a.User)
                .WithMany(u=>u.Attendances) // Nếu bạn muốn: .WithMany(u => u.Attendances)
                .HasForeignKey(a => a.UserId)
                .OnDelete(DeleteBehavior.Restrict);

            builder.Property(a => a.CheckInTime).IsRequired();

            builder.Property(a => a.CheckOutTime).IsRequired(false);

            // Navigation đến AttendanceMedia
            builder.HasMany(a => a.AttendanceMedias)
                .WithOne(am => am.Attendance)
                .HasForeignKey(am => am.AttendanceId)
                .OnDelete(DeleteBehavior.Restrict);

            builder.ToTable("Attendance");
        }
    }
}
