using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.Logging;
using MS.DbContexts.AccountingService;
using MS.DbContexts.Mappings;
using MS.Entities;
using MS.Entities.AccountingService_Models;
using MS.Entities.Models;
using System;
using System.Collections.Generic;
using System.Text;

namespace MS.DbContexts
{
    public class AccountingContext : DbContext
    {
        public AccountingContext(DbContextOptions<AccountingContext> options)
           : base(options)
        {
        }
        public static readonly ILoggerFactory MyLoggerFactory = LoggerFactory.Create(builder => builder.AddDebug().AddConsole());
        public DbSet<MyTransaction> TransactionInfoDtos { get; set; }
        public DbSet<AcctDto> acctDtos { get; set; }
        public DbSet<AccountRechargeTotal> accountRechargeTotals { get; set; }
        public DbSet<CardSummary> cardSummaries { get; set; }
        public DbSet<ChangeHistory> changeHistories { get; set; }
        public DbSet<GroupedAccountIdTotal> groupedAccountIdTotals { get; set; }
        
        public virtual DbSet<AccountInfo> AccountInfo { get; set; }
        public virtual DbSet<AccountType> AccountType { get; set; }
        public virtual DbSet<BlackCardInfo> BlackCardInfo { get; set; }
        public virtual DbSet<BusinessUnitInfo> BusinessUnitInfo { get; set; }
        public virtual DbSet<CardInfo> CardInfo { get; set; }
        public virtual DbSet<CardRepLossInfo> CardRepLossInfo { get; set; }
        public virtual DbSet<ChangeHistory> ChangeHistory { get; set; }
        public virtual DbSet<FleetCardRechargeHistory> FleetCardRechargeHistory { get; set; }
        public virtual DbSet<FlywaySchemaHistory> FlywaySchemaHistory { get; set; }
        public virtual DbSet<GrayInfo> GrayInfo { get; set; }
        public virtual DbSet<ImageInfo> ImageInfo { get; set; }
        public virtual DbSet<InvoiceInfo> InvoiceInfo { get; set; }
        public virtual DbSet<MembershipGroup> MembershipGroup { get; set; }
        public virtual DbSet<MembershipGrowthRules> MembershipGrowthRules { get; set; }
        public virtual DbSet<MembershipLevelInfo> MembershipLevelInfo { get; set; }
        public virtual DbSet<OfflineTransactionInfo> OfflineTransactionInfo { get; set; }
        public virtual DbSet<RechargePaymentHistory> RechargePaymentHistory { get; set; }
        public virtual DbSet<SmsInfo> SmsInfo { get; set; }
        public virtual DbSet<TransactionInfo> TransactionInfo { get; set; }
        public virtual DbSet<UserInfo> UserInfo { get; set; }
        public virtual DbSet<UserInfoMembershipGroups> UserInfoMembershipGroups { get; set; }
        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            base.OnConfiguring(optionsBuilder);
            optionsBuilder.UseLoggerFactory(MyLoggerFactory);
        }
        protected override void OnModelCreating(ModelBuilder modelBuilder)
        {
            modelBuilder.ApplyConfiguration(new MembershipGroupMap());
            modelBuilder.ApplyConfiguration(new UserInfoMap());
            modelBuilder.ApplyConfiguration(new UserInfoMembershipGroupsMap());

            modelBuilder.Entity<MembershipGroup>()
       .Ignore(m => m.BuInfoCreated);
            modelBuilder.Entity<MyTransaction>()
        .HasNoKey(); // 标记为无主键实体
            modelBuilder.Entity<AcctDto>()
     .HasNoKey(); // 标记为无主键实体
            modelBuilder.Entity<CardSummary>()
.HasNoKey(); // 标记为无主键实体
            modelBuilder.Entity<GroupedAccountIdTotal>()
.HasNoKey(); // 标记为无主键实体
            modelBuilder.Entity<AccountRechargeTotal>()
.HasNoKey(); // 标记为无主键实体


            modelBuilder.Entity<AccountInfo>(entity =>
            {
                entity.ToTable("account_info");

                entity.HasIndex(e => e.LastModified)
                    .HasName("account_info_last_modified");

                entity.HasIndex(e => new { e.BusinessUnitInfoId, e.BelongTo })
                    .HasName("account_info_bu_and_belong_to");

                entity.HasIndex(e => new { e.BusinessUnitInfoId, e.OfflineAccountId })
                    .HasName("account_info_offline_account_id");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.AccountId).HasColumnName("account_id");

                entity.Property(e => e.AccountInfoId).HasColumnName("account_info_id");

                entity.Property(e => e.AccountNo)
                    .HasColumnName("account_no")
                    .HasMaxLength(255);

                entity.Property(e => e.AccountPin)
                    .HasColumnName("account_pin")
                    .HasMaxLength(255);

                entity.Property(e => e.AccountState).HasColumnName("account_state");

                entity.Property(e => e.AccountTypeId).HasColumnName("account_type_id");

                entity.Property(e => e.AcctSno).HasColumnName("acct_sno");

                entity.Property(e => e.AcctType).HasColumnName("acct_type");

                entity.Property(e => e.Address)
                    .HasColumnName("address")
                    .HasColumnType("character varying");

                entity.Property(e => e.AmountLimit).HasColumnName("amount_limit");

                entity.Property(e => e.Balance).HasColumnName("balance");

                entity.Property(e => e.BelongTo)
                    .HasColumnName("belong_to")
                    .HasMaxLength(255);

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.BusinessUnitInfoId).HasColumnName("business_unit_info_id");

                entity.Property(e => e.CardClass).HasColumnName("card_class");

                entity.Property(e => e.CardType).HasColumnName("card_type");

                entity.Property(e => e.Cash).HasColumnName("cash");

                entity.Property(e => e.CertfNo)
                    .HasColumnName("certf_no")
                    .HasColumnType("character varying");

                entity.Property(e => e.CertfType)
                    .HasColumnName("certf_type")
                    .HasColumnType("character varying");

                entity.Property(e => e.CreationDate).HasColumnName("creation_date");

                entity.Property(e => e.DailyAmountLimit).HasColumnName("daily_amount_limit");

                entity.Property(e => e.DiscountType).HasColumnName("discount_type");

                entity.Property(e => e.EnableSms)
                    .HasColumnName("enable_sms")
                    .HasMaxLength(255);

                entity.Property(e => e.ExpirationDate).HasColumnName("expiration_date");

                entity.Property(e => e.FuelNo)
                    .HasColumnName("fuel_no")
                    .HasColumnType("character varying");

                entity.Property(e => e.GasLiterLimit)
                    .HasColumnName("gas_liter_limit")
                    .HasMaxLength(255);

                entity.Property(e => e.Gid).HasColumnName("gid");

                entity.Property(e => e.Gift).HasColumnName("gift");

                entity.Property(e => e.Holder)
                    .HasColumnName("holder")
                    .HasMaxLength(255);

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.MonthlyAmountLimit).HasColumnName("monthly_amount_limit");

                entity.Property(e => e.OfflineAccountId)
                    .HasColumnName("offline_account_id")
                    .HasMaxLength(255);

                entity.Property(e => e.OfflineDepositBalance).HasColumnName("offline_deposit_balance");

                entity.Property(e => e.OfflinePhoneNo)
                    .HasColumnName("offline_phone_no")
                    .HasMaxLength(255);

                entity.Property(e => e.OperatorNo)
                    .HasColumnName("operator_no")
                    .HasMaxLength(255);

                entity.Property(e => e.PhysicalCardUserInfo)
                    .HasColumnName("physical_card_user_info")
                    .HasMaxLength(255);

                entity.Property(e => e.PinTryLimit).HasColumnName("pin_try_limit");

                entity.Property(e => e.RechargeTotal).HasColumnName("recharge_total");

                entity.Property(e => e.Sno).HasColumnName("sno");

                entity.Property(e => e.TMac).HasColumnName("t_mac");

                entity.Property(e => e.UploadFlag).HasColumnName("upload_flag");

                entity.Property(e => e.UserId).HasColumnName("user_id");

                entity.Property(e => e.UserInfoId).HasColumnName("user_info_id");

                entity.Property(e => e.ValidationDate).HasColumnName("validation_date");

                entity.HasOne(d => d.AccountInfoNavigation)
                    .WithMany(p => p.InverseAccountInfoNavigation)
                    .HasForeignKey(d => d.AccountInfoId)
                    .HasConstraintName("fkbrnpgdi1yxogfv0s8btdq8hls");

                entity.HasOne(d => d.AccountType)
                    .WithMany(p => p.AccountInfo)
                    .HasForeignKey(d => d.AccountTypeId)
                    .HasConstraintName("fkr9nd5vvqy3s90103qlb38tsjf");

                entity.HasOne(d => d.BuInfoCreated)
                    .WithMany(p => p.AccountInfoBuInfoCreated)
                    .HasForeignKey(d => d.BuInfoCreatedId)
                    .HasConstraintName("account_info_bu_info_created_id_fkey");

                entity.HasOne(d => d.BusinessUnitInfo)
                    .WithMany(p => p.AccountInfoBusinessUnitInfo)
                    .HasForeignKey(d => d.BusinessUnitInfoId)
                    .HasConstraintName("fkke7sdylmdqsbs9tr8r9gcmg6p");

                entity.HasOne(d => d.UserInfo)
                    .WithMany(p => p.AccountInfo)
                    .HasForeignKey(d => d.UserInfoId)
                    .HasConstraintName("fk48ykkq9kivu155t7ee6svwx9h");
            });

            modelBuilder.Entity<AccountType>(entity =>
            {
                entity.ToTable("account_type");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.AccountType1).HasColumnName("account_type");

                entity.Property(e => e.MembershipDescription)
                    .HasColumnName("membership_description")
                    .HasMaxLength(255);

                entity.Property(e => e.Name)
                    .HasColumnName("name")
                    .HasMaxLength(255);
            });

            modelBuilder.Entity<BlackCardInfo>(entity =>
            {
                entity.ToTable("black_card_info");

                entity.HasIndex(e => e.LastModified)
                    .HasName("black_card_info_last_modified");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.AcctGid).HasColumnName("acct_gid");

                entity.Property(e => e.AcctId)
                    .HasColumnName("acct_id")
                    .HasMaxLength(255);

                entity.Property(e => e.BlackCardType).HasColumnName("black_card_type");

                entity.Property(e => e.BlackDate).HasColumnName("black_date");

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.BuInfoId).HasColumnName("bu_info_id");

                entity.Property(e => e.CardNo)
                    .HasColumnName("card_no")
                    .HasMaxLength(255);

                entity.Property(e => e.CardType).HasColumnName("card_type");

                entity.Property(e => e.DiscountNo).HasColumnName("discount_no");

                entity.Property(e => e.Gid).HasColumnName("gid");

                entity.Property(e => e.IsDeleted)
                    .HasColumnName("is_deleted")
                    .HasDefaultValueSql("false");

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.Reason)
                    .HasColumnName("reason")
                    .HasColumnType("character varying");

                entity.Property(e => e.UploadFlag).HasColumnName("upload_flag");

                entity.HasOne(d => d.BuInfoCreated)
                    .WithMany(p => p.BlackCardInfoBuInfoCreated)
                    .HasForeignKey(d => d.BuInfoCreatedId)
                    .HasConstraintName("black_card_info_bu_info_created_id_fkey");

                entity.HasOne(d => d.BuInfo)
                    .WithMany(p => p.BlackCardInfoBuInfo)
                    .HasForeignKey(d => d.BuInfoId)
                    .HasConstraintName("black_card_info_bu_info_id_fkey");
            });

            modelBuilder.Entity<BusinessUnitInfo>(entity =>
            {
                entity.ToTable("business_unit_info");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.AreaType)
                    .HasColumnName("area_type")
                    .HasMaxLength(255);

                entity.Property(e => e.BuAddress)
                    .HasColumnName("bu_address")
                    .HasMaxLength(255);

                entity.Property(e => e.BuName)
                    .HasColumnName("bu_name")
                    .HasMaxLength(255);

                entity.Property(e => e.BuNo).HasColumnName("bu_no");

                entity.Property(e => e.BusinessUnitInfoId).HasColumnName("business_unit_info_id");

                entity.Property(e => e.CStore).HasColumnName("c_store");

                entity.Property(e => e.CanCount).HasColumnName("can_count");

                entity.Property(e => e.CanVolume).HasColumnName("can_volume");

                entity.Property(e => e.CarWash).HasColumnName("car_wash");

                entity.Property(e => e.Character)
                    .HasColumnName("character")
                    .HasMaxLength(255);

                entity.Property(e => e.ComCount).HasColumnName("com_count");

                entity.Property(e => e.DeviceSn)
                    .HasColumnName("device_sn")
                    .HasMaxLength(255);

                entity.Property(e => e.DispenserCount).HasColumnName("dispenser_count");

                entity.Property(e => e.Email)
                    .HasColumnName("email")
                    .HasMaxLength(255);

                entity.Property(e => e.EmployeeCount).HasColumnName("employee_count");

                entity.Property(e => e.Fax)
                    .HasColumnName("fax")
                    .HasMaxLength(255);

                entity.Property(e => e.GpsCoordinates)
                    .HasColumnName("gps_coordinates")
                    .HasColumnType("character varying");

                entity.Property(e => e.IcCardType)
                    .HasColumnName("ic_card_type")
                    .HasDefaultValueSql("0");

                entity.Property(e => e.ImageLoyaltyRedemption).HasColumnName("image_loyalty_redemption");

                entity.Property(e => e.ImageMain).HasColumnName("image_main");

                entity.Property(e => e.ImageMembershipCard).HasColumnName("image_membership_card");

                entity.Property(e => e.LinkMan)
                    .HasColumnName("link_man")
                    .HasMaxLength(255);

                entity.Property(e => e.MembershipDescription).HasColumnName("membership_description");

                entity.Property(e => e.MembershipPrivacy).HasColumnName("membership_privacy");

                entity.Property(e => e.MembershipStatement).HasColumnName("membership_statement");

                entity.Property(e => e.MerchantId)
                    .HasColumnName("merchant_id")
                    .HasMaxLength(255);

                entity.Property(e => e.MerchantIpAddress)
                    .HasColumnName("merchant_ip_address")
                    .HasMaxLength(255);

                entity.Property(e => e.MerchantKey)
                    .HasColumnName("merchant_key")
                    .HasMaxLength(255);

                entity.Property(e => e.MerchantSubId)
                    .HasColumnName("merchant_sub_id")
                    .HasMaxLength(255);

                entity.Property(e => e.MiniprogramAppSecret)
                    .HasColumnName("miniprogram_app_secret")
                    .HasMaxLength(255);

                entity.Property(e => e.MiniprogramAppid)
                    .HasColumnName("miniprogram_appid")
                    .HasMaxLength(255);

                entity.Property(e => e.Mobile)
                    .HasColumnName("mobile")
                    .HasMaxLength(255);

                entity.Property(e => e.NozzleCount).HasColumnName("nozzle_count");

                entity.Property(e => e.OfflineTransferCount).HasColumnName("offline_transfer_count");

                entity.Property(e => e.Online)
                    .HasColumnName("online")
                    .HasMaxLength(255);

                entity.Property(e => e.OperationDate).HasColumnName("operation_date");

                entity.Property(e => e.ParentBuId).HasColumnName("parent_bu_id");

                entity.Property(e => e.ParkingCount).HasColumnName("parking_count");

                entity.Property(e => e.Password)
                    .HasColumnName("password")
                    .HasMaxLength(255);

                entity.Property(e => e.Phone)
                    .HasColumnName("phone")
                    .HasMaxLength(255);

                entity.Property(e => e.PosCount).HasColumnName("pos_count");

                entity.Property(e => e.PostCode)
                    .HasColumnName("post_code")
                    .HasMaxLength(255);

                entity.Property(e => e.ReferenceBuId).HasColumnName("reference_bu_id");

                entity.Property(e => e.Road)
                    .HasColumnName("road")
                    .HasMaxLength(255);

                entity.Property(e => e.RoadCount).HasColumnName("road_count");

                entity.Property(e => e.ScaleType)
                    .HasColumnName("scale_type")
                    .HasMaxLength(255);

                entity.Property(e => e.ServiceProviderId)
                    .HasColumnName("service_provider_id")
                    .HasMaxLength(255);

                entity.Property(e => e.SmsEnabled)
                    .HasColumnName("sms_enabled")
                    .HasDefaultValueSql("false");

                entity.Property(e => e.SmsMsgTemplate)
                    .HasColumnName("sms_msg_template")
                    .HasColumnType("character varying")
                    .HasDefaultValueSql("''::character varying");

                entity.Property(e => e.SmsPrimarySite)
                    .HasColumnName("sms_primary_site")
                    .HasDefaultValueSql("false");

                entity.Property(e => e.SmsRemainingCount)
                    .HasColumnName("sms_remaining_count")
                    .HasDefaultValueSql("0");

                entity.Property(e => e.SmsSentCount)
                    .HasColumnName("sms_sent_count")
                    .HasDefaultValueSql("0");

                entity.Property(e => e.UserName)
                    .HasColumnName("user_name")
                    .HasMaxLength(255);

                entity.Property(e => e.Wc).HasColumnName("wc");

                entity.Property(e => e.WxNotifyPaymentUrl)
                    .HasColumnName("wx_notify_payment_url")
                    .HasMaxLength(255);

                entity.Property(e => e.WxNotifyRechargeUrl)
                    .HasColumnName("wx_notify_recharge_url")
                    .HasMaxLength(255);

                entity.Property(e => e.WxNotifyShortCodeUrl)
                    .HasColumnName("wx_notify_short_code_url")
                    .HasMaxLength(255);

                entity.HasOne(d => d.BusinessUnitInfoNavigation)
                    .WithMany(p => p.InverseBusinessUnitInfoNavigation)
                    .HasForeignKey(d => d.BusinessUnitInfoId)
                    .HasConstraintName("fk75f37nhfy18ie24he2a0iqoba");

                entity.HasOne(d => d.ParentBu)
                    .WithMany(p => p.InverseParentBu)
                    .HasForeignKey(d => d.ParentBuId)
                    .HasConstraintName("business_unit_info_parent_bu_id_fkey");
            });

            modelBuilder.Entity<CardInfo>(entity =>
            {
                entity.ToTable("card_info");

                entity.HasIndex(e => e.LastModified)
                    .HasName("card_info_last_modified");

                entity.HasIndex(e => new { e.AccountId, e.Id })
                    .HasName("card_info_account_id_id_idx");

                entity.HasIndex(e => new { e.BusinessUnitInfoId, e.CardNo, e.Holder, e.CardType })
                    .HasName("card_info_card_no_holder_card_type");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.AccountId)
                    .HasColumnName("account_id")
                    .HasMaxLength(255);

                entity.Property(e => e.AccountInfoId).HasColumnName("account_info_id");

                entity.Property(e => e.ActivationDate).HasColumnName("activation_date");

                entity.Property(e => e.BLimitCar).HasColumnName("b_limit_car");

                entity.Property(e => e.Balance).HasColumnName("balance");

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.BusinessUnitInfoId).HasColumnName("business_unit_info_id");

                entity.Property(e => e.CarLicenseNo)
                    .HasColumnName("car_license_no")
                    .HasMaxLength(255);

                entity.Property(e => e.CardClass).HasColumnName("card_class");

                entity.Property(e => e.CardId).HasColumnName("card_id");

                entity.Property(e => e.CardNo)
                    .HasColumnName("card_no")
                    .HasMaxLength(255);

                entity.Property(e => e.CardSno).HasColumnName("card_sno");

                entity.Property(e => e.CardStatus).HasColumnName("card_status");

                entity.Property(e => e.CardType).HasColumnName("card_type");

                entity.Property(e => e.CreationDate).HasColumnName("creation_date");

                entity.Property(e => e.Ctc).HasColumnName("ctc");

                entity.Property(e => e.CtcFlag).HasColumnName("ctc_flag");

                entity.Property(e => e.CtcTime)
                    .HasColumnName("ctc_time")
                    .HasMaxLength(255);

                entity.Property(e => e.DMaxPay).HasColumnName("d_max_pay");

                entity.Property(e => e.DepositBalance).HasColumnName("deposit_balance");

                entity.Property(e => e.DiscountNo).HasColumnName("discount_no");

                entity.Property(e => e.EnableSms)
                    .HasColumnName("enable_sms")
                    .HasColumnType("character varying");

                entity.Property(e => e.ExpirationDate).HasColumnName("expiration_date");

                entity.Property(e => e.Gid).HasColumnName("gid");

                entity.Property(e => e.Holder)
                    .HasColumnName("holder")
                    .HasMaxLength(255);

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.LimitTimes).HasColumnName("limit_times");

                entity.Property(e => e.LmtGood).HasColumnName("lmt_good");

                entity.Property(e => e.LmtOil)
                    .HasColumnName("lmt_oil")
                    .HasColumnType("character varying");

                entity.Property(e => e.MMaxPay).HasColumnName("m_max_pay");

                entity.Property(e => e.OnceMaxPay).HasColumnName("once_max_pay");

                entity.Property(e => e.OperatorNo)
                    .HasColumnName("operator_no")
                    .HasMaxLength(255);

                entity.Property(e => e.PhoneNo)
                    .HasColumnName("phone_no")
                    .HasMaxLength(255);

                entity.Property(e => e.PointsAwardedTotal).HasColumnName("points_awarded_total");

                entity.Property(e => e.RechargeTotal).HasColumnName("recharge_total");

                entity.Property(e => e.Sno).HasColumnName("sno");

                entity.Property(e => e.Tmac).HasColumnName("tmac");

                entity.Property(e => e.UploadFlag).HasColumnName("upload_flag");

                entity.Property(e => e.UserNo)
                    .HasColumnName("user_no")
                    .HasMaxLength(255);

                entity.Property(e => e.UserPin)
                    .HasColumnName("user_pin")
                    .HasColumnType("character varying");

                entity.HasOne(d => d.AccountInfo)
                    .WithMany(p => p.CardInfo)
                    .HasForeignKey(d => d.AccountInfoId)
                    .HasConstraintName("fkhy8g8ddgv03kw51l2qnca3n5u");

                entity.HasOne(d => d.BuInfoCreated)
                    .WithMany(p => p.CardInfoBuInfoCreated)
                    .HasForeignKey(d => d.BuInfoCreatedId)
                    .HasConstraintName("card_info_bu_info_created_id_fkey");

                entity.HasOne(d => d.BusinessUnitInfo)
                    .WithMany(p => p.CardInfoBusinessUnitInfo)
                    .HasForeignKey(d => d.BusinessUnitInfoId)
                    .HasConstraintName("fkdoganwfsp7k6vwdohfms42c9x");
            });

            modelBuilder.Entity<CardRepLossInfo>(entity =>
            {
                entity.ToTable("card_rep_loss_info");

                entity.HasIndex(e => e.LastModified)
                    .HasName("card_rep_loss_info_last_modified");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.BuInfoId).HasColumnName("bu_info_id");

                entity.Property(e => e.CardNo)
                    .HasColumnName("card_no")
                    .HasMaxLength(255);

                entity.Property(e => e.Gid).HasColumnName("gid");

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.LossTime).HasColumnName("loss_time");

                entity.Property(e => e.OperationType).HasColumnName("operation_type");

                entity.Property(e => e.OperatorNo)
                    .HasColumnName("operator_no")
                    .HasMaxLength(255);

                entity.Property(e => e.Reason)
                    .HasColumnName("reason")
                    .HasMaxLength(255);

                entity.Property(e => e.Sno).HasColumnName("sno");

                entity.HasOne(d => d.BuInfoCreated)
                    .WithMany(p => p.CardRepLossInfoBuInfoCreated)
                    .HasForeignKey(d => d.BuInfoCreatedId)
                    .HasConstraintName("card_rep_loss_info_bu_info_created_id_fkey");

                entity.HasOne(d => d.BuInfo)
                    .WithMany(p => p.CardRepLossInfoBuInfo)
                    .HasForeignKey(d => d.BuInfoId)
                    .HasConstraintName("card_rep_loss_info_bu_info_id_fkey");
            });

            modelBuilder.Entity<ChangeHistory>(entity =>
            {
                entity.ToTable("change_history");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.BuId).HasColumnName("bu_id");

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.RecordId).HasColumnName("record_id");

                entity.Property(e => e.TableName).HasColumnName("table_name");
            });

            modelBuilder.Entity<FleetCardRechargeHistory>(entity =>
            {
                entity.ToTable("fleet_card_recharge_history");

                entity.HasIndex(e => e.BuId)
                    .HasName("fleet_card_recharge_history_bu_id");

                entity.HasIndex(e => e.LastModified)
                    .HasName("fleet_card_recharge_history_last_modified");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.AccountInfoId).HasColumnName("account_info_id");

                entity.Property(e => e.AccountName)
                    .HasColumnName("account_name")
                    .HasMaxLength(255);

                entity.Property(e => e.AccountNo)
                    .HasColumnName("account_no")
                    .HasMaxLength(255);

                entity.Property(e => e.Acknowledged)
                    .HasColumnName("acknowledged")
                    .HasDefaultValueSql("false");

                entity.Property(e => e.Amount).HasColumnName("amount");

                entity.Property(e => e.BatchNo).HasColumnName("batch_no");

                entity.Property(e => e.BuId).HasColumnName("bu_id");

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.CardHolder)
                    .HasColumnName("card_holder")
                    .HasMaxLength(255);

                entity.Property(e => e.CardInfoId).HasColumnName("card_info_id");

                entity.Property(e => e.CardNo)
                    .HasColumnName("card_no")
                    .HasMaxLength(255);

                entity.Property(e => e.CreationTime)
                    .HasColumnName("creation_time")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.Deleted)
                    .HasColumnName("deleted")
                    .HasDefaultValueSql("false");

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");
            });

            modelBuilder.Entity<FlywaySchemaHistory>(entity =>
            {
                entity.HasKey(e => e.InstalledRank)
                    .HasName("flyway_schema_history_pk");

                entity.ToTable("flyway_schema_history");

                entity.HasIndex(e => e.Success)
                    .HasName("flyway_schema_history_s_idx");

                entity.Property(e => e.InstalledRank)
                    .HasColumnName("installed_rank")
                    .ValueGeneratedNever();

                entity.Property(e => e.Checksum).HasColumnName("checksum");

                entity.Property(e => e.Description)
                    .IsRequired()
                    .HasColumnName("description")
                    .HasMaxLength(200);

                entity.Property(e => e.ExecutionTime).HasColumnName("execution_time");

                entity.Property(e => e.InstalledBy)
                    .IsRequired()
                    .HasColumnName("installed_by")
                    .HasMaxLength(100);

                entity.Property(e => e.InstalledOn)
                    .HasColumnName("installed_on")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.Script)
                    .IsRequired()
                    .HasColumnName("script")
                    .HasMaxLength(1000);

                entity.Property(e => e.Success).HasColumnName("success");

                entity.Property(e => e.Type)
                    .IsRequired()
                    .HasColumnName("type")
                    .HasMaxLength(20);

                entity.Property(e => e.Version)
                    .HasColumnName("version")
                    .HasMaxLength(50);
            });

            modelBuilder.Entity<GrayInfo>(entity =>
            {
                entity.ToTable("gray_info");

                entity.HasIndex(e => e.LastModified)
                    .HasName("gray_info_last_modified");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.BuInfoId).HasColumnName("bu_info_id");

                entity.Property(e => e.CardBalance).HasColumnName("card_balance");

                entity.Property(e => e.CardNo)
                    .HasColumnName("card_no")
                    .HasMaxLength(255);

                entity.Property(e => e.CommId)
                    .HasColumnName("comm_id")
                    .HasMaxLength(255);

                entity.Property(e => e.Ctc).HasColumnName("ctc");

                entity.Property(e => e.DiscountNo).HasColumnName("discount_no");

                entity.Property(e => e.EndPump).HasColumnName("end_pump");

                entity.Property(e => e.Gid).HasColumnName("gid");

                entity.Property(e => e.Gmac).HasColumnName("gmac");

                entity.Property(e => e.IsDeleted)
                    .HasColumnName("is_deleted")
                    .HasDefaultValueSql("false");

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.Money).HasColumnName("money");

                entity.Property(e => e.NozzleNo).HasColumnName("nozzle_no");

                entity.Property(e => e.PayTerminalId).HasColumnName("pay_terminal_id");

                entity.Property(e => e.PaymodeId).HasColumnName("paymode_id");

                entity.Property(e => e.Price).HasColumnName("price");

                entity.Property(e => e.PsamAsn)
                    .HasColumnName("psam_asn")
                    .HasMaxLength(255);

                entity.Property(e => e.PsamTac).HasColumnName("psam_tac");

                entity.Property(e => e.PsamTid)
                    .HasColumnName("psam_tid")
                    .HasMaxLength(255);

                entity.Property(e => e.PsamTtc)
                    .HasColumnName("psam_ttc")
                    .HasMaxLength(255);

                entity.Property(e => e.PumpNo).HasColumnName("pump_no");

                entity.Property(e => e.PumpType).HasColumnName("pump_type");

                entity.Property(e => e.RealMoney).HasColumnName("real_money");

                entity.Property(e => e.SequenceNo).HasColumnName("sequence_no");

                entity.Property(e => e.Sno).HasColumnName("sno");

                entity.Property(e => e.Tac).HasColumnName("tac");

                entity.Property(e => e.Tmac).HasColumnName("tmac");

                entity.Property(e => e.TrdType).HasColumnName("trd_type");

                entity.Property(e => e.Ttc).HasColumnName("ttc");

                entity.Property(e => e.TtcTime).HasColumnName("ttc_time");

                entity.Property(e => e.TtcTimeEnd).HasColumnName("ttc_time_end");

                entity.Property(e => e.UploadFlag).HasColumnName("upload_flag");

                entity.Property(e => e.Volume).HasColumnName("volume");

                entity.HasOne(d => d.BuInfoCreated)
                    .WithMany(p => p.GrayInfoBuInfoCreated)
                    .HasForeignKey(d => d.BuInfoCreatedId)
                    .HasConstraintName("gray_info_bu_info_created_id_fkey");

                entity.HasOne(d => d.BuInfo)
                    .WithMany(p => p.GrayInfoBuInfo)
                    .HasForeignKey(d => d.BuInfoId)
                    .HasConstraintName("gray_info_bu_info_id_fkey");
            });

            modelBuilder.Entity<ImageInfo>(entity =>
            {
                entity.ToTable("image_info");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.Image).HasColumnName("image");

                entity.Property(e => e.ImageName)
                    .HasColumnName("image_name")
                    .HasMaxLength(255);
            });

            modelBuilder.Entity<InvoiceInfo>(entity =>
            {
                entity.ToTable("invoice_info");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.Amount).HasColumnName("amount");

                entity.Property(e => e.Balance).HasColumnName("balance");

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.BuInfoId).HasColumnName("bu_info_id");

                entity.Property(e => e.CardNo)
                    .HasColumnName("card_no")
                    .HasMaxLength(255);

                entity.Property(e => e.Comments)
                    .HasColumnName("comments")
                    .HasMaxLength(255);

                entity.Property(e => e.IssuedTimestamp).HasColumnName("issued_timestamp");

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.PhoneNo)
                    .HasColumnName("phone_no")
                    .HasMaxLength(255)
                    .HasDefaultValueSql("''::character varying");

                entity.Property(e => e.UserInfoId).HasColumnName("user_info_id");

                entity.HasOne(d => d.BuInfoCreated)
                    .WithMany(p => p.InvoiceInfoBuInfoCreated)
                    .HasForeignKey(d => d.BuInfoCreatedId)
                    .HasConstraintName("invoice_info_bu_info_created_id_fkey");

                entity.HasOne(d => d.BuInfo)
                    .WithMany(p => p.InvoiceInfoBuInfo)
                    .HasForeignKey(d => d.BuInfoId)
                    .HasConstraintName("invoice_info_bu_info_id_fkey");

                entity.HasOne(d => d.UserInfo)
                    .WithMany(p => p.InvoiceInfo)
                    .HasForeignKey(d => d.UserInfoId)
                    .HasConstraintName("invoice_info_user_info_id_fkey");
            });

            modelBuilder.Entity<MembershipGroup>(entity =>
            {
                entity.ToTable("membership_group");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.BuInfoId).HasColumnName("bu_info_id");

                entity.Property(e => e.ConfigAppliedItems)
                    .HasColumnName("config_applied_items")
                    .HasMaxLength(255);

                entity.Property(e => e.ConfigCreationTimeFrom).HasColumnName("config_creation_time_from");

                entity.Property(e => e.ConfigCreationTimeTo).HasColumnName("config_creation_time_to");

                entity.Property(e => e.ConfigEAccountBalanceFrom)
                    .HasColumnName("config_e_account_balance_from")
                    .HasDefaultValueSql("0");

                entity.Property(e => e.ConfigEAccountBalanceTo)
                    .HasColumnName("config_e_account_balance_to")
                    .HasDefaultValueSql("0");

                entity.Property(e => e.ConfigEndTimeOfDay)
                    .HasColumnName("config_end_time_of_day")
                    .HasMaxLength(255);

                entity.Property(e => e.ConfigGender).HasColumnName("config_gender");

                entity.Property(e => e.ConfigLevel)
                    .HasColumnName("config_level")
                    .HasMaxLength(255);

                entity.Property(e => e.ConfigPhysicalCard).HasColumnName("config_physical_card");

                entity.Property(e => e.ConfigRfmFrequencyFrom).HasColumnName("config_rfm_frequency_from");

                entity.Property(e => e.ConfigRfmFrequencyTo).HasColumnName("config_rfm_frequency_to");

                entity.Property(e => e.ConfigRfmMonetaryAbove).HasColumnName("config_rfm_monetary_above");

                entity.Property(e => e.ConfigRfmMonetaryBelow).HasColumnName("config_rfm_monetary_below");

                entity.Property(e => e.ConfigRfmRecencyBefore).HasColumnName("config_rfm_recency_before");

                entity.Property(e => e.ConfigSpecifiedDateOfMonth)
                    .HasColumnName("config_specified_date_of_month")
                    .HasMaxLength(255);

                entity.Property(e => e.ConfigSpecifiedDateOfMonthCount).HasColumnName("config_specified_date_of_month_count");

                entity.Property(e => e.ConfigSpecifiedDayOfWeek)
                    .HasColumnName("config_specified_day_of_week")
                    .HasMaxLength(255);

                entity.Property(e => e.ConfigSpecifiedDayOfWeekCount).HasColumnName("config_specified_day_of_week_count");

                entity.Property(e => e.ConfigStartTimeOfDay)
                    .HasColumnName("config_start_time_of_day")
                    .HasMaxLength(255);

                entity.Property(e => e.ConfigTimeOfDayCount).HasColumnName("config_time_of_day_count");

                entity.Property(e => e.CreationTime).HasColumnName("creation_time");

                entity.Property(e => e.Description)
                    .HasColumnName("description")
                    .HasMaxLength(255);

                entity.Property(e => e.GroupId)
                    .HasColumnName("group_id")
                    .HasMaxLength(255);

                entity.Property(e => e.GroupMemberLimit).HasColumnName("group_member_limit");

                entity.Property(e => e.GroupName)
                    .HasColumnName("group_name")
                    .HasMaxLength(255);

                entity.Property(e => e.GroupStatus)
                    .HasColumnName("group_status")
                    .HasDefaultValueSql("1");

                entity.Property(e => e.GroupType).HasColumnName("group_type");

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.LastRefreshTime).HasColumnName("last_refresh_time");

                entity.Property(e => e.MembershipLevel).HasColumnName("membership_level");

                entity.HasOne(d => d.BuInfoCreated)
                    .WithMany(p => p.MembershipGroupBuInfoCreated)
                    .HasForeignKey(d => d.BuInfoCreatedId)
                    .HasConstraintName("membership_group_bu_info_created_id_fkey");

                entity.HasOne(d => d.BuInfo)
                    .WithMany(p => p.MembershipGroupBuInfo)
                    .HasForeignKey(d => d.BuInfoId)
                    .HasConstraintName("membership_group_bu_info_id_fkey");

                entity.HasOne(d => d.MembershipLevelNavigation)
                    .WithMany(p => p.MembershipGroup)
                    .HasForeignKey(d => d.MembershipLevel)
                    .HasConstraintName("membership_group_membership_level_fkey");
            });

            modelBuilder.Entity<MembershipGrowthRules>(entity =>
            {
                entity.ToTable("membership_growth_rules");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.BuInfoId).HasColumnName("bu_info_id");

                entity.Property(e => e.GrowthType).HasColumnName("growth_type");

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.ValidBegin).HasColumnName("valid_begin");

                entity.Property(e => e.ValidEnd).HasColumnName("valid_end");

                entity.Property(e => e.ValidateType).HasColumnName("validate_type");

                entity.HasOne(d => d.BuInfoCreated)
                    .WithMany(p => p.MembershipGrowthRulesBuInfoCreated)
                    .HasForeignKey(d => d.BuInfoCreatedId)
                    .HasConstraintName("membership_growth_rules_bu_info_created_id_fkey");

                entity.HasOne(d => d.BuInfo)
                    .WithMany(p => p.MembershipGrowthRulesBuInfo)
                    .HasForeignKey(d => d.BuInfoId)
                    .HasConstraintName("membership_growth_rules_bu_info_id_fkey");
            });

            modelBuilder.Entity<MembershipLevelInfo>(entity =>
            {
                entity.ToTable("membership_level_info");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.BuInfoId).HasColumnName("bu_info_id");

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.LevelName)
                    .HasColumnName("level_name")
                    .HasMaxLength(255);

                entity.Property(e => e.LevelRetainCondition).HasColumnName("level_retain_condition");

                entity.Property(e => e.LevelUpCondition).HasColumnName("level_up_condition");

                entity.Property(e => e.MembershipLevelId)
                    .HasColumnName("membership_level_id")
                    .HasMaxLength(255);

                entity.Property(e => e.NextLevelId).HasColumnName("next_level_id");

                entity.Property(e => e.UpperLevelId).HasColumnName("upper_level_id");

                entity.HasOne(d => d.BuInfoCreated)
                    .WithMany(p => p.MembershipLevelInfoBuInfoCreated)
                    .HasForeignKey(d => d.BuInfoCreatedId)
                    .HasConstraintName("membership_level_info_bu_info_created_id_fkey");

                entity.HasOne(d => d.BuInfo)
                    .WithMany(p => p.MembershipLevelInfoBuInfo)
                    .HasForeignKey(d => d.BuInfoId)
                    .HasConstraintName("membership_level_info_bu_info_id_fkey");

                entity.HasOne(d => d.NextLevel)
                    .WithMany(p => p.InverseNextLevel)
                    .HasForeignKey(d => d.NextLevelId)
                    .HasConstraintName("membership_level_info_next_level_id_fkey");

                entity.HasOne(d => d.UpperLevel)
                    .WithMany(p => p.InverseUpperLevel)
                    .HasForeignKey(d => d.UpperLevelId)
                    .HasConstraintName("membership_level_info_upper_level_id_fkey");
            });

            modelBuilder.Entity<OfflineTransactionInfo>(entity =>
            {
                entity.HasNoKey();

                entity.ToTable("offline_transaction_info");

                entity.HasIndex(e => new { e.BusinessUnitInfoId, e.TransactionTime })
                    .HasName("offline_transaction_info_business_unit_info_id_idx");

                entity.Property(e => e.AccountId)
                    .HasColumnName("account_id")
                    .HasMaxLength(255);

                entity.Property(e => e.AccountInfoId).HasColumnName("account_info_id");

                entity.Property(e => e.Amount).HasColumnName("amount");

                entity.Property(e => e.Balance).HasColumnName("balance");

                entity.Property(e => e.BarCode)
                    .HasColumnName("bar_code")
                    .HasColumnType("character varying");

                entity.Property(e => e.BillNo).HasColumnName("bill_no");

                entity.Property(e => e.BillType).HasColumnName("bill_type");

                entity.Property(e => e.BusinessUnitInfoId).HasColumnName("business_unit_info_id");

                entity.Property(e => e.CarId)
                    .HasColumnName("car_id")
                    .HasColumnType("character varying");

                entity.Property(e => e.CarLicenseNo)
                    .HasColumnName("car_license_no")
                    .HasMaxLength(255);

                entity.Property(e => e.CardBalance).HasColumnName("card_balance");

                entity.Property(e => e.CardInfoId).HasColumnName("card_info_id");

                entity.Property(e => e.CardNo)
                    .HasColumnName("card_no")
                    .HasMaxLength(255);

                entity.Property(e => e.CardSequenceNo).HasColumnName("card_sequence_no");

                entity.Property(e => e.CardType).HasColumnName("card_type");

                entity.Property(e => e.CommId)
                    .HasColumnName("comm_id")
                    .HasColumnType("character varying");

                entity.Property(e => e.Comments)
                    .HasColumnName("comments")
                    .HasMaxLength(255);

                entity.Property(e => e.Ctc).HasColumnName("ctc");

                entity.Property(e => e.DisIntegral).HasColumnName("dis_integral");

                entity.Property(e => e.DisMoney).HasColumnName("dis_money");

                entity.Property(e => e.DiscountNo).HasColumnName("discount_no");

                entity.Property(e => e.EmployeeNo)
                    .HasColumnName("employee_no")
                    .HasMaxLength(255);

                entity.Property(e => e.EndTotalizer).HasColumnName("end_totalizer");

                entity.Property(e => e.FuelName)
                    .HasColumnName("fuel_name")
                    .HasColumnType("character varying")
                    .HasDefaultValueSql("''::character varying");

                entity.Property(e => e.Gid).HasColumnName("gid");

                entity.Property(e => e.Gmac).HasColumnName("gmac");

                entity.Property(e => e.GrossAmount).HasColumnName("gross_amount");

                entity.Property(e => e.Id).HasColumnName("id");

                entity.Property(e => e.Integral).HasColumnName("integral");

                entity.Property(e => e.InvoiceIssued).HasColumnName("invoice_issued");

                entity.Property(e => e.InvoiceType).HasColumnName("invoice_type");

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.LineNo)
                    .HasColumnName("line_no")
                    .HasMaxLength(255);

                entity.Property(e => e.Mileage).HasColumnName("mileage");

                entity.Property(e => e.NozzleNo).HasColumnName("nozzle_no");

                entity.Property(e => e.OperCardNo)
                    .HasColumnName("oper_card_no")
                    .HasColumnType("character varying");

                entity.Property(e => e.Operator)
                    .HasColumnName("operator")
                    .HasMaxLength(255);

                entity.Property(e => e.PayModeId).HasColumnName("pay_mode_id");

                entity.Property(e => e.PayModeNo)
                    .HasColumnName("pay_mode_no")
                    .HasMaxLength(255);

                entity.Property(e => e.PayTemId).HasColumnName("pay_tem_id");

                entity.Property(e => e.PaymentId).HasColumnName("payment_id");

                entity.Property(e => e.PosId).HasColumnName("pos_id");

                entity.Property(e => e.Price).HasColumnName("price");

                entity.Property(e => e.ProductId)
                    .HasColumnName("product_id")
                    .HasMaxLength(255);

                entity.Property(e => e.PsamAsn)
                    .HasColumnName("psam_asn")
                    .HasColumnType("character varying");

                entity.Property(e => e.PsamTac).HasColumnName("psam_tac");

                entity.Property(e => e.PsamTid)
                    .HasColumnName("psam_tid")
                    .HasColumnType("character varying");

                entity.Property(e => e.PsamTtc).HasColumnName("psam_ttc");

                entity.Property(e => e.PumpNo).HasColumnName("pump_no");

                entity.Property(e => e.PumpType).HasColumnName("pump_type");

                entity.Property(e => e.ReceiptNo).HasColumnName("receipt_no");

                entity.Property(e => e.RechargeType).HasColumnName("recharge_type");

                entity.Property(e => e.SequenceNo).HasColumnName("sequence_no");

                entity.Property(e => e.ShiftId).HasColumnName("shift_id");

                entity.Property(e => e.SmsSent)
                    .HasColumnName("sms_sent")
                    .HasDefaultValueSql("false");

                entity.Property(e => e.Sno).HasColumnName("sno");

                entity.Property(e => e.SubTransactionType).HasColumnName("sub_transaction_type");

                entity.Property(e => e.Tac).HasColumnName("tac");

                entity.Property(e => e.Tmac).HasColumnName("tmac");

                entity.Property(e => e.TransactionTime).HasColumnName("transaction_time");

                entity.Property(e => e.TransactionType).HasColumnName("transaction_type");

                entity.Property(e => e.TrxEndTime).HasColumnName("trx_end_time");

                entity.Property(e => e.TrxOriginalId)
                    .HasColumnName("trx_original_id")
                    .HasMaxLength(255);

                entity.Property(e => e.TrxSequenceNo)
                    .HasColumnName("trx_sequence_no")
                    .HasMaxLength(255);

                entity.Property(e => e.TrxStartTime).HasColumnName("trx_start_time");

                entity.Property(e => e.Ttc).HasColumnName("ttc");

                entity.Property(e => e.Volume).HasColumnName("volume");

                entity.HasOne(d => d.AccountInfo)
                    .WithMany()
                    .HasForeignKey(d => d.AccountInfoId)
                    .HasConstraintName("fk23gjts31sw86t9b674iadlyaj");

                entity.HasOne(d => d.BusinessUnitInfo)
                    .WithMany()
                    .HasForeignKey(d => d.BusinessUnitInfoId)
                    .HasConstraintName("fk14c59inbbebmk3gbmnthp3jb6");

                entity.HasOne(d => d.CardInfo)
                    .WithMany()
                    .HasForeignKey(d => d.CardInfoId)
                    .HasConstraintName("fk1f9j7u7gbj0wy2juhw14bn0lp");
            });

            modelBuilder.Entity<RechargePaymentHistory>(entity =>
            {
                entity.ToTable("recharge_payment_history");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.AccountBalance).HasColumnName("account_balance");

                entity.Property(e => e.AccountInfoId).HasColumnName("account_info_id");

                entity.Property(e => e.BusinessUnitInfoId).HasColumnName("business_unit_info_id");

                entity.Property(e => e.DiscountNo).HasColumnName("discount_no");

                entity.Property(e => e.LoyaltyPointsAwarded).HasColumnName("loyalty_points_awarded");

                entity.Property(e => e.LoyaltyPointsBalance).HasColumnName("loyalty_points_balance");

                entity.Property(e => e.OperatorNo)
                    .HasColumnName("operator_no")
                    .HasMaxLength(255);

                entity.Property(e => e.PaymentAmount).HasColumnName("payment_amount");

                entity.Property(e => e.RechargeAmount).HasColumnName("recharge_amount");

                entity.Property(e => e.TransactionDate).HasColumnName("transaction_date");

                entity.Property(e => e.TransactionType).HasColumnName("transaction_type");

                entity.Property(e => e.TrxOriginalId)
                    .HasColumnName("trx_original_id")
                    .HasMaxLength(255);

                entity.Property(e => e.TrxSequenceNo)
                    .HasColumnName("trx_sequence_no")
                    .HasMaxLength(255);

                entity.HasOne(d => d.AccountInfo)
                    .WithMany(p => p.RechargePaymentHistory)
                    .HasForeignKey(d => d.AccountInfoId)
                    .HasConstraintName("fk9ig9ho56ln4hmphmtdxofebfd");

                entity.HasOne(d => d.BusinessUnitInfo)
                    .WithMany(p => p.RechargePaymentHistory)
                    .HasForeignKey(d => d.BusinessUnitInfoId)
                    .HasConstraintName("fknkbj1nmk3hp0aloybvvf0dfqi");
            });

            modelBuilder.Entity<SmsInfo>(entity =>
            {
                entity.ToTable("sms_info");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.BuInfoCreatedId).HasColumnName("bu_info_created_id");

                entity.Property(e => e.BuInfoId).HasColumnName("bu_info_id");

                entity.Property(e => e.CreationDate)
                    .HasColumnName("creation_date")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.ExpirationDate).HasColumnName("expiration_date");

                entity.Property(e => e.LastModified)
                    .HasColumnName("last_modified")
                    .HasDefaultValueSql("now()");

                entity.Property(e => e.RechargeAmount).HasColumnName("recharge_amount");

                entity.HasOne(d => d.BuInfoCreated)
                    .WithMany(p => p.SmsInfoBuInfoCreated)
                    .HasForeignKey(d => d.BuInfoCreatedId)
                    .HasConstraintName("sms_info_bu_info_created_id_fkey");

                entity.HasOne(d => d.BuInfo)
                    .WithMany(p => p.SmsInfoBuInfo)
                    .HasForeignKey(d => d.BuInfoId)
                    .HasConstraintName("sms_info_bu_info_id_fkey");
            });

            modelBuilder.Entity<TransactionInfo>(entity =>
            {
                entity.ToTable("transaction_info");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.AccountInfoId).HasColumnName("account_info_id");

                entity.Property(e => e.Amount).HasColumnName("amount");

                entity.Property(e => e.CarLicenseNo)
                    .HasColumnName("car_license_no")
                    .HasMaxLength(255);

                entity.Property(e => e.CardBalance).HasColumnName("card_balance");

                entity.Property(e => e.CardNo)
                    .HasColumnName("card_no")
                    .HasMaxLength(255);

                entity.Property(e => e.CardType).HasColumnName("card_type");

                entity.Property(e => e.DiscountNo).HasColumnName("discount_no");

                entity.Property(e => e.EmployeeNo)
                    .HasColumnName("employee_no")
                    .HasMaxLength(255);

                entity.Property(e => e.LineNo)
                    .HasColumnName("line_no")
                    .HasMaxLength(255);

                entity.Property(e => e.Mileage).HasColumnName("mileage");

                entity.Property(e => e.NozzleNo).HasColumnName("nozzle_no");

                entity.Property(e => e.Operator)
                    .HasColumnName("operator")
                    .HasMaxLength(255);

                entity.Property(e => e.PayModeId).HasColumnName("pay_mode_id");

                entity.Property(e => e.PayModeNo)
                    .HasColumnName("pay_mode_no")
                    .HasMaxLength(255);

                entity.Property(e => e.PaymentId).HasColumnName("payment_id");

                entity.Property(e => e.PosId).HasColumnName("pos_id");

                entity.Property(e => e.Price).HasColumnName("price");

                entity.Property(e => e.ProductId)
                    .HasColumnName("product_id")
                    .HasMaxLength(255);

                entity.Property(e => e.PumpNo).HasColumnName("pump_no");

                entity.Property(e => e.PumpType).HasColumnName("pump_type");

                entity.Property(e => e.ReceiptNo).HasColumnName("receipt_no");

                entity.Property(e => e.SequenceNo).HasColumnName("sequence_no");

                entity.Property(e => e.ShiftId).HasColumnName("shift_id");

                entity.Property(e => e.TransactionType).HasColumnName("transaction_type");

                entity.Property(e => e.TrxOriginalId)
                    .HasColumnName("trx_original_id")
                    .HasMaxLength(255);

                entity.Property(e => e.TrxSequenceNo)
                    .HasColumnName("trx_sequence_no")
                    .HasMaxLength(255);

                entity.Property(e => e.Volume).HasColumnName("volume");

                entity.HasOne(d => d.AccountInfo)
                    .WithMany(p => p.TransactionInfo)
                    .HasForeignKey(d => d.AccountInfoId)
                    .HasConstraintName("fks1xvhy67lr9k1i7r3fbwmo36o");
            });

            modelBuilder.Entity<UserInfo>(entity =>
            {
                entity.ToTable("user_info");

                entity.HasIndex(e => e.BusinessUnitInfoId)
                    .HasName("user_info_bu_id");

                entity.HasIndex(e => e.Id)
                    .HasName("user_info_id");

                entity.HasIndex(e => new { e.BusinessUnitInfoId, e.PhoneNo })
                    .HasName("user_info_bu_id_phone_no");

                entity.HasIndex(e => new { e.BusinessUnitInfoId, e.UserName })
                    .HasName("user_info_bu_id_user_name");

                entity.HasIndex(e => new { e.BusinessUnitInfoId, e.UserNo })
                    .HasName("user_info_bu_id_user_no");

                entity.Property(e => e.Id)
                    .HasColumnName("id")
                    .ValueGeneratedNever();

                entity.Property(e => e.Address)
                    .HasColumnName("address")
                    .HasMaxLength(255);

                entity.Property(e => e.AliPayId)
                    .HasColumnName("ali_pay_id")
                    .HasMaxLength(255);

                entity.Property(e => e.Amount).HasColumnName("amount");

                entity.Property(e => e.Birthday).HasColumnName("birthday");

                entity.Property(e => e.BuId)
                    .HasColumnName("bu_id")
                    .HasMaxLength(255);

                entity.Property(e => e.BuString)
                    .HasColumnName("bu_string")
                    .HasMaxLength(255);

                entity.Property(e => e.BusinessUnitInfoId).HasColumnName("business_unit_info_id");

                entity.Property(e => e.CertificateNo)
                    .HasColumnName("certificate_no")
                    .HasMaxLength(255);

                entity.Property(e => e.CertificateType)
                    .HasColumnName("certificate_type")
                    .HasMaxLength(255);

                entity.Property(e => e.CreationDate).HasColumnName("creation_date");

                entity.Property(e => e.EnableSms).HasColumnName("enable_sms");

                entity.Property(e => e.FuelNo)
                    .HasColumnName("fuel_no")
                    .HasMaxLength(255);

                entity.Property(e => e.Gender)
                    .HasColumnName("gender")
                    .HasMaxLength(255);

                entity.Property(e => e.Gift).HasColumnName("gift");

                entity.Property(e => e.InvoiceBalance).HasColumnName("invoice_balance");

                entity.Property(e => e.LastActiveDate).HasColumnName("last_active_date");

                entity.Property(e => e.LastLevelUpTime).HasColumnName("last_level_up_time");

                entity.Property(e => e.LastMembershipLevel).HasColumnName("last_membership_level");

                entity.Property(e => e.MembershipLevel).HasColumnName("membership_level");

                entity.Property(e => e.MembershipPoints)
                    .HasColumnName("membership_points")
                    .HasMaxLength(255);

                entity.Property(e => e.NextLevelUpDateTime).HasColumnName("next_level_up_date_time");

                entity.Property(e => e.OfflineTransferRemaining).HasColumnName("offline_transfer_remaining");

                entity.Property(e => e.PassCode)
                    .HasColumnName("pass_code")
                    .HasMaxLength(255);

                entity.Property(e => e.Password)
                    .HasColumnName("password")
                    .HasMaxLength(255);

                entity.Property(e => e.PhoneNo)
                    .HasColumnName("phone_no")
                    .HasMaxLength(255);

                entity.Property(e => e.Portrait)
                    .HasColumnName("portrait")
                    .HasMaxLength(255);

                entity.Property(e => e.RechargeTotal).HasColumnName("recharge_total");

                entity.Property(e => e.TotalSpending)
                    .HasColumnName("total_spending")
                    .HasDefaultValueSql("0");

                entity.Property(e => e.TotalVolume)
                    .HasColumnName("total_volume")
                    .HasDefaultValueSql("0");

                entity.Property(e => e.UnionId)
                    .HasColumnName("union_id")
                    .HasMaxLength(255);

                entity.Property(e => e.UserId).HasColumnName("user_id");

                entity.Property(e => e.UserInfoId).HasColumnName("user_info_id");

                entity.Property(e => e.UserName)
                    .HasColumnName("user_name")
                    .HasMaxLength(255);

                entity.Property(e => e.UserNo)
                    .HasColumnName("user_no")
                    .HasMaxLength(255);

                entity.Property(e => e.UserState).HasColumnName("user_state");

                entity.Property(e => e.UserType).HasColumnName("user_type");

                entity.Property(e => e.VehicleLicenseNo)
                    .HasColumnName("vehicle_license_no")
                    .HasMaxLength(255);

                entity.Property(e => e.VehicleModel)
                    .HasColumnName("vehicle_model")
                    .HasMaxLength(255);

                entity.HasOne(d => d.BusinessUnitInfo)
                    .WithMany(p => p.UserInfo)
                    .HasForeignKey(d => d.BusinessUnitInfoId)
                    .HasConstraintName("fksxb41p6dxyhjqm7r10vlxfd6g");

                entity.HasOne(d => d.LastMembershipLevelNavigation)
                    .WithMany(p => p.UserInfoLastMembershipLevelNavigation)
                    .HasForeignKey(d => d.LastMembershipLevel)
                    .HasConstraintName("user_info_last_membership_level_fkey");

                entity.HasOne(d => d.MembershipLevelNavigation)
                    .WithMany(p => p.UserInfoMembershipLevelNavigation)
                    .HasForeignKey(d => d.MembershipLevel)
                    .HasConstraintName("user_info_membership_level_fkey");

                entity.HasOne(d => d.UserInfoNavigation)
                    .WithMany(p => p.InverseUserInfoNavigation)
                    .HasForeignKey(d => d.UserInfoId)
                    .HasConstraintName("fk5ua5b6b1a136mgeuapq75epg");
            });

            modelBuilder.Entity<UserInfoMembershipGroups>(entity =>
            {
                entity.HasKey(e => new { e.UserInfoId, e.MembershipGroupId })
                    .HasName("user_info_membership_groups_pkey");

                entity.ToTable("user_info_membership_groups");

                entity.Property(e => e.UserInfoId).HasColumnName("user_info_id");

                entity.Property(e => e.MembershipGroupId).HasColumnName("membership_group_id");

                entity.HasOne(d => d.MembershipGroup)
                    .WithMany(p => p.UserInfoMembershipGroups)
                    .HasForeignKey(d => d.MembershipGroupId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("user_info_membership_groups_membership_group_id_fkey");

                entity.HasOne(d => d.UserInfo)
                    .WithMany(p => p.UserInfoMembershipGroups)
                    .HasForeignKey(d => d.UserInfoId)
                    .OnDelete(DeleteBehavior.ClientSetNull)
                    .HasConstraintName("user_info_membership_groups_user_info_id_fkey");
            });

            modelBuilder.HasSequence("change_history_id_seq");

            modelBuilder.HasSequence("fleet_card_recharge_history_id_seq");

            base.OnModelCreating(modelBuilder);
        }
    }
}
