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

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

            builder.Property(e => e.Description)
                .HasMaxLength(1024);

            builder.Property(e => e.Note)
                .HasMaxLength(1024);

            builder.Property(e => e.ApprovedBy)
                .HasComment("UserId của người duyệt cho từng chi phí");

            builder.Property(e => e.RejectReason)
                .HasMaxLength(1000)
                .HasComment("Lý do từ chối (nếu có)");

            builder.HasOne(e => e.ExpenseCategory)
                .WithMany()
                .HasForeignKey(e => e.ExpenseCategoryId)
                .OnDelete(DeleteBehavior.Restrict);

            builder.HasOne(e => e.Transaction)
                .WithMany()
                .HasForeignKey(e => e.TransactionId)
                .OnDelete(DeleteBehavior.SetNull);

            builder.HasOne(e => e.Order)
                .WithMany()
                .HasForeignKey(e => e.OrderId)
                .OnDelete(DeleteBehavior.SetNull);

            builder.ToTable("Expense");
        }
    }
}