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

namespace OmsorgCore.Infrastructure.Persistence.Configurations;

public class ValueListItemTransitionConfiguration : IEntityTypeConfiguration<ValueListItemTransition>
{
    public void Configure(EntityTypeBuilder<ValueListItemTransition> builder)
    {
        builder.ToTable("value_list_item_transitions");
        builder.HasKey(t => t.Id);
        builder.HasIndex(t => new { t.FromItemId, t.ToItemId }).IsUnique();
        builder.Property(t => t.RequiresApproval).HasDefaultValue(true);

        builder.HasOne(t => t.FromItem)
            .WithMany()
            .HasForeignKey(t => t.FromItemId)
            .OnDelete(DeleteBehavior.Restrict);

        builder.HasOne(t => t.ToItem)
            .WithMany()
            .HasForeignKey(t => t.ToItemId)
            .OnDelete(DeleteBehavior.Restrict);
    }
}
