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

namespace Baya.Infrastructure.Persistence.Configuration.CatalogConfig;

internal sealed class ServiceOptionValueConfig : IEntityTypeConfiguration<ServiceOptionValue>
{
    public void Configure(EntityTypeBuilder<ServiceOptionValue> builder)
    {
        builder.ToTable("ServiceOptionValues", "catalog");

        builder.Property(v => v.NameFa).HasMaxLength(150).IsRequired();
        builder.Property(v => v.NameEn).HasMaxLength(150).IsRequired();
        builder.Property(v => v.SortOrder).HasDefaultValue(0);
        builder.Property(v => v.IsActive).HasDefaultValue(true);

        builder.HasIndex(v => new { v.OptionGroupId, v.SortOrder });

        builder.HasOne(v => v.OptionGroup)
            .WithMany(g => g.Values)
            .HasForeignKey(v => v.OptionGroupId)
            .IsRequired();

        builder.HasQueryFilter(v => v.DeletedAt == null);
    }
}
