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

namespace Infrastructure.Persistence.Configurations.EmailVerification;

public sealed class EmailVerifyNumberConfiguration : IEntityTypeConfiguration<EmailVerifyNumber>
{
    public void Configure(EntityTypeBuilder<EmailVerifyNumber> builder)
    {
        builder.HasIndex(x => x.Type);
        builder.HasIndex(x => x.Email);
        builder.HasIndex(x => x.Code);
        builder.HasIndex(x => x.IsVerified);
        builder.HasIndex(x => x.Expiration);
        builder.HasIndex(x => new { x.Type, x.Code });
        builder.HasIndex(x => new { x.Type, x.Code, x.IsVerified });

        builder.ToTable(nameof(EmailVerifyNumber), x => x.HasComment("이메일 인증 번호들"));
        builder.HasKey(x => x.ID);
        builder.Property(x => x.ID).ValueGeneratedOnAdd().HasComment("PK");
        builder.Property(x => x.Type).HasConversion<int>().IsRequired().HasComment("인증 유형 (이메일 인증 / 비밀번호 재설정)");
        builder.Property(x => x.Email).HasMaxLength(60).IsRequired().HasComment("이메일");
        builder.Property(x => x.Code).HasMaxLength(10).IsRequired().HasComment("Code");
        builder.Property(x => x.IsVerified).IsRequired().HasComment("인증 여부");
        builder.Property(x => x.Expiration).IsRequired().HasComment("만료 일시");
        builder.Property(x => x.CreatedAt).IsRequired().HasComment("등록 일시");
    }
}