package internal

import (
	_ "go.uber.org/automaxprocs"
	"go.uber.org/zap"

	"wails-app/internal/core"
	"wails-app/internal/global"
	"wails-app/internal/initialize"
)

// InitBackend initializes the Go backend (Viper, Zap, GORM, Gin) and starts the
// HTTP server in a background goroutine. It does not block. Call this before
// running the Wails application.
func InitBackend() {
	global.GVA_VP = core.Viper()
	initialize.OtherInit()
	global.GVA_LOG = core.Zap()
	zap.ReplaceGlobals(global.GVA_LOG)
	global.GVA_DB = initialize.Gorm()
	initialize.Timer()
	initialize.DBList()
	if global.GVA_DB != nil {
		initialize.RegisterTables()
		initialize.SeedSystemData()
	}
	initialize.InitUHFDevices()
	go core.RunWindowsServer()
}
