using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//محصول
public class ProductConfiguration : IEntityTypeConfiguration<Product>
{
    public void Configure(EntityTypeBuilder<Product> builder)
    {
        builder.HasQueryFilter(p => !p.IsDeleted);
        builder.Ignore(entity => entity.DomainEvents);
        builder.HasKey(entity => entity.Id);
        builder.Property(entity => entity.Id).UseIdentityColumn();
        builder.Property(entity => entity.Title).IsRequired(true);
        builder.Property(entity => entity.Description).IsRequired(true);
        builder.Property(entity => entity.ShortInfomation).IsRequired(true);
        builder.Property(entity => entity.FullInformation).IsRequired(true);
        builder.Property(entity => entity.Price).IsRequired(true);
        builder.Property(entity => entity.Discount).IsRequired(true);
        builder.Property(entity => entity.Rate).IsRequired(true);
        builder.Property(entity => entity.ImagePath).IsRequired(true);
        builder.Property(entity => entity.ThumbnailPath).IsRequired(true);
        builder.Property(entity => entity.SaleCount).IsRequired(true);
        builder.Property(entity => entity.ViewCount).IsRequired(true);
        builder.Property(entity => entity.RemainingCount).IsRequired(true);
        
        // ============= Club Shop Fields =============
        builder.Property(entity => entity.IsClubExclusive).IsRequired(true);
        builder.Property(entity => entity.ClubDiscountPercent).IsRequired(true);
        
        // Index برای IsClubExclusive
        builder.HasIndex(e => e.IsClubExclusive)
            .HasDatabaseName("IX_Products_IsClubExclusive");

    }
}
