using Lada.Framework.Data.Domains.Rewards;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Lada.Framework.Data.Mappings.EntityMappings.Rewards
{
    public class UserCashViolationMap : IEntityMappingConfiguration<UserCashViolation>
    {
        public void Map(EntityTypeBuilder<UserCashViolation> builder)
        {
            builder.HasKey(v => v.Id);

            // Unique Index: chống trùng vi phạm cho cùng 1 user + 1 ngày
            builder.HasIndex(v => new { v.UserId, v.BusinessDate })
                    .IsUnique()
                    .HasDatabaseName("IX_UserCashViolation_UserId_BusinessDate");

            builder.HasOne(v => v.User)
                    .WithMany()
                    .HasForeignKey(v => v.UserId)
                    .OnDelete(DeleteBehavior.Restrict);

            builder.HasOne(v => v.ConfigApplied)
                    .WithMany()
                    .HasForeignKey(v => v.ConfigIdApplied)
                    .OnDelete(DeleteBehavior.Restrict);

            builder.Property(v => v.AmountDue).HasColumnType("decimal(18,2)");
            builder.Property(v => v.AmountPaid).HasColumnType("decimal(18,2)");
            builder.Property(v => v.OutstandingAmount).HasColumnType("decimal(18,2)");

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