using System;
using System.Collections.Generic;
using EVCB_OCPP.Domain.Models.MainDb;
using Microsoft.EntityFrameworkCore;

namespace EVCB_OCPP.Domain;

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

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

    public virtual DbSet<ConnectorMeterValueRecord> ConnectorMeterValueRecords { get; set; }

    public virtual DbSet<ConnectorStatus> ConnectorStatuses { get; set; }

    public virtual DbSet<Customer> Customers { get; set; }

    public virtual DbSet<LoadingBalance> LoadingBalances { get; set; }

    public virtual DbSet<Machine> Machines { get; set; }

    public virtual DbSet<MachineConfiguration> MachineConfigurations { get; set; }

    public virtual DbSet<MachineError> MachineErrors { get; set; }

    public virtual DbSet<MachineOperateRecord> MachineOperateRecords { get; set; }

    public virtual DbSet<MachineVersionFile> MachineVersionFiles { get; set; }

    public virtual DbSet<MigrationHistory> MigrationHistories { get; set; }

    public virtual DbSet<Ocmf> Ocmfs { get; set; }

    public virtual DbSet<ServerMessage> ServerMessages { get; set; }

    public virtual DbSet<TransactionRecord> TransactionRecords { get; set; }

    public virtual DbSet<UploadFile> UploadFiles { get; set; }

    public virtual DbSet<VConnectorStatus> VConnectorStatuses { get; set; }

    public virtual DbSet<VConnectorStatusCombind> VConnectorStatusCombinds { get; set; }

    public virtual DbSet<VMachine> VMachines { get; set; }

    public virtual DbSet<VMachineCombind> VMachineCombinds { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.UseCollation("Chinese_Taiwan_Stroke_CI_AS");

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

            entity.ToTable("ConnectorMeterValueRecord");

            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.Value).HasMaxLength(10);
        });

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

            entity.ToTable("ConnectorStatus");

            entity.Property(e => e.Id).HasMaxLength(36);
            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.ErrorInfo).HasMaxLength(50);
            entity.Property(e => e.TotalEnergy).HasColumnType("decimal(10, 2)");
            entity.Property(e => e.VendorErrorCode).HasMaxLength(100);
            entity.Property(e => e.VendorId).HasMaxLength(255);
        });

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

            entity.ToTable("Customer");

            entity.Property(e => e.Id).ValueGeneratedNever();
            entity.Property(e => e.ApiCustomerId).HasMaxLength(36);
            entity.Property(e => e.ApiKey).HasMaxLength(128);
            entity.Property(e => e.ApiKeyUpdatedOn).HasColumnType("datetime");
            entity.Property(e => e.ApiUrl).HasMaxLength(256);
            entity.Property(e => e.CreatedBy).HasMaxLength(50);
            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.Deadline).HasColumnType("datetime");
            entity.Property(e => e.EnableTtia).HasColumnName("EnableTTIA");
            entity.Property(e => e.Ftphost)
                .HasMaxLength(50)
                .HasColumnName("FTPHost");
            entity.Property(e => e.Ftppassword)
                .HasMaxLength(20)
                .HasColumnName("FTPPassword");
            entity.Property(e => e.Ftppath).HasColumnName("FTPPath");
            entity.Property(e => e.Ftpuser)
                .HasMaxLength(20)
                .HasColumnName("FTPUser");
            entity.Property(e => e.Name).HasMaxLength(50);
            entity.Property(e => e.PartnerId).HasMaxLength(36);
            entity.Property(e => e.TtiaApikey)
                .HasMaxLength(12)
                .HasColumnName("TTIA_APIKey");
            entity.Property(e => e.TtiaApiurl)
                .HasMaxLength(110)
                .HasColumnName("TTIA_APIUrl");
            entity.Property(e => e.TtiaCustomerId).HasColumnName("TTIA_CustomerId");
            entity.Property(e => e.TtiaEquipmentProvider)
                .HasMaxLength(10)
                .HasColumnName("TTIA_EquipmentProvider");
            entity.Property(e => e.UpdatedBy).HasMaxLength(50);
            entity.Property(e => e.UpdatedOn).HasColumnType("datetime");
        });

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

            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.FinishedOn).HasColumnType("datetime");
            entity.Property(e => e.MachineId)
                .IsRequired()
                .HasMaxLength(36);
            entity.Property(e => e.Power).HasColumnType("decimal(10, 2)");
        });

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

            entity.ToTable("Machine");

            entity.Property(e => e.Id).HasMaxLength(36);
            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.ChargeBoxSerialNumber).HasMaxLength(25);
            entity.Property(e => e.ChargePointModel).HasMaxLength(20);
            entity.Property(e => e.ChargePointSerialNumber).HasMaxLength(25);
            entity.Property(e => e.ChargePointVendor).HasMaxLength(20);
            entity.Property(e => e.Comment).HasMaxLength(100);
            entity.Property(e => e.ConnectorPowerType).HasMaxLength(50);
            entity.Property(e => e.ConnectorType).HasMaxLength(50);
            entity.Property(e => e.CreatedBy).HasMaxLength(50);
            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.FwAssignedVersion).HasColumnName("FW_AssignedVersion");
            entity.Property(e => e.FwCurrentVersion)
                .HasMaxLength(50)
                .HasColumnName("FW_CurrentVersion");
            entity.Property(e => e.FwVersionReport).HasColumnName("FW_VersionReport");
            entity.Property(e => e.HeartbeatUpdatedOn).HasColumnType("datetime");
            entity.Property(e => e.Iccid).HasMaxLength(20);
            entity.Property(e => e.Imsi).HasMaxLength(20);
            entity.Property(e => e.Latitude).HasColumnType("decimal(10, 6)");
            entity.Property(e => e.Longitude).HasColumnType("decimal(10, 6)");
            entity.Property(e => e.MeterSerialNumber).HasMaxLength(25);
            entity.Property(e => e.MeterType).HasMaxLength(25);
            entity.Property(e => e.ModelName)
                .IsRequired()
                .HasMaxLength(50)
                .HasDefaultValueSql("('')");
            entity.Property(e => e.OfflineOn).HasColumnType("datetime");
            entity.Property(e => e.RatedPower).HasColumnType("decimal(6, 2)");
            entity.Property(e => e.Ttiatag).HasColumnName("TTIATag");
            entity.Property(e => e.VendorId)
                .HasMaxLength(50)
                .HasDefaultValueSql("('Zerova')");

            entity.HasOne(d => d.Customer).WithMany(p => p.Machines)
                .HasForeignKey(d => d.CustomerId)
                .HasConstraintName("FK_dbo.Machine_dbo.Customer_CustomerId");
        });

        modelBuilder.Entity<MachineConfiguration>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_dbo.MachineConfigurations");

            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.ConfigureName).HasMaxLength(50);
            entity.Property(e => e.ConfigureSetting).HasMaxLength(500);
        });

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

            entity.ToTable("MachineError");

            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.ErrorInfo).HasMaxLength(50);
            entity.Property(e => e.VendorErrorCode).HasMaxLength(100);
            entity.Property(e => e.VendorId).HasMaxLength(255);
        });

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

            entity.ToTable("MachineOperateRecord");

            entity.Property(e => e.Action).HasMaxLength(30);
            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.EvseStatus).HasColumnName("EVSE_Status");
            entity.Property(e => e.EvseValue).HasColumnName("EVSE_Value");
            entity.Property(e => e.FinishedOn).HasColumnType("datetime");
            entity.Property(e => e.ReportedOn).HasColumnType("datetime");
            entity.Property(e => e.SerialNo).HasMaxLength(36);
        });

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

            entity.ToTable("MachineVersionFile");

            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.UploadFileId)
                .IsRequired()
                .HasMaxLength(36);

            entity.HasOne(d => d.UploadFile).WithMany(p => p.MachineVersionFiles)
                .HasForeignKey(d => d.UploadFileId)
                .HasConstraintName("FK_dbo.MachineVersionFile_dbo.UploadFile_UploadFileId");
        });

        modelBuilder.Entity<MigrationHistory>(entity =>
        {
            entity.HasKey(e => new { e.MigrationId, e.ContextKey }).HasName("PK_dbo.__MigrationHistory");

            entity.ToTable("__MigrationHistory");

            entity.Property(e => e.MigrationId).HasMaxLength(150);
            entity.Property(e => e.ContextKey).HasMaxLength(300);
            entity.Property(e => e.Model).IsRequired();
            entity.Property(e => e.ProductVersion)
                .IsRequired()
                .HasMaxLength(32);
        });

        modelBuilder.Entity<Ocmf>(entity =>
        {
            entity.HasKey(e => e.Id).HasName("PK_dbo.OCMF");

            entity.ToTable("OCMF");

            entity.Property(e => e.DataString).HasMaxLength(2048);
            entity.Property(e => e.PublicKey).HasMaxLength(256);
        });

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

            entity.ToTable("ServerMessage");

            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.CreatedBy).HasMaxLength(36);
            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.OutAction).HasMaxLength(30);
            entity.Property(e => e.ReceivedOn).HasColumnType("datetime");
            entity.Property(e => e.SerialNo).HasMaxLength(36);
            entity.Property(e => e.UpdatedOn).HasColumnType("datetime");
        });

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

            entity.ToTable("TransactionRecord");

            entity.Property(e => e.ChargeBoxId)
                .IsRequired()
                .HasMaxLength(50);
            entity.Property(e => e.Cost).HasColumnType("decimal(18, 2)");
            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.Fee).HasMaxLength(1500);
            entity.Property(e => e.MeterStart).HasColumnType("decimal(18, 2)");
            entity.Property(e => e.MeterStop).HasColumnType("decimal(18, 2)");
            entity.Property(e => e.Receipt).HasMaxLength(3000);
            entity.Property(e => e.StartIdTag).HasMaxLength(20);
            entity.Property(e => e.StartSoc)
                .HasMaxLength(3)
                .HasColumnName("StartSOC");
            entity.Property(e => e.StartTime).HasColumnType("datetime");
            entity.Property(e => e.StartTransactionReportedOn).HasColumnType("datetime");
            entity.Property(e => e.StopIdTag).HasMaxLength(20);
            entity.Property(e => e.StopReason).HasMaxLength(60);
            entity.Property(e => e.StopSoc)
                .HasMaxLength(3)
                .HasColumnName("StopSOC");
            entity.Property(e => e.StopTime).HasColumnType("datetime");
            entity.Property(e => e.StopTransactionReportedOn).HasColumnType("datetime");
            entity.Property(e => e.UpdatedOn).HasColumnType("datetime");
            entity.Property(e => e.UploadedtoTtia).HasColumnName("UploadedtoTTIA");
        });

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

            entity.ToTable("UploadFile");

            entity.Property(e => e.Id).HasMaxLength(36);
            entity.Property(e => e.CreatedBy).HasMaxLength(50);
            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.FileExtensionName).HasMaxLength(50);
            entity.Property(e => e.FileMd5)
                .HasMaxLength(50)
                .HasColumnName("FileMD5");
            entity.Property(e => e.FileName)
                .IsRequired()
                .HasMaxLength(500);
            entity.Property(e => e.FilePath)
                .IsRequired()
                .HasMaxLength(500);
            entity.Property(e => e.FileType).HasMaxLength(200);
            entity.Property(e => e.FileUrl).HasMaxLength(512);
            entity.Property(e => e.ModelName)
                .IsRequired()
                .HasMaxLength(50);
            entity.Property(e => e.OriginName)
                .IsRequired()
                .HasMaxLength(500);
            entity.Property(e => e.VendorId)
                .IsRequired()
                .HasMaxLength(50);
        });

        modelBuilder.Entity<VConnectorStatus>(entity =>
        {
            entity
                .HasNoKey()
                .ToView("vConnectorStatus");

            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.CreatedOn).HasColumnType("datetime");
            entity.Property(e => e.ErrorInfo).HasMaxLength(50);
            entity.Property(e => e.Id)
                .IsRequired()
                .HasMaxLength(36);
            entity.Property(e => e.TotalEnergy).HasColumnType("decimal(10, 2)");
            entity.Property(e => e.VendorErrorCode).HasMaxLength(100);
            entity.Property(e => e.VendorId).HasMaxLength(255);
        });

        modelBuilder.Entity<VConnectorStatusCombind>(entity =>
        {
            entity
                .HasNoKey()
                .ToView("vConnectorStatusCombind");

            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.Ocpp)
                .IsRequired()
                .HasMaxLength(3)
                .IsUnicode(false)
                .HasColumnName("OCPP");
            entity.Property(e => e.TotalEnergy).HasColumnType("decimal(10, 2)");
            entity.Property(e => e.VendorErrorCode).HasMaxLength(100);
        });

        modelBuilder.Entity<VMachine>(entity =>
        {
            entity
                .HasNoKey()
                .ToView("vMachine");

            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.ConnectorType).HasMaxLength(50);
            entity.Property(e => e.HeartbeatUpdatedOn).HasColumnType("datetime");
            entity.Property(e => e.Id)
                .IsRequired()
                .HasMaxLength(36);
            entity.Property(e => e.ModelName)
                .IsRequired()
                .HasMaxLength(50);
            entity.Property(e => e.OfflineOn).HasColumnType("datetime");
            entity.Property(e => e.RatedPower).HasColumnType("decimal(6, 2)");
            entity.Property(e => e.Ttiatag).HasColumnName("TTIATag");
            entity.Property(e => e.VendorId).HasMaxLength(50);
        });

        modelBuilder.Entity<VMachineCombind>(entity =>
        {
            entity
                .HasNoKey()
                .ToView("vMachineCombind");

            entity.Property(e => e.ChargeBoxId).HasMaxLength(50);
            entity.Property(e => e.ConnectorType).HasMaxLength(50);
            entity.Property(e => e.HeartbeatUpdatedOn).HasColumnType("datetime");
            entity.Property(e => e.Id)
                .IsRequired()
                .HasMaxLength(36);
            entity.Property(e => e.ModelName)
                .IsRequired()
                .HasMaxLength(50);
            entity.Property(e => e.Ocpp)
                .IsRequired()
                .HasMaxLength(3)
                .IsUnicode(false)
                .HasColumnName("OCPP");
            entity.Property(e => e.OfflineOn).HasColumnType("datetime");
            entity.Property(e => e.RatedPower).HasColumnType("decimal(6, 2)");
            entity.Property(e => e.Ttiatag).HasColumnName("TTIATag");
            entity.Property(e => e.VendorId).HasMaxLength(50);
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
