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

namespace Infrastructure.Persistence.Configurations.Page;

public sealed class PopupConfiguration : IEntityTypeConfiguration<Popup>
{
    public void Configure(EntityTypeBuilder<Popup> builder)
    {
        builder.HasIndex(x => x.PositionID);
        builder.HasIndex(x => x.Order);
        builder.HasIndex(x => new { x.Order, x.IsActive });
        builder.HasIndex(x => new { x.StartAt, x.EndAt, x.Order, x.IsActive });

        builder.ToTable(nameof(Popup), t => t.HasComment("팝업"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID) .ValueGeneratedOnAdd() .HasComment("PK");
        builder.Property(x => x.PositionID).IsRequired().HasComment("팝업 위치 ID");
        builder.Property(x => x.Subject).HasMaxLength(255).IsRequired().HasComment("제목");
        builder.Property(x => x.Content).HasMaxLength(4000).HasComment("내용");
        builder.Property(x => x.Link).HasMaxLength(255).HasComment("주소");
        builder.Property(x => x.StartAt).HasComment("사용 기간 - 시작");
        builder.Property(x => x.EndAt).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("등록 일시");
    }
}