using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using SolutionErp.Domain.Identity;

namespace SolutionErp.Infrastructure.Persistence.Configurations;

public class MenuItemConfiguration : IEntityTypeConfiguration<MenuItem>
{
    public void Configure(EntityTypeBuilder<MenuItem> b)
    {
        b.ToTable("MenuItems");
        b.HasKey(x => x.Key);

        b.Property(x => x.Key).HasMaxLength(50);
        b.Property(x => x.Label).HasMaxLength(200).IsRequired();
        b.Property(x => x.ParentKey).HasMaxLength(50);
        b.Property(x => x.Icon).HasMaxLength(50);
        b.Property(x => x.IsVisible).HasDefaultValue(true);
        b.Property(x => x.DisplayLabel).HasMaxLength(200);

        b.HasOne(x => x.Parent)
            .WithMany(x => x.Children)
            .HasForeignKey(x => x.ParentKey)
            .OnDelete(DeleteBehavior.Restrict);

        b.HasIndex(x => x.ParentKey);
    }
}
