package config

import (
	"gitlink.org.cn/cloudream/common/pkgs/logger"
	"gitlink.org.cn/cloudream/common/pkgs/mq"
	"gitlink.org.cn/cloudream/common/utils/config"
	"gitlink.org.cn/cloudream/jcs-pub/client/internal/db"
	"gitlink.org.cn/cloudream/jcs-pub/client/internal/downloader"
	"gitlink.org.cn/cloudream/jcs-pub/client/internal/downloader/strategy"
	"gitlink.org.cn/cloudream/jcs-pub/client/internal/http"
	mntcfg "gitlink.org.cn/cloudream/jcs-pub/client/internal/mount/config"
	"gitlink.org.cn/cloudream/jcs-pub/client/internal/ticktock"
	stgglb "gitlink.org.cn/cloudream/jcs-pub/common/globals"
	"gitlink.org.cn/cloudream/jcs-pub/common/pkgs/connectivity"
	hubrpc "gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc/hub"
)

type Config struct {
	Local            stgglb.LocalMachineInfo `json:"local"`
	HubRPC           hubrpc.PoolConfig       `json:"hubRPC"`
	Logger           logger.Config           `json:"logger"`
	DB               db.Config               `json:"db"`
	RabbitMQ         mq.Config               `json:"rabbitMQ"`
	Connectivity     connectivity.Config     `json:"connectivity"`
	Downloader       downloader.Config       `json:"downloader"`
	DownloadStrategy strategy.Config         `json:"downloadStrategy"`
	TickTock         ticktock.Config         `json:"tickTock"`
	HTTP             *http.Config            `json:"http"`
	Mount            *mntcfg.Config          `json:"mount"`
}

var cfg Config

// Init 初始化client
// TODO 这里的modeulName参数弄成可配置的更好
func Init(configPath string) error {
	if configPath == "" {
		return config.DefaultLoad("client", &cfg)
	}
	return config.Load(configPath, &cfg)
}

func Cfg() *Config {
	return &cfg
}
