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

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

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

            builder.HasOne(t => t.Violation)
                    .WithMany(v => v.Tickets)
                    .HasForeignKey(t => t.ViolationId)
                    .OnDelete(DeleteBehavior.Restrict);

            builder.Property(t => t.Amount).HasColumnType("decimal(18,2)");

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