package init

import (
	"flag"
	"fmt"
	"jyBXCore/entity"
	"jyBXCore/rpc/internal/config"

	"app.yhyue.com/moapp/jypkg/middleground"
	_ "github.com/go-sql-driver/mysql"
	"github.com/zeromicro/go-zero/core/conf"
)

var (
	configFile     = flag.String("cf", "etc/bxcore.yaml", "the config file")
	C              config.Config
	dbFile         = flag.String("df", "etc/db.yaml", "the db file")
	DB             config.Db
	logFile        = flag.String("lf", "etc/logs.yaml", "the logs file")
	logc           entity.Logc
	SearchLimitKey = "jy_limitSearchText_new" // 全文或附件搜索限制
	Middleground   *middleground.Middleground
)

func init() {
	//基本配置
	conf.MustLoad(*configFile, &C)
	//数据库配置
	conf.MustLoad(*dbFile, &DB)
	//初始mongodb
	MongoDBInit(&DB.Mongo)
	//初始化msyql
	MysqlInit(&DB.Mysql)
	//初始redis
	RedisInit(&DB.Redis)
	//初始es
	EsInit(&DB.Es)

	//初始化标签
	LabelInit()
	//
	SearchLimitKey = fmt.Sprintf(C.LimitSearchText.LimitKey, "jy_limitSearchText")
	//初始化中台相关
	Middleground = middleground.NewMiddleground(C.Middleground.Etcd.Hosts).
		RegUserCenter(C.Middleground.UserCenterKey).
		RegPowerCheckCenter(C.Middleground.PowerCheckCenterKey).
		RegResourceCenter(C.Middleground.ResourceCenterKey)
}
