using Lada.Framework.Data.Domains.Finance.Wallets;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Lada.Framework.Data.Mappings.EntityMappings.Finances.Wallets
{
    public class WalletMap : IEntityMappingConfiguration<Wallet>
    {
        public void Map(EntityTypeBuilder<Wallet> builder)
        {
            builder.HasKey(a => a.Id);

            builder.HasMany(w => w.Transactions)
                    .WithOne(t => t.Wallet)
                    .HasForeignKey(t => t.WalletId)
                    .OnDelete(DeleteBehavior.Restrict);

            builder.HasMany(w => w.RelatedTransactions)
                    .WithOne(t => t.RelatedWallet)
                    .HasForeignKey(t => t.RelatedWalletId)
                    .OnDelete(DeleteBehavior.Restrict);

            // Cấu hình RowVersion cho optimistic concurrency
            builder.Property(w => w.RowVersion)
                    .IsRowVersion();

            builder.ToTable("Wallet");
        }
    }


}
