package initialize

import (
	"os"
	"server/dao/devices"
	example2 "server/dao/example"
	"server/dao/system"

	"go.uber.org/zap"
	"gorm.io/gorm"
	"server/global"
	"server/model/example"
)

func Gorm() *gorm.DB {
	switch global.GVA_CONFIG.System.DbType {
	case "mysql":
		return GormMysql()
	case "pgsql":
		return GormPgSql()
	case "oracle":
		return GormOracle()
	case "mssql":
		return GormMssql()
	case "sqlite":
		return GormSqlite()
	default:
		return GormMysql()
	}
}

func RegisterTables() {
	db := global.GVA_DB
	err := db.AutoMigrate(

		system.SysApi{},
		system.SysUser{},
		system.SysBaseMenu{},
		system.JwtBlacklist{},
		system.SysAuthority{},
		system.SysDictionary{},
		system.SysOperationRecord{},
		system.SysDictionaryDetail{},
		system.SysBaseMenuParameter{},
		system.SysBaseMenuBtn{},
		system.SysAuthorityBtn{},

		example.ExaFile{},
		example.ExaFileChunk{},
		example2.ExaFileUploadAndDownload{},

		devices.GateWay{},
		devices.Camera{},
		devices.Screens{}, devices.Resolution{}, devices.ScreensSize{}, //屏幕以及一些屏参
		devices.Radar{},
		devices.Intersect{},
	)
	if err != nil {
		global.GVA_LOG.Error("register table failed", zap.Error(err))
		os.Exit(0)
	}
	global.GVA_LOG.Info("register table success")
}
