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

namespace Infrastructure.Persistence.Configurations.Page;

public sealed class DocumentConfiguration : IEntityTypeConfiguration<Document>
{
    public void Configure(EntityTypeBuilder<Document> builder)
    {
        builder.HasIndex(x => x.Code).IsUnique();
        builder.HasIndex(x => x.Subject);
        builder.HasIndex(x => x.IsActive);
        builder.HasIndex(x => new { x.Code, x.IsActive });

        builder.ToTable(nameof(Document), t => t.HasComment("문서"));
        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(120).IsRequired().HasComment("제목");
        builder.Property(x => x.Content).HasMaxLength(5000).HasComment("내용");
        builder.Property(x => x.IsActive).IsRequired().HasComment("사용 여부");
        builder.Property(x => x.Views).IsRequired().HasComment("조회 수");
        builder.Property(x => x.UpdatedAt).HasComment("수정 일시");
        builder.Property(x => x.CreatedAt).IsRequired().HasComment("등록 일시");
    }
}