using Baya.Domain.Entities.Catalog;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Baya.Infrastructure.Persistence.Configuration.CatalogConfig;

internal sealed class ServiceCategoryConfig : IEntityTypeConfiguration<ServiceCategory>
{
    public void Configure(EntityTypeBuilder<ServiceCategory> builder)
    {
        builder.ToTable("ServiceCategories", "catalog");

        builder.Property(c => c.NameFa).HasMaxLength(150).IsRequired();
        builder.Property(c => c.NameEn).HasMaxLength(150).IsRequired();
        builder.Property(c => c.DescriptionFa).HasMaxLength(1000);
        builder.Property(c => c.DescriptionEn).HasMaxLength(1000);
        builder.Property(c => c.IconKey).HasMaxLength(100);
        builder.Property(c => c.SortOrder).HasDefaultValue(0);
        builder.Property(c => c.IsActive).HasDefaultValue(true);

        // Public ordered browse: active categories in sort order.
        builder.HasIndex(c => new { c.IsActive, c.SortOrder });

        builder.HasQueryFilter(c => c.DeletedAt == null);

        builder.HasData(CatalogSeed.Categories());
    }
}
