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

namespace CouponReport.Models.Parkingeyes;

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

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

    public virtual DbSet<AggregatedCounter> AggregatedCounters { get; set; }

    public virtual DbSet<AlertLpr> AlertLprs { get; set; }

    public virtual DbSet<AlertSetting> AlertSettings { get; set; }

    public virtual DbSet<Camera> Cameras { get; set; }

    public virtual DbSet<CarEnter> CarEnters { get; set; }

    public virtual DbSet<CarIdentityCounter> CarIdentityCounters { get; set; }

    public virtual DbSet<ChargingBill> ChargingBills { get; set; }

    public virtual DbSet<ChargingBillDetail> ChargingBillDetails { get; set; }

    public virtual DbSet<ChargingBillSession> ChargingBillSessions { get; set; }

    public virtual DbSet<ChargingPile> ChargingPiles { get; set; }

    public virtual DbSet<ChargingSession> ChargingSessions { get; set; }

    public virtual DbSet<CommonQueue> CommonQueues { get; set; }

    public virtual DbSet<Counter> Counters { get; set; }

    public virtual DbSet<Division> Divisions { get; set; }

    public virtual DbSet<DivisionDisplay> DivisionDisplays { get; set; }

    public virtual DbSet<EventLog> EventLogs { get; set; }

    public virtual DbSet<Hash> Hashes { get; set; }

    public virtual DbSet<Job> Jobs { get; set; }

    public virtual DbSet<JobParameter> JobParameters { get; set; }

    public virtual DbSet<JobQueue> JobQueues { get; set; }

    public virtual DbSet<List> Lists { get; set; }

    public virtual DbSet<MergedCarEnter> MergedCarEnters { get; set; }

    public virtual DbSet<ParkingColumn> ParkingColumns { get; set; }

    public virtual DbSet<ParkingLot> ParkingLots { get; set; }

    public virtual DbSet<ParkingStationExtendSetting> ParkingStationExtendSettings { get; set; }

    public virtual DbSet<PaymentDevice> PaymentDevices { get; set; }

    public virtual DbSet<PendingCarRecord> PendingCarRecords { get; set; }

    public virtual DbSet<RoadsideQueue> RoadsideQueues { get; set; }

    public virtual DbSet<RoadsideSignRecord> RoadsideSignRecords { get; set; }

    public virtual DbSet<RoadsideTicket> RoadsideTickets { get; set; }

    public virtual DbSet<Schema> Schemas { get; set; }

    public virtual DbSet<Server> Servers { get; set; }

    public virtual DbSet<Set> Sets { get; set; }

    public virtual DbSet<State> States { get; set; }

    public virtual DbSet<TypeDef> TypeDefs { get; set; }

    protected override void OnModelCreating(ModelBuilder modelBuilder)
    {
        modelBuilder.Entity<AggregatedCounter>(entity =>
        {
            entity.HasKey(e => e.Key).HasName("PK_HangFire_CounterAggregated");

            entity.ToTable("AggregatedCounter", "HangFire");

            entity.HasIndex(e => e.ExpireAt, "IX_HangFire_AggregatedCounter_ExpireAt").HasFilter("([ExpireAt] IS NOT NULL)");

            entity.Property(e => e.Key).HasMaxLength(100);
            entity.Property(e => e.ExpireAt).HasColumnType("datetime");
        });

        modelBuilder.Entity<AlertLpr>(entity =>
        {
            entity.HasKey(e => e.LprId);

            entity.ToTable("AlertLpr");

            entity.Property(e => e.LprId)
                .HasMaxLength(40)
                .HasComment("車牌序號");
            entity.Property(e => e.AlertId)
                .HasMaxLength(40)
                .HasComment("通知編號");
            entity.Property(e => e.LprNo)
                .HasMaxLength(30)
                .HasDefaultValue(",,,")
                .HasComment("車牌號碼,以\",\"分開");
            entity.Property(e => e.LprNo2)
                .HasMaxLength(4000)
                .HasComputedColumnSql("(replace([LprNo],'''',''))", false)
                .HasComment("運算欄位,無逗號的車牌");

            entity.HasOne(d => d.Alert).WithMany(p => p.AlertLprs)
                .HasForeignKey(d => d.AlertId)
                .HasConstraintName("FK_AlertLpr_AlertSetting");
        });

        modelBuilder.Entity<AlertSetting>(entity =>
        {
            entity.HasKey(e => e.AlertId);

            entity.ToTable("AlertSetting");

            entity.Property(e => e.AlertId)
                .HasMaxLength(40)
                .HasComment("通知編號");
            entity.Property(e => e.AlertName)
                .HasMaxLength(20)
                .HasDefaultValue("")
                .HasComment("名稱");
            entity.Property(e => e.Enbale)
                .HasMaxLength(1)
                .IsUnicode(false)
                .HasDefaultValue("N")
                .IsFixedLength()
                .HasComment("啟動");
            entity.Property(e => e.GroupBy)
                .HasDefaultValue(1)
                .HasComment("類型 1,依照車格 2 依照車號");
            entity.Property(e => e.Inbound)
                .HasMaxLength(1)
                .IsUnicode(false)
                .HasDefaultValue("N")
                .IsFixedLength()
                .HasComment("進場警示");
            entity.Property(e => e.Message)
                .HasMaxLength(500)
                .HasDefaultValue("")
                .HasComment("通知訊息");
            entity.Property(e => e.Outbound)
                .HasMaxLength(1)
                .IsUnicode(false)
                .HasDefaultValue("N")
                .IsFixedLength()
                .HasComment("出場警示");

            entity.HasMany(d => d.Lots).WithMany(p => p.Alerts)
                .UsingEntity<Dictionary<string, object>>(
                    "AlertParkingLot",
                    r => r.HasOne<ParkingLot>().WithMany()
                        .HasForeignKey("LotId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("FK_AlertParkingLots_ParkingLot"),
                    l => l.HasOne<AlertSetting>().WithMany()
                        .HasForeignKey("AlertId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("FK_AlertParkingLots_AlertSetting"),
                    j =>
                    {
                        j.HasKey("AlertId", "LotId");
                        j.ToTable("AlertParkingLots");
                        j.IndexerProperty<string>("AlertId").HasMaxLength(40);
                        j.IndexerProperty<string>("LotId").HasMaxLength(40);
                    });
        });

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

            entity.Property(e => e.CameraId)
                .HasMaxLength(40)
                .HasComment("攝影機序號");
            entity.Property(e => e.AiLocation)
                .HasMaxLength(150)
                .HasDefaultValue("")
                .HasComment("AI的IP，暫時為背景寫入值");
            entity.Property(e => e.CameraTypeId)
                .HasDefaultValue(1)
                .HasComment("種類");
            entity.Property(e => e.Enable)
                .HasMaxLength(1)
                .IsUnicode(false)
                .HasDefaultValue("N")
                .IsFixedLength()
                .HasComment("啟用否");
            entity.Property(e => e.Ip)
                .HasMaxLength(150)
                .HasComment("IP")
                .HasColumnName("IP");

            entity.HasOne(d => d.CameraType).WithMany(p => p.Cameras)
                .HasForeignKey(d => d.CameraTypeId)
                .HasConstraintName("FK_Camera_TypeDef");
        });

        modelBuilder.Entity<CarEnter>(entity =>
        {
            entity.HasKey(e => e.SerialNo);

            entity.ToTable("CarEnter");

            entity.Property(e => e.SerialNo)
                .HasMaxLength(50)
                .IsUnicode(false);
            entity.Property(e => e.CarIdentity).HasDefaultValue(1);
            entity.Property(e => e.CarNo).HasMaxLength(30);
            entity.Property(e => e.CarNoSimple)
                .HasMaxLength(30)
                .IsUnicode(false);
            entity.Property(e => e.CarType)
                .HasMaxLength(1)
                .IsUnicode(false);
            entity.Property(e => e.CreateFromCloud).HasComment("從雲端建立資料");
            entity.Property(e => e.CreationDate).HasColumnType("datetime");
            entity.Property(e => e.DataHandleType).HasComment("資料處理的方式(0:一般, 1:程式處理)");
            entity.Property(e => e.DepartureDateTime).HasColumnType("datetime");
            entity.Property(e => e.DepartureLaneNo)
                .HasMaxLength(20)
                .IsUnicode(false);
            entity.Property(e => e.DeparturePhotoPath)
                .HasMaxLength(255)
                .IsUnicode(false);
            entity.Property(e => e.DeparturePhotoUrlPath).IsUnicode(false);
            entity.Property(e => e.DepartureSourceDeviceId)
                .HasMaxLength(30)
                .IsUnicode(false);
            entity.Property(e => e.EnterDateTime).HasColumnType("datetime");
            entity.Property(e => e.EnterPhotoPath)
                .HasMaxLength(255)
                .IsUnicode(false);
            entity.Property(e => e.EnterPhotoUrlPath).IsUnicode(false);
            entity.Property(e => e.Etag)
                .HasMaxLength(30)
                .IsUnicode(false);
            entity.Property(e => e.GridNumber)
                .HasMaxLength(6)
                .IsUnicode(false);
            entity.Property(e => e.LaneNo)
                .HasMaxLength(20)
                .IsUnicode(false);
            entity.Property(e => e.LimitedTimeDeparture).HasColumnType("datetime");
            entity.Property(e => e.OriginalDepartureDateTime).HasColumnType("datetime");
            entity.Property(e => e.PayDateTime).HasColumnType("datetime");
            entity.Property(e => e.PayDeviceId)
                .HasMaxLength(30)
                .IsUnicode(false);
            entity.Property(e => e.PayType)
                .HasMaxLength(30)
                .IsUnicode(false);
            entity.Property(e => e.Remark)
                .HasMaxLength(255)
                .IsUnicode(false);
            entity.Property(e => e.SourceDeviceId)
                .HasMaxLength(30)
                .IsUnicode(false);
            entity.Property(e => e.StationId)
                .HasMaxLength(10)
                .IsUnicode(false);
            entity.Property(e => e.UpdateDate).HasColumnType("datetime");
            entity.Property(e => e.ValuationDateTime).HasColumnType("datetime");
        });

        modelBuilder.Entity<CarIdentityCounter>(entity =>
        {
            entity.HasKey(e => new { e.StationId, e.CounterId }).HasName("PK_Counter");

            entity.ToTable("CarIdentityCounter");

            entity.Property(e => e.StationId)
                .HasMaxLength(10)
                .IsUnicode(false);
            entity.Property(e => e.CounterId)
                .HasMaxLength(10)
                .IsUnicode(false);
            entity.Property(e => e.AdamIp)
                .HasMaxLength(150)
                .IsUnicode(false)
                .HasColumnName("AdamIP");
            entity.Property(e => e.CounterName)
                .HasMaxLength(50)
                .IsUnicode(false);
            entity.Property(e => e.CounterType)
                .HasMaxLength(10)
                .IsUnicode(false);
            entity.Property(e => e.DisplayType).HasComment("顯示類別");
            entity.Property(e => e.Enable).HasDefaultValue(true);
            entity.Property(e => e.ReservedQty).HasColumnType("decimal(5, 0)");
            entity.Property(e => e.ScheduleSet).HasComment("預先設定要等排程處理的Flag");
            entity.Property(e => e.Setting888)
                .HasMaxLength(500)
                .IsUnicode(false);
            entity.Property(e => e.TotalQty).HasColumnType("decimal(5, 0)");
            entity.Property(e => e.UsedQty).HasColumnType("decimal(5, 0)");
        });

        modelBuilder.Entity<ChargingBill>(entity =>
        {
            entity.HasKey(e => e.BillingNo);

            entity.ToTable("ChargingBill");

            entity.Property(e => e.BillingNo)
                .ValueGeneratedNever()
                .HasComment("帳單編號");
            entity.Property(e => e.CarNo).HasMaxLength(30);
            entity.Property(e => e.CenterSerialNo)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("中控進場序號");
            entity.Property(e => e.CreationDate).HasColumnType("datetime");
            entity.Property(e => e.LimitedTimeDeparture).HasColumnType("datetime");
            entity.Property(e => e.PaidDateTime)
                .HasComment("付款時間")
                .HasColumnType("datetime");
            entity.Property(e => e.PayDeviceId)
                .HasMaxLength(100)
                .IsUnicode(false)
                .HasComment("繳費裝置");
            entity.Property(e => e.TotalAmount)
                .HasComment("金額")
                .HasColumnType("decimal(5, 2)");
            entity.Property(e => e.UpdateDate).HasColumnType("datetime");
            entity.Property(e => e.ValuationDateTime).HasColumnType("datetime");
        });

        modelBuilder.Entity<ChargingBillDetail>(entity =>
        {
            entity.HasKey(e => new { e.BillingNo, e.LineNo });

            entity.Property(e => e.BillingNo).HasComment("帳單編號");
            entity.Property(e => e.LineNo).HasComment("行號");
            entity.Property(e => e.ChargingDescription)
                .HasMaxLength(50)
                .HasComment("敘述");
            entity.Property(e => e.CreationDate).HasColumnType("datetime");
            entity.Property(e => e.DetailAmount)
                .HasComment("小計")
                .HasColumnType("decimal(5, 2)");
            entity.Property(e => e.FeeType)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("收費類型");
            entity.Property(e => e.LotNo)
                .HasMaxLength(20)
                .HasComment("車格號");
            entity.Property(e => e.SumKwh).HasComment("瓦數總和");
            entity.Property(e => e.SumSec).HasComment("秒數總和");

            entity.HasOne(d => d.BillingNoNavigation).WithMany(p => p.ChargingBillDetails)
                .HasForeignKey(d => d.BillingNo)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ChargingBillDetails_ChargingBill");
        });

        modelBuilder.Entity<ChargingBillSession>(entity =>
        {
            entity.HasKey(e => new { e.BillingNo, e.SessionId });

            entity.Property(e => e.BillingNo).HasComment("帳單編號");
            entity.Property(e => e.SessionId).HasComment("充電資訊ID");
            entity.Property(e => e.CreationDate).HasColumnType("datetime");

            entity.HasOne(d => d.BillingNoNavigation).WithMany(p => p.ChargingBillSessions)
                .HasForeignKey(d => d.BillingNo)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ChargingBillSessions_ChargingBill");

            entity.HasOne(d => d.Session).WithMany(p => p.ChargingBillSessions)
                .HasForeignKey(d => d.SessionId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ChargingBillSessions_ChargingBillSessions");
        });

        modelBuilder.Entity<ChargingPile>(entity =>
        {
            entity.HasKey(e => new { e.ChargingPileId, e.SubPort });

            entity.ToTable("ChargingPile");

            entity.Property(e => e.ChargingPileId)
                .HasMaxLength(40)
                .HasComment("充電樁序號");
            entity.Property(e => e.SubPort)
                .HasMaxLength(2)
                .IsUnicode(false)
                .HasComment("槍號");
            entity.Property(e => e.CreationDate).HasColumnType("datetime");
            entity.Property(e => e.Enable)
                .HasDefaultValue(true)
                .HasComment("啟用");
            entity.Property(e => e.LotNo)
                .HasMaxLength(20)
                .HasComment("車格號");
            entity.Property(e => e.UpdateDate).HasColumnType("datetime");
        });

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

            entity.Property(e => e.Id)
                .ValueGeneratedNever()
                .HasComment("充電資訊ID");
            entity.Property(e => e.ChargeKwh).HasComment("充電瓦數");
            entity.Property(e => e.ChargeSec).HasComment("充電秒數");
            entity.Property(e => e.ChargeStatus)
                .HasMaxLength(20)
                .IsUnicode(false)
                .HasComment("充電狀態");
            entity.Property(e => e.CreationDate).HasColumnType("datetime");
            entity.Property(e => e.EndTime)
                .HasComment("結束時間")
                .HasColumnType("datetime");
            entity.Property(e => e.ExternalSerialNo)
                .HasMaxLength(50)
                .IsUnicode(false);
            entity.Property(e => e.ExternalSessionId)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("外部充電資訊Id");
            entity.Property(e => e.IsChargeAction).HasComment("是否有充電行為");
            entity.Property(e => e.LotNo)
                .HasMaxLength(20)
                .HasComment("車格號");
            entity.Property(e => e.SerialNo)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("進場序號");
            entity.Property(e => e.StartTime)
                .HasComment("起始時間")
                .HasColumnType("datetime");
        });

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

            entity.ToTable("CommonQueue");

            entity.Property(e => e.CreationTime).HasColumnType("datetime");
            entity.Property(e => e.ErrorCount).HasComment("失敗次數");
            entity.Property(e => e.EventTime)
                .HasComment("時間發生時間")
                .HasColumnType("datetime");
            entity.Property(e => e.ExtendField).HasComment("客制欄位");
            entity.Property(e => e.NextProcessTime)
                .HasComment("下次執行時間")
                .HasColumnType("datetime");
            entity.Property(e => e.ProcessingTime)
                .HasComment("處理時間")
                .HasColumnType("datetime");
            entity.Property(e => e.ReadyToDeleteTime)
                .HasComment("距離可刪除的時間,null 表示不可刪除")
                .HasColumnType("datetime");
            entity.Property(e => e.SerialNo)
                .HasMaxLength(64)
                .HasComment("進場序號");
            entity.Property(e => e.Status)
                .HasMaxLength(30)
                .HasComment("InQueue, Processing, Fail");
            entity.Property(e => e.Type)
                .HasMaxLength(30)
                .HasComment("進場:In, 出場: Out");
        });

        modelBuilder.Entity<Counter>(entity =>
        {
            entity
                .HasNoKey()
                .ToTable("Counter", "HangFire");

            entity.HasIndex(e => e.Key, "CX_HangFire_Counter").IsClustered();

            entity.Property(e => e.ExpireAt).HasColumnType("datetime");
            entity.Property(e => e.Key).HasMaxLength(100);
        });

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

            entity.Property(e => e.DivisionId)
                .HasMaxLength(40)
                .HasComment("區域編號");
            entity.Property(e => e.DivisionName)
                .HasMaxLength(40)
                .HasDefaultValue("")
                .HasComment("名稱");
            entity.Property(e => e.DivisionType)
                .HasDefaultValue(2)
                .HasComment("區域類別");
            entity.Property(e => e.Enable)
                .HasMaxLength(1)
                .IsUnicode(false)
                .HasDefaultValue("Y")
                .IsFixedLength();

            entity.HasOne(d => d.DivisionTypeNavigation).WithMany(p => p.Divisions)
                .HasForeignKey(d => d.DivisionType)
                .HasConstraintName("FK_Division_TypeDef");

            entity.HasMany(d => d.Lots).WithMany(p => p.Divisions)
                .UsingEntity<Dictionary<string, object>>(
                    "DivisionParkingLot",
                    r => r.HasOne<ParkingLot>().WithMany()
                        .HasForeignKey("LotId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("FK_DivisionParkingLots_ParkingLot"),
                    l => l.HasOne<Division>().WithMany()
                        .HasForeignKey("DivisionId")
                        .OnDelete(DeleteBehavior.ClientSetNull)
                        .HasConstraintName("FK_DivisionParkingLots_Division"),
                    j =>
                    {
                        j.HasKey("DivisionId", "LotId");
                        j.ToTable("DivisionParkingLots");
                        j.IndexerProperty<string>("DivisionId")
                            .HasMaxLength(40)
                            .HasComment("區域序號");
                        j.IndexerProperty<string>("LotId")
                            .HasMaxLength(40)
                            .HasComment("車格序號");
                    });
        });

        modelBuilder.Entity<DivisionDisplay>(entity =>
        {
            entity.HasKey(e => e.DisplayId);

            entity.ToTable("DivisionDisplay");

            entity.Property(e => e.DisplayId)
                .HasMaxLength(40)
                .HasComment("顯示器編號")
                .HasColumnName("DisplayID");
            entity.Property(e => e.AdamIp)
                .HasMaxLength(150)
                .HasDefaultValue("")
                .HasComment("ADAM IP")
                .HasColumnName("AdamIP");
            entity.Property(e => e.AlarmSec).HasComment("警報秒數");
            entity.Property(e => e.DisplayType).HasComment("顯示類別");
            entity.Property(e => e.DivisionId)
                .HasMaxLength(40)
                .HasComment("區域序號");
            entity.Property(e => e.DoPort).HasComment("Do Port");
            entity.Property(e => e.Enable)
                .HasMaxLength(1)
                .IsUnicode(false)
                .HasDefaultValue("N")
                .IsFixedLength()
                .HasComment("啟用");
            entity.Property(e => e.Port).HasDefaultValue(17494);
            entity.Property(e => e.ReserveQty)
                .HasDefaultValue(0)
                .HasComment("保留車格");
            entity.Property(e => e.ScheduleSet).HasComment("預先設定要等PE處理的Flag");
            entity.Property(e => e.SetAsFull)
                .HasMaxLength(1)
                .IsUnicode(false)
                .HasDefaultValue("N")
                .IsFixedLength()
                .HasComment("強制滿位");

            entity.HasOne(d => d.Division).WithMany(p => p.DivisionDisplays)
                .HasForeignKey(d => d.DivisionId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_DivisionDisplay_Division");
        });

        modelBuilder.Entity<EventLog>(entity =>
        {
            entity.HasKey(e => e.EventId);

            entity.ToTable("EventLog");

            entity.Property(e => e.EventId)
                .HasMaxLength(40)
                .HasComment("事件編號");
            entity.Property(e => e.CloudSyncTime)
                .HasComment("雲端同步日期")
                .HasColumnType("smalldatetime");
            entity.Property(e => e.CreateDate)
                .HasComment("建立日期")
                .HasColumnType("smalldatetime");
            entity.Property(e => e.DeviceId)
                .HasMaxLength(40)
                .HasComment("裝置編號");
            entity.Property(e => e.EventCode).HasComment("事件類別");
            entity.Property(e => e.EventDate)
                .HasComment("事件時間(可能調整)")
                .HasColumnType("smalldatetime");
            entity.Property(e => e.Info)
                .HasMaxLength(500)
                .HasComment("資訊");
            entity.Property(e => e.LotId)
                .HasMaxLength(40)
                .HasComment("車格號");
            entity.Property(e => e.LprNo)
                .HasMaxLength(30)
                .HasComment("車牌號碼");
            entity.Property(e => e.RelatedEventId)
                .HasMaxLength(40)
                .HasComment("歸連事件編號,通常應用在出場事件");
            entity.Property(e => e.UnlockDate)
                .HasComment("異常事件解除日期")
                .HasColumnType("smalldatetime");

            entity.HasOne(d => d.EventCodeNavigation).WithMany(p => p.EventLogs)
                .HasForeignKey(d => d.EventCode)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_EventLog_TypeDef");

            entity.HasOne(d => d.Lot).WithMany(p => p.EventLogs)
                .HasForeignKey(d => d.LotId)
                .HasConstraintName("FK_EventLog_ParkingLot");
        });

        modelBuilder.Entity<Hash>(entity =>
        {
            entity.HasKey(e => new { e.Key, e.Field }).HasName("PK_HangFire_Hash");

            entity.ToTable("Hash", "HangFire");

            entity.HasIndex(e => e.ExpireAt, "IX_HangFire_Hash_ExpireAt").HasFilter("([ExpireAt] IS NOT NULL)");

            entity.Property(e => e.Key).HasMaxLength(100);
            entity.Property(e => e.Field).HasMaxLength(100);
        });

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

            entity.ToTable("Job", "HangFire");

            entity.HasIndex(e => e.ExpireAt, "IX_HangFire_Job_ExpireAt").HasFilter("([ExpireAt] IS NOT NULL)");

            entity.HasIndex(e => e.StateName, "IX_HangFire_Job_StateName").HasFilter("([StateName] IS NOT NULL)");

            entity.Property(e => e.CreatedAt).HasColumnType("datetime");
            entity.Property(e => e.ExpireAt).HasColumnType("datetime");
            entity.Property(e => e.StateName).HasMaxLength(20);
        });

        modelBuilder.Entity<JobParameter>(entity =>
        {
            entity.HasKey(e => new { e.JobId, e.Name }).HasName("PK_HangFire_JobParameter");

            entity.ToTable("JobParameter", "HangFire");

            entity.Property(e => e.Name).HasMaxLength(40);

            entity.HasOne(d => d.Job).WithMany(p => p.JobParameters)
                .HasForeignKey(d => d.JobId)
                .HasConstraintName("FK_HangFire_JobParameter_Job");
        });

        modelBuilder.Entity<JobQueue>(entity =>
        {
            entity.HasKey(e => new { e.Queue, e.Id }).HasName("PK_HangFire_JobQueue");

            entity.ToTable("JobQueue", "HangFire");

            entity.Property(e => e.Queue).HasMaxLength(50);
            entity.Property(e => e.Id).ValueGeneratedOnAdd();
            entity.Property(e => e.FetchedAt).HasColumnType("datetime");
        });

        modelBuilder.Entity<List>(entity =>
        {
            entity.HasKey(e => new { e.Key, e.Id }).HasName("PK_HangFire_List");

            entity.ToTable("List", "HangFire");

            entity.HasIndex(e => e.ExpireAt, "IX_HangFire_List_ExpireAt").HasFilter("([ExpireAt] IS NOT NULL)");

            entity.Property(e => e.Key).HasMaxLength(100);
            entity.Property(e => e.Id).ValueGeneratedOnAdd();
            entity.Property(e => e.ExpireAt).HasColumnType("datetime");
        });

        modelBuilder.Entity<MergedCarEnter>(entity =>
        {
            entity.HasKey(e => e.IncomingSerialNo);

            entity.ToTable("MergedCarEnter");

            entity.Property(e => e.IncomingSerialNo)
                .HasMaxLength(50)
                .IsUnicode(false);
            entity.Property(e => e.CreationDate).HasColumnType("datetime");
            entity.Property(e => e.SerialNo)
                .HasMaxLength(50)
                .IsUnicode(false);
        });

        modelBuilder.Entity<ParkingColumn>(entity =>
        {
            entity.HasKey(e => e.CameraId);

            entity.ToTable("ParkingColumn");

            entity.Property(e => e.CameraId).HasMaxLength(40);
            entity.Property(e => e.DeviceId).HasMaxLength(40);
            entity.Property(e => e.LastHeartBeat)
                .HasComment("最後一次心跳包時間")
                .HasColumnType("datetime");
            entity.Property(e => e.ParkingNo).HasMaxLength(6);
            entity.Property(e => e.PassTime).HasColumnType("datetime");
        });

        modelBuilder.Entity<ParkingLot>(entity =>
        {
            entity.HasKey(e => e.LotId);

            entity.ToTable("ParkingLot");

            entity.Property(e => e.LotId)
                .HasMaxLength(40)
                .HasComment("車格序號");
            entity.Property(e => e.AliasName)
                .HasMaxLength(50)
                .HasDefaultValue("")
                .HasComment("別名");
            entity.Property(e => e.CameraId)
                .HasMaxLength(40)
                .HasComment("隸屬攝影機");
            entity.Property(e => e.Enable)
                .HasMaxLength(1)
                .IsUnicode(false)
                .HasDefaultValue("Y")
                .IsFixedLength()
                .HasComment("啟用否");
            entity.Property(e => e.IsBackShot).HasComment("是否是後拍");
            entity.Property(e => e.IsChargePole).HasComment("是否為充電車格");
            entity.Property(e => e.LastEvent)
                .HasMaxLength(40)
                .HasComment("上次事件");
            entity.Property(e => e.LotNo)
                .HasMaxLength(20)
                .HasComment("車格編號");
            entity.Property(e => e.SortOrder)
                .HasComment("車格排序")
                .HasColumnType("decimal(5, 3)");

            entity.HasOne(d => d.Camera).WithMany(p => p.ParkingLots)
                .HasForeignKey(d => d.CameraId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK_ParkingLot_Camera");
        });

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

            entity.Property(e => e.Remark).HasMaxLength(500);
            entity.Property(e => e.SiteId).HasMaxLength(20);
            entity.Property(e => e.Type).HasMaxLength(50);
            entity.Property(e => e.Value).HasMaxLength(450);
        });

        modelBuilder.Entity<PaymentDevice>(entity =>
        {
            entity.HasKey(e => e.DeviceId);

            entity.ToTable("PaymentDevice");

            entity.Property(e => e.DeviceId)
                .HasMaxLength(40)
                .HasComment("裝置序號");
            entity.Property(e => e.DeviceType)
                .HasDefaultValue(1)
                .HasComment("類別, APS=1");
            entity.Property(e => e.Enable)
                .HasMaxLength(1)
                .IsUnicode(false)
                .HasDefaultValue("N")
                .IsFixedLength()
                .HasComment("啟用否");
            entity.Property(e => e.Ip)
                .HasMaxLength(150)
                .HasDefaultValue("")
                .HasComment("IP位置")
                .HasColumnName("IP");
        });

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

            entity.ToTable("PendingCarRecord");

            entity.Property(e => e.CreationDate)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime");
            entity.Property(e => e.GuidNum)
                .HasMaxLength(50)
                .IsUnicode(false);
            entity.Property(e => e.IoTime).HasColumnType("datetime");
            entity.Property(e => e.Iotype)
                .HasMaxLength(30)
                .HasColumnName("IOType");
            entity.Property(e => e.LprNo).HasMaxLength(30);
            entity.Property(e => e.ProcessedTime).HasColumnType("datetime");
            entity.Property(e => e.Remark).HasMaxLength(255);
            entity.Property(e => e.SpotNo).HasMaxLength(6);
            entity.Property(e => e.StationId).HasMaxLength(10);
        });

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

            entity.ToTable("RoadsideQueue");

            entity.Property(e => e.CreationTime).HasColumnType("datetime");
            entity.Property(e => e.ErrorCount).HasComment("失敗次數");
            entity.Property(e => e.EventTime)
                .HasComment("時間發生時間")
                .HasColumnType("datetime");
            entity.Property(e => e.NextProcessTime)
                .HasComment("下次執行時間")
                .HasColumnType("datetime");
            entity.Property(e => e.ProcessingTime)
                .HasComment("處理時間")
                .HasColumnType("datetime");
            entity.Property(e => e.SerialNo)
                .HasMaxLength(64)
                .HasComment("進場序號");
            entity.Property(e => e.Status)
                .HasMaxLength(30)
                .HasComment("InQueue, Processing, Fail");
            entity.Property(e => e.TicketNo)
                .HasMaxLength(15)
                .IsUnicode(false)
                .HasComment("路邊單號");
            entity.Property(e => e.Type)
                .HasMaxLength(30)
                .HasComment("開單:OpenTicket, 加簽: AddSign, 結單: CloseTicket, 改單:ChangeTicket, 檢查結單了但未離場: CheckLeave, 繳費通加: PaidNotify");
        });

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

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.CreateTime)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime");
            entity.Property(e => e.DeviceReceivable)
                .HasComment("繳費機的應收金額")
                .HasColumnType("decimal(5, 2)");
            entity.Property(e => e.IsDeleted).HasComment("簽單是否被刪除(取消)");
            entity.Property(e => e.Minutes).HasComment("加簽分鐘數");
            entity.Property(e => e.Receivable)
                .HasComment("路邊的應收金額")
                .HasColumnType("decimal(5, 2)");
            entity.Property(e => e.RoadsideTicketNo)
                .HasMaxLength(15)
                .IsUnicode(false)
                .HasComment("路邊單號");
            entity.Property(e => e.SerialNo)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("進場序號");
            entity.Property(e => e.SignPhotoPath).HasComment("開單照片實體路徑");
            entity.Property(e => e.StartTime)
                .HasComment("加簽開始時間")
                .HasColumnType("datetime");

            entity.HasOne(d => d.RoadsideTicket).WithMany(p => p.RoadsideSignRecords)
                .HasForeignKey(d => d.RoadsideTicketId)
                .OnDelete(DeleteBehavior.ClientSetNull)
                .HasConstraintName("FK__RoadsideS__Roads__4119A21D");
        });

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

            entity.Property(e => e.Id).HasColumnName("id");
            entity.Property(e => e.CarIdentity).HasComment("計價身份別");
            entity.Property(e => e.CarNo)
                .HasMaxLength(30)
                .HasComment("車號");
            entity.Property(e => e.CarType)
                .HasMaxLength(1)
                .IsUnicode(false)
                .HasComment("車種");
            entity.Property(e => e.CardNumber)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("卡片號碼");
            entity.Property(e => e.CardSn)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("卡片序號")
                .HasColumnName("CardSN");
            entity.Property(e => e.ClosePhotoPath).HasComment("結單照片實體路徑");
            entity.Property(e => e.CloseTime)
                .HasComment("結單時間")
                .HasColumnType("datetime");
            entity.Property(e => e.CreateTime)
                .HasDefaultValueSql("(getdate())")
                .HasColumnType("datetime");
            entity.Property(e => e.DeviceReceivable)
                .HasComment("繳費機的應收金額")
                .HasColumnType("decimal(5, 2)");
            entity.Property(e => e.EnterTime)
                .HasComment("進格時間")
                .HasColumnType("datetime");
            entity.Property(e => e.IsAutoPay).HasComment("是否自動扣繳");
            entity.Property(e => e.IsFree).HasComment("是否為公務車");
            entity.Property(e => e.LastQueryTime)
                .HasComment("上次查詢時間")
                .HasColumnType("datetime");
            entity.Property(e => e.LastestSignTime)
                .HasComment("最新加簽時間")
                .HasColumnType("datetime");
            entity.Property(e => e.NextSignTime)
                .HasComment("下次加簽時間")
                .HasColumnType("datetime");
            entity.Property(e => e.OpenPhotoPath).HasComment("開單照片實體路徑");
            entity.Property(e => e.OpenTime)
                .HasComment("開單時間")
                .HasColumnType("datetime");
            entity.Property(e => e.PaidDueDate)
                .HasComment("繳費期限")
                .HasColumnType("datetime");
            entity.Property(e => e.PaidTime)
                .HasComment("繳費時間")
                .HasColumnType("datetime");
            entity.Property(e => e.Receivable)
                .HasComment("路邊的應收金額")
                .HasColumnType("decimal(5, 2)");
            entity.Property(e => e.RoadsideTicketNo)
                .HasMaxLength(15)
                .IsUnicode(false)
                .HasComment("路邊單號");
            entity.Property(e => e.SendToRoadsidePaidTime)
                .HasComment("傳給路邊的付款時間")
                .HasColumnType("datetime");
            entity.Property(e => e.SerialNo)
                .HasMaxLength(50)
                .IsUnicode(false)
                .HasComment("進場序號");
            entity.Property(e => e.SiteId)
                .HasMaxLength(10)
                .IsUnicode(false)
                .HasComment("場站代碼");
            entity.Property(e => e.Status)
                .HasMaxLength(10)
                .IsUnicode(false)
                .HasComment("狀態: Open, Close");
        });

        modelBuilder.Entity<Schema>(entity =>
        {
            entity.HasKey(e => e.Version).HasName("PK_HangFire_Schema");

            entity.ToTable("Schema", "HangFire");

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

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

            entity.ToTable("Server", "HangFire");

            entity.HasIndex(e => e.LastHeartbeat, "IX_HangFire_Server_LastHeartbeat");

            entity.Property(e => e.Id).HasMaxLength(200);
            entity.Property(e => e.LastHeartbeat).HasColumnType("datetime");
        });

        modelBuilder.Entity<Set>(entity =>
        {
            entity.HasKey(e => new { e.Key, e.Value }).HasName("PK_HangFire_Set");

            entity.ToTable("Set", "HangFire");

            entity.HasIndex(e => e.ExpireAt, "IX_HangFire_Set_ExpireAt").HasFilter("([ExpireAt] IS NOT NULL)");

            entity.HasIndex(e => new { e.Key, e.Score }, "IX_HangFire_Set_Score");

            entity.Property(e => e.Key).HasMaxLength(100);
            entity.Property(e => e.Value).HasMaxLength(256);
            entity.Property(e => e.ExpireAt).HasColumnType("datetime");
        });

        modelBuilder.Entity<State>(entity =>
        {
            entity.HasKey(e => new { e.JobId, e.Id }).HasName("PK_HangFire_State");

            entity.ToTable("State", "HangFire");

            entity.Property(e => e.Id).ValueGeneratedOnAdd();
            entity.Property(e => e.CreatedAt).HasColumnType("datetime");
            entity.Property(e => e.Name).HasMaxLength(20);
            entity.Property(e => e.Reason).HasMaxLength(100);

            entity.HasOne(d => d.Job).WithMany(p => p.States)
                .HasForeignKey(d => d.JobId)
                .HasConstraintName("FK_HangFire_State_Job");
        });

        modelBuilder.Entity<TypeDef>(entity =>
        {
            entity.HasKey(e => e.TypeId).HasName("PK_CameraType");

            entity.ToTable("TypeDef");

            entity.Property(e => e.TypeId)
                .ValueGeneratedNever()
                .HasComment("類別編號");
            entity.Property(e => e.CategoryId).HasComment("主要類別");
            entity.Property(e => e.TypeName)
                .HasMaxLength(40)
                .HasComment("類別名稱");
        });

        OnModelCreatingPartial(modelBuilder);
    }

    partial void OnModelCreatingPartial(ModelBuilder modelBuilder);
}
