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

namespace UniVerse.Infrastructure.Data.Configurations;

public class LocationConfiguration : IEntityTypeConfiguration<Location>
{
    public void Configure(EntityTypeBuilder<Location> builder)
    {
        builder.ToTable("locations");

        builder.HasKey(l => l.Id);
        builder.Property(l => l.Id).HasColumnName("id");
        builder.Property(l => l.Name).HasColumnName("name").HasMaxLength(255).IsRequired();
        builder.Property(l => l.Building).HasColumnName("building").HasMaxLength(255);
        builder.Property(l => l.Room).HasColumnName("room").HasMaxLength(100);
        builder.Property(l => l.Address).HasColumnName("address").HasMaxLength(500);
        builder.Property(l => l.ExternalId).HasColumnName("external_id").HasMaxLength(255);
        builder.Property(l => l.CreatedAt).HasColumnName("created_at").HasDefaultValueSql("NOW()");

        builder.HasIndex(l => l.ExternalId).IsUnique().HasFilter("external_id IS NOT NULL");
    }
}
