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

namespace Infrastructure.Persistence.Configurations.Forum.Boards;

public sealed class BoardManagerConfiguration : IEntityTypeConfiguration<BoardManager>
{
    public void Configure(EntityTypeBuilder<BoardManager> builder)
    {
        builder.HasIndex(x => x.BoardID);
        builder.HasIndex(x => x.MemberID);
        builder.HasIndex(x => new { x.BoardID, x.MemberID });

        builder.HasOne(x => x.Board).WithMany(x => x.BoardManager).HasForeignKey(x => x.BoardID).OnDelete(DeleteBehavior.Cascade);
        builder.HasOne(x => x.Member).WithMany().HasForeignKey(x => x.MemberID).OnDelete(DeleteBehavior.Cascade);

        builder.ToTable(nameof(BoardManager), x => x.HasComment("게시판 관리자"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
        builder.Property(x => x.BoardID).IsRequired().HasComment("게시판 ID");
        builder.Property(x => x.MemberID).IsRequired().HasComment("관리자 ID");
        builder.Property(x => x.CanEdit).IsRequired().HasComment("수정 권한");
        builder.Property(x => x.CanDelete).IsRequired().HasComment("삭제 권한");
        builder.Property(x => x.UpdatedAt).HasComment("수정 일시");
        builder.Property(x => x.CreatedAt).IsRequired().HasComment("등록 일시");
    }
}
