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

namespace Infrastructure.Persistence.Configurations.Forum.Comments;

public sealed class CommentLinkConfiguration : IEntityTypeConfiguration<CommentLink>
{
    public void Configure(EntityTypeBuilder<CommentLink> builder)
    {
        builder.HasIndex(x => x.BoardID);
        builder.HasIndex(x => x.PostID);
        builder.HasIndex(x => x.CommentID);

        builder.HasOne(x => x.Board).WithMany().HasForeignKey(x => x.BoardID).OnDelete(DeleteBehavior.Restrict);
        builder.HasOne(x => x.Post).WithMany().HasForeignKey(x => x.PostID).OnDelete(DeleteBehavior.Restrict);
        builder.HasOne(x => x.Comment).WithMany(x => x.CommentLink).HasForeignKey(x => x.CommentID).OnDelete(DeleteBehavior.Cascade);

        builder.ToTable("CommentLink", x => x.HasComment("댓글 링크"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
    }
}
