using CMSMicroservice.Domain.Entities.DiscountShop;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace CMSMicroservice.Infrastructure.Persistence.Configurations.DiscountShop;

/// <summary>
/// تنظیمات EF Core برای محصول فروشگاه تخفیفی
/// </summary>
public class DiscountProductConfiguration : IEntityTypeConfiguration<DiscountProduct>
{
    public void Configure(EntityTypeBuilder<DiscountProduct> 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()
            .HasMaxLength(200);
        
        builder.Property(entity => entity.ShortInfomation)
            .IsRequired()
            .HasMaxLength(500);
        
        builder.Property(entity => entity.FullInformation)
            .IsRequired();
        
        builder.Property(entity => entity.Price)
            .IsRequired();
        
        builder.Property(entity => entity.MaxDiscountPercent)
            .IsRequired();
        
        builder.Property(entity => entity.ImagePath)
            .IsRequired();
        
        builder.Property(entity => entity.ThumbnailPath)
            .IsRequired();
        
        builder.Property(entity => entity.IsActive)
            .IsRequired()
            .HasDefaultValue(true);
    }
}
