package config

import (
	log "gitlink.org.cn/cloudream/common/pkgs/logger"
	"gitlink.org.cn/cloudream/common/pkgs/mq"
	c "gitlink.org.cn/cloudream/common/utils/config"
	stgglb "gitlink.org.cn/cloudream/jcs-pub/common/globals"
	"gitlink.org.cn/cloudream/jcs-pub/common/pkgs/connectivity"
	"gitlink.org.cn/cloudream/jcs-pub/common/pkgs/rpc"
	cortypes "gitlink.org.cn/cloudream/jcs-pub/coordinator/types"
)

type Config struct {
	ID           cortypes.HubID          `json:"id"`
	Local        stgglb.LocalMachineInfo `json:"local"`
	RPC          rpc.Config              `json:"rpc"`
	Logger       log.Config              `json:"logger"`
	RabbitMQ     mq.Config               `json:"rabbitMQ"`
	Connectivity connectivity.Config     `json:"connectivity"`
}

var cfg Config

func Init(path string) error {
	if path == "" {
		return c.DefaultLoad("hub", &cfg)
	}

	return c.Load(path, &cfg)
}

func Cfg() *Config {
	return &cfg
}
