using Baya.Domain.Entities.User;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Baya.Infrastructure.Persistence.Configuration.UserConfig;

internal class UserConfig:IEntityTypeConfiguration<User>
{
    public void Configure(EntityTypeBuilder<User> builder)
    {
        builder.ToTable("Users","usr").Property(p => p.Id).HasColumnName("UserId");

        builder.Property(u => u.Gender).HasMaxLength(10);
        builder.Property(u => u.PhoneHash).HasMaxLength(64);
        builder.Property(u => u.IsActive).HasDefaultValue(false);

        // One identity per phone. The unique index lives on the deterministic hash because the
        // encrypted phone column itself is non-deterministic ciphertext. Filtered: users without a
        // phone (internally provisioned admins) don't collide on NULL.
        builder.HasIndex(u => u.PhoneHash).IsUnique().HasFilter("[PhoneHash] IS NOT NULL");

        builder.HasQueryFilter(u => u.DeletedAt == null);
    }
}