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

namespace CartWise.Infrastructure.Data.Configurations;

public class GroceryConceptConfiguration : IEntityTypeConfiguration<GroceryConcept>
{
    public void Configure(EntityTypeBuilder<GroceryConcept> builder)
    {
        builder.HasKey(c => c.GroceryConceptId);

        builder.Property(c => c.Name)
            .HasMaxLength(160)
            .IsRequired();

        builder.Property(c => c.NormalizedName)
            .HasMaxLength(160)
            .IsRequired();

        builder.HasIndex(c => c.NormalizedName)
            .IsUnique();

        builder.HasOne<ProductCategory>()
            .WithMany()
            .HasForeignKey(c => c.CategoryId)
            .OnDelete(DeleteBehavior.SetNull);
    }
}
