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

namespace Baya.Infrastructure.Persistence.Configuration.BookingConfig;

internal sealed class BookingSessionConfig : IEntityTypeConfiguration<BookingSession>
{
    public void Configure(EntityTypeBuilder<BookingSession> builder)
    {
        builder.ToTable("BookingSessions", "booking");

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

        // The nurse's "today" view and the no-show sweep both read (status, scheduled_date).
        builder.HasIndex(s => new { s.BookingId, s.SessionIndex });
        builder.HasIndex(s => new { s.Status, s.ScheduledDate });

        // 1:1 with its EVV record (the FK is on the verification side, on the session).
        builder.HasOne(s => s.Verification)
            .WithOne(v => v.Session)
            .HasForeignKey<VisitVerification>(v => v.BookingSessionId);

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