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

namespace Infrastructure.Persistence.Configurations.Members;

public sealed class MemberGradeConfiguration : IEntityTypeConfiguration<MemberGrade>
{
    public void Configure(EntityTypeBuilder<MemberGrade> builder)
    {
        builder.HasIndex(x => x.KorName).IsUnique();
        builder.HasIndex(x => x.EngName).IsUnique();
        builder.HasIndex(x => x.Order);
        builder.HasIndex(x => x.IsActive);
        builder.HasIndex(x => new { x.Order, x.IsActive });

        builder.ToTable(nameof(MemberGrade), x => x.HasComment("회원 등급"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
        builder.Property(x => x.KorName).HasMaxLength(240).IsRequired().HasComment("한글 명");
        builder.Property(x => x.EngName).HasMaxLength(120).IsRequired().HasComment("영문 명");
        builder.Property(x => x.Description).HasMaxLength(1000).HasComment("설명");
        builder.Property(x => x.Order).IsRequired().HasComment("순서");
        builder.Property(x => x.Image).HasMaxLength(1000).HasComment("이미지");
        builder.Property(x => x.TextColor).HasMaxLength(7).HasComment("표시 색상");
        builder.Property(x => x.RequiredExp).IsRequired().HasComment("누적 경험치");
        builder.Property(x => x.RequiredAttendance).IsRequired().HasComment("누적 출석 수");
        builder.Property(x => x.IsActive).IsRequired().HasComment("사용 여부");
        builder.Property(x => x.UpdatedAt).HasComment("수정 일시");
        builder.Property(x => x.CreatedAt).IsRequired().HasComment("등록 일시");
    }
}
