using DntSite.Web.Features.PrivateMessages.Entities;

namespace DntSite.Web.Features.PrivateMessages.EfConfig;

public class PrivateMessageBookmarkConfig : IEntityTypeConfiguration<PrivateMessageBookmark>
{
    public void Configure(EntityTypeBuilder<PrivateMessageBookmark> builder)
    {
        ArgumentNullException.ThrowIfNull(builder);

        builder.HasOne(bookmark => bookmark.Parent)
            .WithMany(entity => entity.Bookmarks)
            .HasForeignKey(bookmark => bookmark.ParentId)
            .IsRequired();

        builder.HasOne(entity => entity.User)
            .WithMany(user => user.PrivateMessageBookmarks)
            .HasForeignKey(entity => entity.UserId)
            .IsRequired(false);
    }
}
