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

namespace Infrastructure.Persistence.Configurations.Members;

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

        builder.ToTable(nameof(MemberDailyRewardCounter), x => x.HasComment("일일 보상 캡 원장 (d3 M2)"));

        // 복합 PK (MemberID, RewardDate[KST], ActionType)
        builder.HasKey(x => new { x.MemberID, x.RewardDate, x.ActionType });

        builder.Property(x => x.MemberID).HasComment("회원 ID");
        builder.Property(x => x.RewardDate).HasColumnType("date").HasComment("KST 기준 일자");
        builder.Property(x => x.ActionType).HasConversion<byte>().HasComment("액션 유형 (Post=1..PaperReward=8)");
        builder.Property(x => x.Count).IsRequired().HasComment("오늘 지급 횟수");
        builder.Property(x => x.ExpTotal).IsRequired().HasComment("오늘 지급 경험치 합계");
        builder.Property(x => x.PointTotal).IsRequired().HasComment("오늘 지급 토큰 합계");

        // 보존기간 경과 정리 배치용
        builder.HasIndex(x => x.RewardDate);
    }
}
