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

namespace Infrastructure.Persistence.Configurations.Members.Logs;

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

        builder.ToTable(nameof(MemberSummaryChangeLog), 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.BeforeSummary).HasMaxLength(50).HasComment("이전 한마디");
        builder.Property(x => x.AfterSummary).HasMaxLength(50).HasComment("바꾼 한마디");
        builder.Property(x => x.Referer).HasComment("이전 페이지 주소");
        builder.Property(x => x.IpAddress).HasMaxLength(15).HasComment("IP Address");
        builder.Property(x => x.UserAgent).HasMaxLength(512).HasComment("User Agent");
        builder.Property(x => x.CreatedAt).IsRequired().HasComment("등록 일시");
    }
}