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

namespace Baya.Infrastructure.Persistence.Configuration.GeographyConfig;

internal sealed class ProvinceConfig : IEntityTypeConfiguration<Province>
{
    public void Configure(EntityTypeBuilder<Province> builder)
    {
        builder.ToTable("Provinces", "geo");

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

        builder.HasIndex(p => p.SortOrder);

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

        builder.HasData(GeographySeed.Provinces());
    }
}
