using Indotalent.Data.Entities;
using Indotalent.Shared.Consts;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;

namespace Indotalent.Infrastructure.Database.MsSQL.Configuration;

public class SalesQuotationItemConfiguration : IEntityTypeConfiguration<SalesQuotationItem>
{
    public void Configure(EntityTypeBuilder<SalesQuotationItem> builder)
    {
        builder.Property(e => e.SalesQuotationId)
            .HasMaxLength(GlobalConsts.StringLengthId);

        builder.Property(e => e.ProductId)
            .HasMaxLength(GlobalConsts.StringLengthId);

        builder.Property(e => e.Summary)
            .HasMaxLength(GlobalConsts.StringLengthShort);

        builder.HasOne(e => e.SalesQuotation)
            .WithMany(e => e.SalesQuotationItemList)
            .HasForeignKey(e => e.SalesQuotationId)
            .OnDelete(DeleteBehavior.Cascade);

        builder.HasOne(e => e.Product)
            .WithMany()
            .HasForeignKey(e => e.ProductId)
            .OnDelete(DeleteBehavior.NoAction);

        builder.HasIndex(e => e.SalesQuotationId);
        builder.HasIndex(e => e.ProductId);
    }
}