using System;
using Microsoft.EntityFrameworkCore;
using Microsoft.EntityFrameworkCore.Metadata;

// Code scaffolded by EF Core assumes nullable reference types (NRTs) are not used or disabled.
// If you have enabled NRTs for your project, then un-comment the following line:
// #nullable disable

namespace MS.WebApi.Models
{
    public partial class TransactionServiceDatabase_NewThu04130311PMContext : DbContext
    {
        public TransactionServiceDatabase_NewThu04130311PMContext()
        {
        }

        public TransactionServiceDatabase_NewThu04130311PMContext(DbContextOptions<TransactionServiceDatabase_NewThu04130311PMContext> options)
            : base(options)
        {
        }

        public virtual DbSet<Currencies> Currencies { get; set; }
        public virtual DbSet<Mops> Mops { get; set; }
        public virtual DbSet<NozzleAssignments> NozzleAssignments { get; set; }
        public virtual DbSet<PosItemAndGroupM2m> PosItemAndGroupM2m { get; set; }
        public virtual DbSet<PosItemGroupSystems> PosItemGroupSystems { get; set; }
        public virtual DbSet<PosItemGroups> PosItemGroups { get; set; }
        public virtual DbSet<PosItems> PosItems { get; set; }
        public virtual DbSet<PosMops> PosMops { get; set; }
        public virtual DbSet<PosPopularItems> PosPopularItems { get; set; }
        public virtual DbSet<PosTrxLineItems> PosTrxLineItems { get; set; }
        public virtual DbSet<PosTrxMops> PosTrxMops { get; set; }
        public virtual DbSet<PosTrxPromotions> PosTrxPromotions { get; set; }
        public virtual DbSet<PosTrxes> PosTrxes { get; set; }
        public virtual DbSet<ShortCodes> ShortCodes { get; set; }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
#warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
                optionsBuilder.UseNpgsql("Server=ipos.biz;port=5432;database=TransactionServiceDatabase_NewThu04130311PM;User Id=postgres;Password=Postgres3141");
            }
        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.HasPostgresExtension("dblink")
                .HasPostgresExtension("uuid-ossp");

            modelBuilder.Entity<Currencies>(entity =>
            {
                entity.HasIndex(e => e.Name)
                    .HasName("Currencies_IX_CurrencyName")
                    .IsUnique();

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

            modelBuilder.Entity<Mops>(entity =>
            {
                entity.HasIndex(e => e.PaymentId)
                    .HasName("Mops_IX_PaymentId")
                    .IsUnique();

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

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

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

                entity.Property(e => e.Name)
                    .IsRequired()
                    .HasMaxLength(60);
            });

            modelBuilder.Entity<NozzleAssignments>(entity =>
            {
                entity.HasIndex(e => new { e.NozzleId, e.TargetBusinessUnitId })
                    .IsUnique();

                entity.Property(e => e.Id).ValueGeneratedNever();
            });

            modelBuilder.Entity<PosItemAndGroupM2m>(entity =>
            {
                entity.HasKey(e => new { e.PosItemId, e.PosItemGroupId })
                    .HasName("PK_public.PosItemAndGroup_M2M");

                entity.ToTable("PosItemAndGroup_M2M");

                entity.HasIndex(e => e.PosItemGroupId)
                    .HasName("PosItemAndGroup_M2M_IX_PosItemGroup_Id");

                entity.HasIndex(e => e.PosItemId)
                    .HasName("PosItemAndGroup_M2M_IX_PosItem_Id");

                entity.Property(e => e.PosItemId).HasColumnName("PosItem_Id");

                entity.Property(e => e.PosItemGroupId).HasColumnName("PosItemGroup_Id");

                //entity.HasOne(d => d.PosItemGroup)
                //    .WithMany(p => p.PosItemAndGroupM2m)
                //    .HasForeignKey(d => d.PosItemGroupId)
                //    .HasConstraintName("FK_public.PosItemAndGroup_M2M_public.PosItemGroups_PosItemGroup");

                //entity.HasOne(d => d.PosItem)
                //    .WithMany(p => p.PosItemAndGroupM2m)
                //    .HasForeignKey(d => d.PosItemId)
                //    .HasConstraintName("FK_public.PosItemAndGroup_M2M_public.PosItems_PosItem_Id");
            });

            modelBuilder.Entity<PosItemGroupSystems>(entity =>
            {
                entity.HasIndex(e => e.Name)
                    .HasName("PosItemGroupSystems_IX_Name")
                    .IsUnique();

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

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

                entity.Property(e => e.Name)
                    .IsRequired()
                    .HasMaxLength(80);

                entity.Property(e => e.TargetBusinessUnitId).HasDefaultValueSql("'00000000-0000-0000-0000-000000000000'::uuid");
            });

            modelBuilder.Entity<PosItemGroups>(entity =>
            {
                entity.HasIndex(e => e.ParentGroupId)
                    .HasName("PosItemGroups_IX_ParentGroupId");

                entity.HasIndex(e => e.SystemId);

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

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

                entity.Property(e => e.Name)
                    .IsRequired()
                    .HasMaxLength(60);

                entity.HasOne(d => d.ParentGroup)
                    .WithMany(p => p.InverseParentGroup)
                    .HasForeignKey(d => d.ParentGroupId)
                    .HasConstraintName("FK_public.PosItemGroups_public.PosItemGroups_ParentGroupId");

                entity.HasOne(d => d.System)
                    .WithMany(p => p.PosItemGroups)
                    .HasForeignKey(d => d.SystemId)
                    .HasConstraintName("FK_public.PosItemGroups_public.PosItemGroupSystems_SystemId");
            });

            modelBuilder.Entity<PosItems>(entity =>
            {
                entity.HasIndex(e => e.BarCode)
                    .HasName("PosItems_IX_BarCode");

                entity.HasIndex(e => e.CreatedDateTime)
                    .HasName("PosItems_IX_CreatedDateTime");

                entity.HasIndex(e => e.ItemId)
                    .HasName("PosItems_IX_ItemId");

                entity.HasIndex(e => e.TargetBusinessUnitId);

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

                entity.Property(e => e.BarCode)
                    .IsRequired()
                    .HasMaxLength(50);

                entity.Property(e => e.ItemId)
                    .IsRequired()
                    .HasMaxLength(20);

                entity.Property(e => e.ItemName)
                    .IsRequired()
                    .HasMaxLength(100);

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

                entity.Property(e => e.Price).HasColumnType("numeric(12,3)");

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

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

            modelBuilder.Entity<PosMops>(entity =>
            {
                entity.HasIndex(e => new { e.PaymentId, e.TargetBusinessUnitId })
                    .HasName("PosMops_IX_PaymentIdAndTargetBusinessUnitId")
                    .IsUnique();

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

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

            modelBuilder.Entity<PosPopularItems>(entity =>
            {
                entity.HasIndex(e => new { e.PosItemId, e.TargetBusinessUnitId })
                    .HasName("PosPopularItems_IX_PosItemIdBizUnitId")
                    .IsUnique();

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

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

                entity.HasOne(d => d.PosItem)
                    .WithMany(p => p.PosPopularItems)
                    .HasForeignKey(d => d.PosItemId)
                    .HasConstraintName("FK_public.PosPopularItems_public.PosItems_PosItemId");
            });

            modelBuilder.Entity<PosTrxLineItems>(entity =>
            {
                entity.HasIndex(e => e.FuelItemPumpTotalizerVolume)
                    .HasName("idx_postrxlineitems_fuelitempumptotalizervolume");

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

            modelBuilder.Entity<PosTrxMops>(entity =>
            {
                entity.HasIndex(e => e.PosMopId)
                    .HasName("PosTrxMops_IX_PosMopId");

                entity.HasIndex(e => e.PosTrxId)
                    .HasName("PosTrxMops_IX_PosTrxId");

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

                entity.Property(e => e.BillNumber).HasMaxLength(28);

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

                entity.Property(e => e.IccardNumber).HasColumnName("ICCardNumber");

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

                entity.Property(e => e.Paid).HasColumnType("numeric(12,3)");

                entity.Property(e => e.PayBack).HasColumnType("numeric(12,3)");

                entity.HasOne(d => d.PosMop)
                    .WithMany(p => p.PosTrxMops)
                    .HasForeignKey(d => d.PosMopId)
                    .HasConstraintName("FK_public.PosTrxMops_public.PosMops_PosMopId");

                entity.HasOne(d => d.PosTrx)
                    .WithMany(p => p.PosTrxMops)
                    .HasForeignKey(d => d.PosTrxId)
                    .HasConstraintName("FK_public.PosTrxMops_public.PosTrxes_PosTrxId");
            });

            modelBuilder.Entity<PosTrxPromotions>(entity =>
            {
                //entity.HasIndex(e => e.CreatedDateTime)
                //    .HasNullSortOrder(new[] { NullSortOrder.NullsLast })
                //    .HasSortOrder(new[] { SortOrder.Descending });

                entity.HasIndex(e => e.OwnerPosTrxId)
                    .HasName("PosTrxPromotions_IX_OwnerPosTrxId");

                entity.HasIndex(e => e.OwnerPosTrxLineItemId)
                    .HasName("PosTrxPromotions_IX_OwnerPosTrxLineItemId");

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

                entity.Property(e => e.AdditionalValue).HasColumnType("numeric(12,3)");

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

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

                entity.Property(e => e.Value).HasColumnType("numeric(12,3)");

                entity.HasOne(d => d.OwnerPosTrx)
                    .WithMany(p => p.PosTrxPromotions)
                    .HasForeignKey(d => d.OwnerPosTrxId)
                    .HasConstraintName("FK_public.PosTrxPromotions_public.PosTrxes_OwnerPosTrxId");

                entity.HasOne(d => d.OwnerPosTrxLineItem)
                    .WithMany(p => p.PosTrxPromotions)
                    .HasForeignKey(d => d.OwnerPosTrxLineItemId)
                    .HasConstraintName("FK_public.PosTrxPromotions_public.PosTrxLineItems_OwnerPosTrxLi");
            });

            modelBuilder.Entity<PosTrxes>(entity =>
            {
                entity.HasIndex(e => e.CreatedDateTime)
                    .HasName("idx_created_datetime");

                entity.HasIndex(e => e.CurrencyId)
                    .HasName("PosTrxes_IX_CurrencyId");

                entity.HasIndex(e => e.EinvoiceId)
                    .HasFilter("(\"EInvoiceId\" IS NOT NULL)");

                entity.HasIndex(e => e.ShiftId)
                    .HasName("PosTrxes_IX_ShiftId");

                entity.HasIndex(e => e.TargetBusinessUnitId);

                entity.HasIndex(e => e.TransactionStatus)
                    .HasName("idx_transaction_status");

                entity.HasIndex(e => e.TransactionType);

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

                entity.Property(e => e.EinvoiceId).HasColumnName("EInvoiceId");

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

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

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

                entity.Property(e => e.ReceiptId).HasMaxLength(20);

                entity.HasOne(d => d.Currency)
                    .WithMany(p => p.PosTrxes)
                    .HasForeignKey(d => d.CurrencyId)
                    .HasConstraintName("FK_public.PosTrxes_public.Currencies_CurrencyId");
            });

            modelBuilder.Entity<ShortCodes>(entity =>
            {
                entity.Property(e => e.Id).ValueGeneratedNever();

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

                entity.Property(e => e.TrxAmount).HasColumnType("numeric(12,3)");
            });

            OnModelCreatingPartial(modelBuilder);
        }

        partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
    }
}
