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

namespace BLW_Log.PGModels;

public partial class PostgresContext : DbContext
{
    public PostgresContext()
    {
    }

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

    public virtual DbSet<DevMonitorlog> DevMonitorlogs { get; set; }

    public virtual DbSet<Excelgenerater> Excelgeneraters { get; set; }

    public virtual DbSet<IotMonitorlog> IotMonitorlogs { get; set; }

    public virtual DbSet<Recordhotel> Recordhotels { get; set; }

    public virtual DbSet<StatisticsTotal> StatisticsTotals { get; set; }

    public virtual DbSet<WebapiMonitorlog> WebapiMonitorlogs { get; set; }

    //protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    //{
    //    //if (!optionsBuilder.IsConfigured)
    //    //{
    //    //    var configuration = new ConfigurationBuilder()
    //    //        .SetBasePath(Directory.GetCurrentDirectory())
    //    //        .AddJsonFile("appsettings.json")
    //    //        .Build();
    //    //    optionsBuilder.UseNpgsql(configuration.GetConnectionString("DefaultConnection"));
    //    //}
    //    //optionsBuilder.UseNpgsql("Server=10.8.8.212;Database=postgres;user id=postgres;password=123456;port=16035;");
    //}

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

            entity.ToTable("dev_monitorlog");

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

            entity.HasIndex(e => e.CreateTimeToUnixTime, "CreateTime").IsDescending();

            entity.HasIndex(e => new { e.HotelCode, e.HostNumber, e.HostId, e.RoomNo }, "MAC");

            entity.HasIndex(e => e.Mac, "MM");

            entity.HasIndex(e => e.CreateTime, "T");

            entity.Property(e => e.Id)
                .UseIdentityAlwaysColumn()
                .HasColumnName("ID");
            entity.Property(e => e.CommandType).HasMaxLength(128);
            entity.Property(e => e.CreateTime).HasColumnType("timestamp(6) without time zone");
            entity.Property(e => e.HostId).HasColumnName("HostID");
            entity.Property(e => e.HostNumber).HasMaxLength(64);
            entity.Property(e => e.HotelCode).HasMaxLength(64);
            entity.Property(e => e.HotelId).HasColumnName("HotelID");
            entity.Property(e => e.LanIp)
                .HasMaxLength(64)
                .HasColumnName("LanIP");
            entity.Property(e => e.Mac)
                .HasMaxLength(64)
                .HasColumnName("MAC");
            entity.Property(e => e.RoomNo).HasMaxLength(64);
            entity.Property(e => e.SendOrReceive).HasMaxLength(64);
            entity.Property(e => e.WwwIp)
                .HasMaxLength(64)
                .HasColumnName("WWW_IP");
            entity.Property(e => e.WwwPort).HasColumnName("WWW_Port");
        });

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

            entity.ToTable("excelgenerater");

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.CreateTime).HasColumnType("timestamp(6) without time zone");
            entity.Property(e => e.CreateTimeUnix).HasColumnName("CreateTime_UNIX");
        });

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

            entity.ToTable("iot_monitorlog");

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.HotelCode).HasMaxLength(255);
            entity.Property(e => e.HotelName).HasMaxLength(255);
            entity.Property(e => e.Platform).HasMaxLength(128);
            entity.Property(e => e.RequestId).HasMaxLength(512);
            entity.Property(e => e.RoomNumber).HasMaxLength(255);
            entity.Property(e => e.TriggerTime).HasMaxLength(64);
        });

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

            entity.ToTable("recordhotel");

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.CreateTime).HasMaxLength(64);
            entity.Property(e => e.HotelId).HasColumnName("HotelID");
        });

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

            entity.ToTable("statistics_total");

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.HostNumber).HasMaxLength(64);
            entity.Property(e => e.HotelCode).HasMaxLength(64);
            entity.Property(e => e.Mac)
                .HasMaxLength(64)
                .HasColumnName("MAC");
            entity.Property(e => e.RxCount).HasColumnName("RX_Count");
            entity.Property(e => e.TxCount).HasColumnName("TX_Count");
            entity.Property(e => e.UpdateTime)
                .HasMaxLength(64)
                .HasColumnName("Update_Time");
        });

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

            entity.ToTable("webapi_monitorlog");

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

            entity.HasIndex(e => new { e.InvokStartTime, e.InvokEndTime }, "Time");

            entity.Property(e => e.Id).HasColumnName("ID");
            entity.Property(e => e.HotelCode).HasMaxLength(64);
            entity.Property(e => e.InvokEndTime)
                .HasMaxLength(64)
                .HasColumnName("InvokEnd_Time");
            entity.Property(e => e.InvokStartTime)
                .HasMaxLength(64)
                .HasColumnName("InvokStart_Time");
            entity.Property(e => e.MethodName).HasMaxLength(128);
            entity.Property(e => e.RemoteIp)
                .HasMaxLength(64)
                .HasColumnName("RemoteIP");
            entity.Property(e => e.RoomNumber).HasMaxLength(64);
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
