using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//سفارش کاربر
public class UserOrderConfiguration : IEntityTypeConfiguration<UserOrder>
{
    public void Configure(EntityTypeBuilder<UserOrder> 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.Amount).IsRequired(true);
        builder
            .HasOne(entity => entity.Package)
            .WithMany(entity => entity.UserOrders)
            .HasForeignKey(entity => entity.PackageId)
            .IsRequired(false);
        builder
            .HasOne(entity => entity.Transaction)
            .WithMany(entity => entity.UserOrders)
            .HasForeignKey(entity => entity.TransactionId)
            .IsRequired(false);
        builder.Property(entity => entity.PaymentStatus).IsRequired(true);
        builder.Property(entity => entity.PaymentDate).IsRequired(false);
        builder
            .HasOne(entity => entity.User)
            .WithMany(entity => entity.UserOrders)
            .HasForeignKey(entity => entity.UserId)
            .IsRequired(true);
        builder
            .HasOne(entity => entity.UserAddress)
            .WithMany(entity => entity.UserOrders)
            .HasForeignKey(entity => entity.UserAddressId).OnDelete(DeleteBehavior.NoAction)
            .IsRequired(true);
        builder.Property(entity => entity.PaymentMethod).IsRequired(false);

    }
}
