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

namespace Infrastructure.Persistence.Configurations.Members.Logs;

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

        builder.ToTable(nameof(MemberEmailChangeLog), x => x.HasComment("사용자 이메일 변경 내역"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
        builder.Property(x => x.MemberID).IsRequired().HasComment("회원 ID");
        builder.Property(x => x.BeforeEmail).HasMaxLength(60).HasComment("이전 이메일");
        builder.Property(x => x.AfterEmail).HasMaxLength(60).IsRequired().HasComment("바뀐 이메일");
        builder.Property(x => x.Referer).HasComment("이전 페이지 주소");
        builder.Property(x => x.IpAddress).HasMaxLength(45).HasComment("IP Address");
        builder.Property(x => x.UserAgent).HasMaxLength(512).HasComment("User Agent");
        builder.Property(x => x.CreatedAt).IsRequired().HasComment("등록 일시");
    }
}