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

namespace Infrastructure.Persistence.Configurations.Forum.Logs;

public sealed class CommentFileDownLogConfiguration : IEntityTypeConfiguration<CommentFileDownLog>
{
    public void Configure(EntityTypeBuilder<CommentFileDownLog> builder)
    {
        builder.HasIndex(x => x.CommentID);
        builder.HasIndex(x => x.CommentFileID);
        builder.HasIndex(x => x.MemberID);
        builder.HasIndex(x => new { x.CommentID, x.CommentFileID });
        builder.HasIndex(x => new { x.CommentID, x.CommentFileID, x.MemberID });

        builder.HasOne(x => x.Comment).WithMany(x => x.CommentFileDownLog).HasForeignKey(x => x.CommentID).OnDelete(DeleteBehavior.Cascade);
        builder.HasOne(x => x.CommentFile).WithMany().HasForeignKey(x => x.CommentFileID).OnDelete(DeleteBehavior.Restrict);
        builder.HasOne(x => x.Member).WithMany().HasForeignKey(x => x.MemberID).OnDelete(DeleteBehavior.Restrict);

        builder.ToTable("CommentFileDownLog", x => x.HasComment("댓글 파일 다운로드 로그"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
        builder.Property(x => x.CommentID).IsRequired().HasComment("댓글 ID");
        builder.Property(x => x.CommentFileID).IsRequired().HasComment("댓글 파일 ID");
        builder.Property(x => x.MemberID).HasComment("회원 ID");
        builder.Property(x => x.IpAddress).HasMaxLength(50).HasComment("IP Address");
        builder.Property(x => x.UserAgent).HasMaxLength(255).HasComment("User-Agent");
        builder.Property(x => x.CreatedAt).IsRequired().HasComment("등록 일시");
    }
}
