package cool

import (
	"blazing/common/utils"
	"context"
	"reflect"
	"time"

	"github.com/antlabs/cronex"
	"github.com/gogf/gf/v2/os/glog"
	sensitive "github.com/zmexing/go-sensitive-word"
)

var ctx = context.TODO()

var (
	CmdCache = &utils.SyncMap[uint32, reflect.Value]{} //命令缓存

	Loger = glog.New()
	Cron  = cronex.New() //时间轮

)
var Filter *sensitive.Manager
var DefaultGenerator = utils.NewGen(time.Date(2025, 1, 1, 0, 0, 0, 0, time.UTC), uint8(Config.PortBL))

func init() {
	// 创建 IdGeneratorOptions 对象，可在构造函数中输入 WorkerId：
	Loger.SetFlags(glog.F_TIME_STD | glog.F_FILE_LONG) //设置flag
	Loger.Print(ctx, "初始化日志")
	// for i := 0; i < 600; i++ {
	// 	glog.Debug(context.Background(), i, "初始化雪花算法", DefaultGenerator.Get())
	// }

	Filter, _ = sensitive.NewFilter(
		sensitive.StoreOption{Type: sensitive.StoreMemory}, // 基于内存
		sensitive.FilterOption{Type: sensitive.FilterDfa},  // 基于DFA算法
	)
	go Cron.Run()

	// if err != nil {
	// 	log.Fatalf("敏感词服务启动失败, err:%v", err)
	// 	return
	// }

	// 加载敏感词库
	Filter.LoadDictEmbed(
		sensitive.DictCovid19,
		sensitive.DictOther,
		sensitive.DictReactionary,
		sensitive.DictViolence,
		sensitive.DictPeopleLife,
		sensitive.DictPornography,
		sensitive.DictAdditional,
		sensitive.DictCorruption,
		sensitive.DictTemporaryTencent,
	)
	// if err != nil {
	// 	log.Fatalf("加载词库发生了错误, err:%v", err)
	// 	return
	// }

	// // 动态添加自定义敏感词
	// err = Filter.Store.AddWord("李世民", "秦始皇")
	// if err != nil {
	// 	log.Fatalf("添加敏感词发生了错误, err:%v", err)
	// 	return
	// }

	// // 动态自定义敏感词白名单
	// err = Filter.Store.DelWord("武汉海鲜市场", "武汉")
	// if err != nil {
	// 	log.Fatalf("删除敏感词发生了错误, err:%v", err)
	// 	return
	// }

}
