using ErsatzTV.Core.Domain;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace ErsatzTV.Infrastructure.Data.Configurations;

public class SmartCollectionConfiguration : IEntityTypeConfiguration<SmartCollection>
{
    public void Configure(EntityTypeBuilder<SmartCollection> builder)
    {
        builder.ToTable("SmartCollection");

        builder.Property(sc => sc.Name)
            .HasMaxLength(50)
            .HasColumnType("varchar(50)");

        builder.HasIndex(sc => sc.Name)
            .IsUnique();

        // Cleanup + list-hiding of the per-source system smart collections an auto-tune weighted channel
        // owns (#425). Nullable: null = a normal user smart collection.
        builder.HasIndex(sc => sc.OwnedByChannelId);
    }
}
