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

namespace Baya.Infrastructure.Persistence.Configuration.IdentityConfig;

internal sealed class CustomerProfileConfig : IEntityTypeConfiguration<CustomerProfile>
{
    public void Configure(EntityTypeBuilder<CustomerProfile> builder)
    {
        builder.ToTable("CustomerProfiles", "usr");

        // Emergency-contact columns are encrypted at rest (converter wired in ApplicationDbContext) —
        // left as nvarchar(max) since ciphertext is longer than the plaintext it carries.

        builder.Property(c => c.AvatarUrl).HasMaxLength(2048);
        builder.Property(c => c.PreferredLanguage).HasMaxLength(10);

        builder.HasIndex(c => c.UserId).IsUnique();
        builder.HasOne(c => c.User)
            .WithOne()
            .HasForeignKey<CustomerProfile>(c => c.UserId)
            .IsRequired();
    }
}
