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

namespace Baya.Infrastructure.Persistence.Configuration.ReviewsConfig;

/// <summary>
/// <c>review_tags_master</c> — the standardized tag vocabulary (seeded via <c>HasData</c>). <c>code</c> is
/// UNIQUE; ordering/toggling is data (<c>sort_order</c>/<c>is_active</c>).
/// </summary>
internal sealed class ReviewTagMasterConfig : IEntityTypeConfiguration<ReviewTagMaster>
{
    public void Configure(EntityTypeBuilder<ReviewTagMaster> builder)
    {
        builder.ToTable("ReviewTagsMaster", "reviews");

        builder.Property(t => t.Code).HasMaxLength(50).IsRequired();
        builder.Property(t => t.LabelFa).HasMaxLength(100).IsRequired();
        builder.Property(t => t.LabelEn).HasMaxLength(100).IsRequired();
        builder.Property(t => t.IsActive).HasDefaultValue(true);
        builder.Property(t => t.SortOrder).HasDefaultValue(0);

        builder.HasIndex(t => t.Code).IsUnique();
        builder.HasIndex(t => new { t.IsActive, t.SortOrder });

        builder.HasData(ReviewsSeed.Tags());
    }
}
