using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SolutionErp.Domain.Office;

namespace SolutionErp.Infrastructure.Persistence.Configurations;

// EF Mig 36 G-O2 (S36) — Attendee join table N-to-N.
// Composite UNIQUE (BookingId, UserId) — không add user 2 lần cùng booking.
// Inherit BaseEntity (Guid Id auto) + composite UNIQUE constraint via index.
public class MeetingBookingAttendeeConfiguration : IEntityTypeConfiguration<MeetingBookingAttendee>
{
    public void Configure(EntityTypeBuilder<MeetingBookingAttendee> e)
    {
        e.ToTable("MeetingBookingAttendees");

        e.Property(x => x.FullName).HasMaxLength(200).IsRequired();
        e.Property(x => x.Email).HasMaxLength(200);
        e.Property(x => x.Notes).HasMaxLength(200);

        // UNIQUE composite — 1 user / 1 booking
        e.HasIndex(x => new { x.BookingId, x.UserId }).IsUnique();
        // UserId lookup "my invites"
        e.HasIndex(x => x.UserId);
    }
}
