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

namespace Infrastructure.Persistence.Configurations.Forum.Boards;

public sealed class BoardPrefixConfiguration : IEntityTypeConfiguration<BoardPrefix>
{
    public void Configure(EntityTypeBuilder<BoardPrefix> builder)
    {
        builder.HasIndex(x => new { x.BoardID, x.IsActive, x.Order, x.CreatedAt });

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

        builder.ToTable(nameof(BoardPrefix), 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.Name).HasMaxLength(20).IsRequired().HasComment("말머리");
        builder.Property(x => x.Color).HasMaxLength(10).HasComment("색상");
        builder.Property(x => x.Order).IsRequired().HasComment("정렬 순서");
        builder.Property(x => x.Posts).IsRequired().HasComment("사용 게시글 수");
        builder.Property(x => x.IsActive).IsRequired().HasComment("사용 여부");
        builder.Property(x => x.UpdatedAt).HasComment("수정 일시");
        builder.Property(x => x.CreatedAt).IsRequired().HasComment("등록 일시");
    }
}
