using CMSMicroservice.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
namespace CMSMicroservice.Infrastructure.Persistence.Configurations;
//آدرس کاربر
public class UserAddressConfiguration : IEntityTypeConfiguration<UserAddress>
{
    public void Configure(EntityTypeBuilder<UserAddress> 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.User)
            .WithMany(entity => entity.UserAddresses)
            .HasForeignKey(entity => entity.UserId)
            .IsRequired(true);
        builder.Property(entity => entity.Title).IsRequired(true);
        builder.Property(entity => entity.Address).IsRequired(true);
        builder.Property(entity => entity.PostalCode).IsRequired(true);
        builder.Property(entity => entity.IsDefault).IsRequired(true);
        builder.Property(entity => entity.CityId).IsRequired(true);

    }
}
