using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SportsDivision.Domain.Entities;

namespace SportsDivision.Infrastructure.Data.Configurations;

public class EventConfiguration : IEntityTypeConfiguration<Event>
{
    public void Configure(EntityTypeBuilder<Event> builder)
    {
        builder.HasKey(e => e.EventId);
        builder.Property(e => e.Name).IsRequired().HasMaxLength(100);
        builder.Property(e => e.Category).HasConversion<string>().HasMaxLength(20);
        builder.HasIndex(e => e.Name).IsUnique();
        builder.HasMany(e => e.EventLevels).WithMany(el => el.Events).UsingEntity(j => j.ToTable("EventEventLevel"));
    }
}
