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

namespace OmsorgCore.Infrastructure.Persistence.Configurations;

public class ValueListItemConfiguration : IEntityTypeConfiguration<ValueListItem>
{
    public void Configure(EntityTypeBuilder<ValueListItem> builder)
    {
        builder.ToTable("value_list_items");
        builder.HasKey(i => i.Id);
        builder.Property(i => i.Value).IsRequired().HasMaxLength(100);
        builder.HasIndex(i => new { i.ValueListId, i.Value }).IsUnique();

        builder.HasOne(i => i.ValueList)
            .WithMany(l => l.Items)
            .HasForeignKey(i => i.ValueListId)
            .OnDelete(DeleteBehavior.Restrict);
    }
}
