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

namespace Baya.Infrastructure.Persistence.Configuration.VerificationConfig;

internal sealed class VerificationDocumentConfig : IEntityTypeConfiguration<VerificationDocument>
{
    public void Configure(EntityTypeBuilder<VerificationDocument> builder)
    {
        builder.ToTable("VerificationDocuments", "verif");

        // Metadata only — the bytes live in object storage behind a signed URL, never in the DB.
        builder.Property(d => d.ObjectStorageKey).HasMaxLength(400).IsRequired();
        builder.Property(d => d.IntegrityHash).HasMaxLength(64).IsRequired();
        builder.Property(d => d.ContentType).HasMaxLength(100).IsRequired();
        builder.Property(d => d.OriginalFileName).HasMaxLength(260);

        builder.HasOne(d => d.Step)
            .WithMany(s => s.Documents)
            .HasForeignKey(d => d.StepId)
            .IsRequired();

        builder.HasOne<User>()
            .WithMany()
            .HasForeignKey(d => d.UploadedByUserId)
            .IsRequired();

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