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

namespace Infrastructure.Persistence.Configurations.Members;

public sealed class AttendanceConfiguration : IEntityTypeConfiguration<Attendance>
{
    public void Configure(EntityTypeBuilder<Attendance> builder)
    {
        builder.HasOne(x => x.Member).WithMany().HasForeignKey(x => x.MemberID).OnDelete(DeleteBehavior.NoAction);

        builder.ToTable(nameof(Attendance), x => x.HasComment("출석 기록"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd();
        builder.Property(x => x.MemberID).IsRequired().HasComment("회원 ID");
        builder.Property(x => x.Greeting).HasMaxLength(200).IsRequired().HasComment("출석 인사");
        builder.Property(x => x.ConsecutiveDays).IsRequired().HasComment("연속 출석 일수");
        builder.Property(x => x.ExpRewarded).IsRequired().HasComment("지급 경험치");
        builder.Property(x => x.PointRewarded).IsRequired().HasComment("지급 포인트");
        builder.Property(x => x.CreatedAt).IsRequired().HasComment("출석 일시");

        builder.HasIndex(x => new { x.MemberID, x.CreatedAt }).IsDescending(false, true);
        builder.HasIndex(x => x.CreatedAt).IsDescending(true);
    }
}