using Domain.Entities.Page.Faq;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Infrastructure.Persistence.Configurations.Page.Faq;

public sealed class FaqCategoryConfiguration : IEntityTypeConfiguration<FaqCategory>
{
    public void Configure(EntityTypeBuilder<FaqCategory> builder)
    {
        builder.HasMany(x => x.FaqItems).WithOne(x => x.FaqCategory).HasForeignKey(x => x.CategoryID).OnDelete(DeleteBehavior.Cascade);
        builder.HasIndex(x => x.Code).IsUnique();
        builder.HasIndex(x => new { x.Order, x.IsActive });
        builder.HasIndex(x => new { x.Code, x.Order, x.IsActive });

        builder.ToTable(nameof(FaqCategory), t => t.HasComment("FAQ 분류"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
        builder.Property(x => x.Code).HasMaxLength(30).IsRequired().HasComment("주소");
        builder.Property(x => x.Subject).HasMaxLength(255).IsRequired().HasComment("분류 명");
        builder.Property(x => x.Order).IsRequired().HasComment("순서");
        builder.Property(x => x.IsActive).IsRequired().HasComment("사용 여부");
        builder.Property(x => x.UpdatedAt).HasComment("수정 일시");
        builder.Property(x => x.CreatedAt).IsRequired().HasComment("등록 일시");
    }
}