using ERPCore.Domain.Entities;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace ERPCore.Infra.Persistence.Configurations;

public sealed class BundleSaleLineConfiguration : IEntityTypeConfiguration<BundleSaleLine>
{
    public void Configure(EntityTypeBuilder<BundleSaleLine> builder)
    {
        builder.ToTable("bundle_sale_lines");
        builder.HasKey(x => x.BundleSaleLineId);
        builder.Property(x => x.Description).IsRequired().HasMaxLength(200);
        builder.Property(x => x.Qty).HasPrecision(18, 4);
        builder.Property(x => x.UnitPrice).HasPrecision(18, 4);
        builder.Property(x => x.LineTotal).HasPrecision(18, 4);
        builder.Property(x => x.IncludeInBundle).HasDefaultValue(true);
        builder.Property(x => x.IsComponent).HasDefaultValue(true);

        builder.HasOne(x => x.Item).WithMany().HasForeignKey(x => x.ItemId).OnDelete(DeleteBehavior.Restrict);
        builder.HasOne(x => x.Warehouse).WithMany().HasForeignKey(x => x.WarehouseId).OnDelete(DeleteBehavior.Restrict);
    }
}
