using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//آدرس کاربر
public class UserWalletHistoryConfiguration : IEntityTypeConfiguration<UserWalletHistory>
{
    public void Configure(EntityTypeBuilder<UserWalletHistory> builder)
    {
        builder.HasQueryFilter(p => !p.IsDeleted);
        builder.Ignore(entity => entity.DomainEvents);
        builder.HasKey(entity => entity.Id);
        builder.Property(entity => entity.Id).UseIdentityColumn();
        builder
            .HasOne(entity => entity.Wallet)
            .WithMany(entity => entity.UserWalletHistories)
            .HasForeignKey(entity => entity.WalletId)
            .IsRequired(true);
        builder.Property(entity => entity.CurrentBalance).IsRequired(true);
        builder.Property(entity => entity.ChangeValue).IsRequired(true);
        builder.Property(entity => entity.CurrentNetworkBalance).IsRequired(true);
        builder.Property(entity => entity.ChangeNerworkValue).IsRequired(true);
        builder.Property(entity => entity.IsIncrease).IsRequired(true);
        builder.Property(entity => entity.RefrenceId).IsRequired(false);
        builder.Property(entity => entity.PackageId).IsRequired(false);
        
        // رابطه با Package (nullable)
        builder.HasOne(entity => entity.Package)
            .WithMany()
            .HasForeignKey(entity => entity.PackageId)
            .IsRequired(false)
            .OnDelete(DeleteBehavior.Restrict);

    }
}
