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

namespace Baya.Infrastructure.Persistence.Configuration.BookingConfig;

internal sealed class VisitVerificationConfig : IEntityTypeConfiguration<VisitVerification>
{
    public void Configure(EntityTypeBuilder<VisitVerification> builder)
    {
        builder.ToTable("VisitVerifications", "booking");

        builder.Property(v => v.Status).HasMaxLength(20).IsRequired();

        builder.Property(v => v.CheckInLat).HasPrecision(9, 6);
        builder.Property(v => v.CheckInLng).HasPrecision(9, 6);
        builder.Property(v => v.CheckOutLat).HasPrecision(9, 6);
        builder.Property(v => v.CheckOutLng).HasPrecision(9, 6);
        builder.Property(v => v.CheckInDistanceMeters).HasPrecision(10, 2);

        // The FK/1:1 to the session is configured on BookingSessionConfig; the UNIQUE index on
        // BookingSessionId is created automatically. The admin mismatch queue reads on the advisory flag.
        builder.HasIndex(v => v.CheckInAddressMatch);

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