using System;
using System.Collections.Generic;
using Microsoft.EntityFrameworkCore;

namespace CloudGaming.Model.DbSqlServer.Db_User;

/// <summary>
/// 云游戏实体类
/// </summary>
public partial class CloudGamingUserContext : MultiTenantDbContext//DbContext
{
    public CloudGamingUserContext() : base(null)
    {
    }

    public CloudGamingUserContext(DbContextOptions<CloudGamingUserContext> options)
         : base(null, options)
    {
    }

    /// <summary>
    /// 
    /// </summary>
    /// <param name="tenantInfo"></param>
    public CloudGamingUserContext(ITenantInfo tenantInfo) : base(tenantInfo)
    {

    }


    /// <summary>
    /// 
    /// </summary>
    /// <param name="tenantInfo"></param>
    /// <param name="options"></param>
    public CloudGamingUserContext(ITenantInfo tenantInfo, DbContextOptions<CloudGamingUserContext> options) : base(tenantInfo, options)
    {
    }


    /// <summary>
    /// 用户表
    /// </summary>
    public virtual DbSet<T_User> T_User { get; set; }

    /// <summary>
    /// 用户货币表
    /// </summary>
    public virtual DbSet<T_User_Currency> T_User_Currency { get; set; }

    /// <summary>
    /// 用户金额记录表
    /// </summary>
    public virtual DbSet<T_User_Currency_Log> T_User_Currency_Log { get; set; }

    /// <summary>
    /// 用户扩展表
    /// </summary>
    public virtual DbSet<T_User_Data> T_User_Data { get; set; }

    /// <summary>
    /// 资产收入、支出表
    /// </summary>
    public virtual DbSet<T_User_DiamondList> T_User_DiamondList { get; set; }

    /// <summary>
    /// 我的游戏收藏
    /// </summary>
    public virtual DbSet<T_User_GameFavorite> T_User_GameFavorite { get; set; }

    /// <summary>
    /// 意向订单表
    /// </summary>
    public virtual DbSet<T_User_IntentOrder> T_User_IntentOrder { get; set; }

    /// <summary>
    /// 用户设备限制行为日志表
    /// </summary>
    public virtual DbSet<T_User_LimitActionLog> T_User_LimitActionLog { get; set; }

    /// <summary>
    /// 小程序登录表
    /// </summary>
    public virtual DbSet<T_User_MiniProgram_Account> T_User_MiniProgram_Account { get; set; }

    /// <summary>
    /// 订单完成表
    /// </summary>
    public virtual DbSet<T_User_Order> T_User_Order { get; set; }

    /// <summary>
    /// 订单详情表
    /// </summary>
    public virtual DbSet<T_User_OrderItems> T_User_OrderItems { get; set; }

    /// <summary>
    /// 手机号登录表
    /// </summary>
    public virtual DbSet<T_User_Phone_Account> T_User_Phone_Account { get; set; }

    /// <summary>
    /// 用户单点登录表
    /// </summary>
    public virtual DbSet<T_User_Token> T_User_Token { get; set; }

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
     {  // => optionsBuilder.UseSqlServer("Server=192.168.195.8;Database=CloudGamingUser;User Id=sa;Password=Dbt@com@123;TrustServerCertificate=true;");
      } 

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<T_User>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__T_User__3214EC073733108B");

            entity.ToTable(tb => tb.HasComment("用户表"));

            entity.Property(e => e.Id).HasComment("用户Id");
            entity.Property(e => e.CreatedAt)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.IDCard)
                .HasMaxLength(64)
                .HasComment("身份证号");
            entity.Property(e => e.Ip)
                .HasMaxLength(100)
                .HasComment("Ip地址")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.IsTest).HasComment("是否是测试账号");
            entity.Property(e => e.LastLoginAt)
                .HasComment("最后一次登录时间")
                .HasColumnType("datetime");
            entity.Property(e => e.LastLoginType).HasComment("最后一次登录方式,1手机号，2默认登录");
            entity.Property(e => e.NickName)
                .HasMaxLength(100)
                .HasComment("用户昵称")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.RegisterType).HasComment("首次注册方式");
            entity.Property(e => e.State).HasComment("0正常，1注销");
            entity.Property(e => e.TenantId).HasComment("租户Id");
            entity.Property(e => e.UpdatedAt)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.UserIconUrl)
                .HasMaxLength(300)
                .HasComment("用户头像")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.UserName)
                .HasMaxLength(100)
                .HasComment("姓名")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.UserRealNameStatus).HasComment("用户实名认证状态0未认证，1已整整，2未成年");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_Currency>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__T_User_C__3214EC0728E86D78");

            entity.ToTable(tb => tb.HasComment("用户货币表"));

            entity.Property(e => e.CreateAt)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.CurrencyMoney)
                .HasComment("货币余额")
                .HasColumnType("decimal(10, 2)");
            entity.Property(e => e.CurrencyName)
                .HasMaxLength(20)
                .HasComment("货币名称")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.CurrencyType).HasComment("货币类型 付费币、免费币");
            entity.Property(e => e.TenantId).HasComment("租户Id");
            entity.Property(e => e.UpdateAt)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.UserId).HasComment("用户Id");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_Currency_Log>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__T_User_C__3214EC07DBD26048");

            entity.ToTable(tb => tb.HasComment("用户金额记录表"));

            entity.Property(e => e.Consume)
                .HasComment("金额")
                .HasColumnType("decimal(10, 2)");
            entity.Property(e => e.ConsumeType).HasComment("消耗类型,0消耗，1增加");
            entity.Property(e => e.CreateAt)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.CurrencyType).HasComment("金额类型");
            entity.Property(e => e.Remarks)
                .HasMaxLength(255)
                .HasComment("备注")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.TenantId).HasComment("租户");
            entity.Property(e => e.UpdateAt)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.UserId).HasComment("用户");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_Data>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__T_UsersD__3214EC0738D57E8A");

            entity.ToTable(tb => tb.HasComment("用户扩展表"));

            entity.HasIndex(e => new { e.TenantId, e.UserId }, "UserData_index");

            entity.Property(e => e.Id).HasComment("主键");
            entity.Property(e => e.CreateAt)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.DeviceNumber)
                .HasMaxLength(255)
                .HasComment("设备号");
            entity.Property(e => e.Email)
                .HasMaxLength(255)
                .HasComment("邮箱");
            entity.Property(e => e.PhoneNum)
                .HasMaxLength(20)
                .HasComment("手机号");
            entity.Property(e => e.TenantId).HasComment("多租户");
            entity.Property(e => e.UpdateAt)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.UserId).HasComment("用户Id");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_DiamondList>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__T_User_D__3214EC07EF4BDC87");

            entity.ToTable(tb => tb.HasComment("资产收入、支出表"));

            entity.Property(e => e.Consume)
                .HasComment("金额变化")
                .HasColumnType("decimal(18, 0)");
            entity.Property(e => e.ConsumeType).HasComment("收入还是支出");
            entity.Property(e => e.CreateAt)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.CurrencyType).HasComment("货币类型");
            entity.Property(e => e.Extend)
                .HasMaxLength(255)
                .HasComment("扩展字段");
            entity.Property(e => e.OrderCode)
                .HasMaxLength(64)
                .HasComment("订单编号");
            entity.Property(e => e.Title)
                .HasMaxLength(255)
                .HasComment("标题");
            entity.Property(e => e.UpdateAt)
                .HasComment("结束时间")
                .HasColumnType("datetime");
            entity.Property(e => e.UserId).HasComment("用户Id");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_GameFavorite>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_T_USER_FAVORITE");

            entity.ToTable(tb => tb.HasComment("我的游戏收藏"));

            entity.HasIndex(e => e.UserId, "UserId");

            entity.Property(e => e.Id).HasComment("主键");
            entity.Property(e => e.Desc)
                .HasMaxLength(50)
                .HasComment("备注")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.FavoriteTime)
                .HasComment("收藏时间")
                .HasColumnType("datetime");
            entity.Property(e => e.GameId)
                .HasMaxLength(100)
                .HasComment("游戏Id")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.TenantId).HasComment("租户");
            entity.Property(e => e.UserId).HasComment("用户Id");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_IntentOrder>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__T_User_I__3214EC07D27A8CE9");

            entity.ToTable(tb => tb.HasComment("意向订单表"));

            entity.Property(e => e.Id).HasComment("主键");
            entity.Property(e => e.Channel)
                .HasMaxLength(10)
                .HasComment("渠道号");
            entity.Property(e => e.CreatedAt)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.CreatedDay).HasComment("创建天");
            entity.Property(e => e.Method)
                .HasMaxLength(10)
                .HasComment("支付方式")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.Notes)
                .HasMaxLength(200)
                .HasComment("备注")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.OrderId)
                .HasMaxLength(64)
                .HasComment("订单Id")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.Price)
                .HasComment("价格")
                .HasColumnType("money");
            entity.Property(e => e.ProductId)
                .HasMaxLength(50)
                .HasComment("产品id")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.Quantity).HasComment("数量");
            entity.Property(e => e.Status).HasComment("状态");
            entity.Property(e => e.TenantId).HasComment("租户");
            entity.Property(e => e.UpdatedAt)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.UserId).HasComment("用户Id");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_LimitActionLog>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_T_USER_LIMITACTIONLOG");

            entity.ToTable(tb => tb.HasComment("用户设备限制行为日志表"));

            entity.Property(e => e.Id).HasComment("自增");
            entity.Property(e => e.ActionId)
                .HasMaxLength(100)
                .HasComment("行为参数")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.ActionType).HasComment("行为类型1新人礼包，2新人第二天登录礼包，3实名认证奖励");
            entity.Property(e => e.CreateTime)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.CreateTimeDay).HasComment("创建时间，天");
            entity.Property(e => e.DeviceNumber)
                .HasMaxLength(100)
                .HasComment("设备号");
            entity.Property(e => e.Extend1)
                .HasMaxLength(200)
                .HasComment("扩展字段")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.Ip)
                .HasMaxLength(100)
                .HasComment("请求Ip")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.UserId).HasComment("用户Id");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_MiniProgram_Account>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__T_User_M__3214EC073889A8B9");

            entity.ToTable(tb => tb.HasComment("小程序登录表"));

            entity.Property(e => e.Id).HasComment("主键");
            entity.Property(e => e.CreateAt)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.OpenId)
                .HasMaxLength(200)
                .HasComment("用户唯一标识")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.SessionKey)
                .HasMaxLength(200)
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.TenantId).HasComment("租户");
            entity.Property(e => e.Unionid)
                .HasMaxLength(200)
                .HasComment("用户在开放平台的唯一标识符，若当前小程序已绑定到微信开放平台账号下会返回，详见")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.UpdateAt)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.UserId).HasComment("用户Id");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_Order>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__T_Order__3214EC07C8DD7EE1");

            entity.ToTable(tb => tb.HasComment("订单完成表"));

            entity.Property(e => e.Channel)
                .HasMaxLength(10)
                .HasComment("渠道");
            entity.Property(e => e.CreatedAt)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.OrderDate)
                .HasComment("订单创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.OrderId)
                .HasMaxLength(64)
                .HasComment("订单编号")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.PaymentDate)
                .HasComment("订单支付时间")
                .HasColumnType("datetime");
            entity.Property(e => e.PaymentDay).HasComment("订单创建天");
            entity.Property(e => e.PaymentMethod)
                .HasMaxLength(10)
                .HasComment("订单支付方式")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.ProductId)
                .HasMaxLength(100)
                .HasComment("购买的产品Id")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.Status).HasComment("订单状态");
            entity.Property(e => e.TenantId).HasComment("租户");
            entity.Property(e => e.TotalPrice)
                .HasComment("价格")
                .HasColumnType("money");
            entity.Property(e => e.UpdatedAt)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.UserId).HasComment("用户Id");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_OrderItems>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__T_OrderI__3214EC077E53EC22");

            entity.ToTable(tb => tb.HasComment("订单详情表"));

            entity.Property(e => e.OrderId)
                .HasMaxLength(64)
                .HasComment("订单id")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.PayUrl)
                .HasComment("支付地址")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.PaymentInfo)
                .HasComment("支付信息")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.Product).HasComment("产品id、主键");
            entity.Property(e => e.ProductId)
                .HasMaxLength(100)
                .HasComment("产品id")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.RewardInfo)
                .HasComment("发放奖励信息")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.RewardTips)
                .HasComment("发放奖励提示")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.TenantId).HasComment("租户");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_Phone_Account>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__T_User_P__3214EC07987BDDB2");

            entity.ToTable(tb => tb.HasComment("手机号登录表"));

            entity.Property(e => e.Id).HasComment("主键");
            entity.Property(e => e.CreatedAt)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.IsLogout).HasComment("是否注销");
            entity.Property(e => e.NikeName)
                .HasMaxLength(100)
                .HasComment("用户昵称")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.PhoneNum)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("手机号")
                .UseCollation("Chinese_PRC_CI_AS");
            entity.Property(e => e.TenantId).HasComment("租户Id");
            entity.Property(e => e.UpdatedAt)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.UserId).HasComment("用户Id");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        modelBuilder.Entity<T_User_Token>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK__T_User_T__3214EC072DF12976");

            entity.ToTable(tb => tb.HasComment("用户单点登录表"));

            entity.Property(e => e.CreateAt)
                .HasComment("创建时间")
                .HasColumnType("datetime");
            entity.Property(e => e.DeviceNumber)
                .HasMaxLength(100)
                .HasComment("设备号");
            entity.Property(e => e.ExpiresAt)
                .HasComment("过期时间")
                .HasColumnType("datetime");
            entity.Property(e => e.LastLoginAt)
                .HasComment("最后一次登录时间")
                .HasColumnType("datetime");
            entity.Property(e => e.TenantId).HasComment("租户");
            entity.Property(e => e.Token).HasComment("登录token");
            entity.Property(e => e.TokenMd5)
                .HasMaxLength(64)
                .HasComment("tokenMd5值");
            entity.Property(e => e.UpdateAt)
                .HasComment("修改时间")
                .HasColumnType("datetime");
            entity.Property(e => e.UserId).HasComment("用户Id");
            //添加全局筛选器
            if (this.TenantInfo != null)
            {
                entity.HasQueryFilter(it => it.TenantId == this.TenantInfo.TenantId);
            }
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
