using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata.Builders;
using MS.Entities.Models;
using System;
using System.Collections.Generic;
using System.Reflection.Emit;
using System.Text;

namespace MS.DbContexts.Mappings
{
    public class PosTrxLineItemsMap : IEntityTypeConfiguration<PosTrxLineItems>
    {
        public void Configure(EntityTypeBuilder<PosTrxLineItems> builder)
        {
            builder.ToTable("PosTrxLineItems");

            builder.HasIndex(e => e.FuelItemPumpTotalizerVolume)
                .HasName("idx_postrxlineitems_fuelitempumptotalizervolume");

            builder.HasIndex(e => e.FuelItemSoldOnPumpNozzleId)
                .HasName("idx_fuel_item_sold_on_pump_nozzle_id");

            builder.HasIndex(e => e.IsDeleted)
                .HasName("idx_postrxlineitems_isdeleted");

            builder.HasIndex(e => e.PosItemId)
                .HasName("PosTrxLineItems_IX_PosItemId");

            builder.HasIndex(e => e.PosTrxId)
                .HasName("PosTrxLineItems_IX_PosTrxId");

            builder.HasIndex(e => e.TargetBusinessUnitId)
                .HasName("idx_target_bu_id");

            builder.HasIndex(e => e.Voided)
                .HasName("idx_postrxlineitems_voided");

            builder.Property(e => e.Id).HasDefaultValueSql("uuid_generate_v4()");

            builder.Property(e => e.CreatedDateTime).HasDefaultValueSql("'0001-01-01 00:00:00'::timestamp without time zone");

            builder.Property(e => e.FuelItemOriginalGrossAmount).HasColumnType("numeric(12,3)");

            builder.Property(e => e.FuelItemPumpTotalizerMoney).HasColumnType("numeric(12,3)");

            builder.Property(e => e.FuelItemPumpTotalizerVolume).HasColumnType("numeric(12,3)");

            builder.Property(e => e.GrossAmount).HasColumnType("numeric(12,3)");

            builder.Property(e => e.ItemPrice).HasColumnType("numeric(12,3)");

            builder.Property(e => e.ModifiedDateTime).HasDefaultValueSql("'0001-01-01 00:00:00'::timestamp without time zone");

            builder.Property(e => e.NetAmount).HasColumnType("numeric(12,3)");

            builder.Property(e => e.Qty).HasColumnType("numeric(12,3)");

            builder.HasOne(d => d.PosItem)
                .WithMany(p => p.PosTrxLineItems)
                .HasForeignKey(d => d.PosItemId)
                .HasConstraintName("FK_public.PosTrxLineItems_public.PosItems_PosItemId");

            builder.HasOne(d => d.PosTrx)
                .WithMany(p => p.PosTrxLineItems)
                .HasForeignKey(d => d.PosTrxId)
                .HasConstraintName("FK_public.PosTrxLineItems_public.PosTrxes_PosTrxId");
        }
    }
}
