package initialize

import (
	"github.com/gogf/gf/v2/os/gcfg"
	"github.com/gogf/gf/v2/os/gctx"
	"go.uber.org/zap"
	"tgk-touch/internal/core"
	g "tgk-touch/internal/global"
	"tgk-touch/internal/model/config"
	"tgk-touch/internal/module/adl400TtyApi"
	m9zTtyApi "tgk-touch/internal/module/m9zTtyApi"
	"tgk-touch/internal/module/m9zTtyPwd"
	"tgk-touch/internal/module/meterFirm"
)

func Init() {
	CfgInit()
	ZapInit()
	m9zTtyPwd.Init()
	meterFirm.Init()
	m9zTtyApi.Init()
	adl400TtyApi.Init()
	timer()

}

func CfgInit() {

	// 读取配置文件
	loader := gcfg.NewLoader[config.AppConfig](g.Cfg(), "")
	// 设置配置变更回调
	loader.OnChange(func(updated config.AppConfig) error {
		g.GVA_Config = updated
		ZapInit()
		return nil
	})
	loader.MustLoadAndWatch(gctx.New(), "app-config")
	g.GVA_Config = loader.Get()

}
func ZapInit() {
	// 初始化zap日志库
	g.GVA_LOG = core.Zap()
	zap.ReplaceGlobals(g.GVA_LOG)
}
