using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//توکن Otp
public class OtpTokenConfiguration : IEntityTypeConfiguration<OtpToken>
{
    public void Configure(EntityTypeBuilder<OtpToken> builder)
    {
        builder.HasQueryFilter(p => !p.IsDeleted);
        builder.Ignore(entity => entity.DomainEvents);
        builder.HasKey(entity => entity.Id);
        builder.Property(entity => entity.Id).UseIdentityColumn();
        builder.Property(entity => entity.Mobile).IsRequired(true);
        builder.Property(entity => entity.Purpose).IsRequired(true);
        
        // Code is not persisted to database, only used in-memory before hashing
        builder.Ignore(entity => entity.Code);
        
        builder.Property(entity => entity.CodeHash).IsRequired(true);
        builder.Property(entity => entity.ExpiresAt).IsRequired(true);
        builder.Property(entity => entity.Attempts).IsRequired(true);
        builder.Property(entity => entity.IsUsed).IsRequired(true);

    }
}
