package impl

import (
	"bsm/full/module/base/logs/internal/config"
	"git.apinb.com/bsm-sdk/core/cache/redis"
	"git.apinb.com/bsm-sdk/core/types"
	"git.apinb.com/bsm-sdk/core/vars"
	"git.apinb.com/bsm-sdk/core/with"
	clientv3 "go.etcd.io/etcd/client/v3"
	"gorm.io/gorm"
)

var (
	RedisService *redis.RedisClient // Redis 客户端服务
	EtcdService  *clientv3.Client   // Etcd 客户端服务
	DBService    *gorm.DB           // 数据库服务
)

// NewImpl 初始化各类服务实例
func NewImpl() {
	// 初始化 Redis 缓存
	RedisService = with.RedisCache(config.Spec.Cache)

	// 初始化数据库服务
	opts := &types.SqlOptions{
		MaxIdleConns:    vars.SqlOptionMaxIdleConns,
		MaxOpenConns:    vars.SqlOptionMaxOpenConns,
		ConnMaxLifetime: vars.SqlOptionConnMaxLifetime,
		LogStdout:       false,
		Debug:           false,
	}
	DBService = with.Databases(config.Spec.Databases, opts)

	// 初始化 Etcd 服务
	EtcdService = with.Etcd(config.Spec.Etcd)
}
