package config

import "sync"

// ===================================================
//	This class has to be updated everytime
//	a new configuration variable is defined
//	in a componant that imports oc-lib
// ===================================================

type Config struct {
	IsApi  bool
	IsNano bool

	APIPort        int
	NATSUrl        string
	MongoUrl       string
	MongoDatabase  string
	Host           string
	Port           string
	LokiUrl        string
	LogLevel       string
	Whitelist      bool
	PrivateKeyPath string
	PublicKeyPath  string

	InternalCatalogAPI    string
	InternalSharedAPI     string
	InternalWorkflowAPI   string
	InternalWorkspaceAPI  string
	InternalPeerAPI       string
	InternalDatacenterAPI string
	InternalSchedulerAPI  string
}

func (c Config) GetUrl() string {
	return c.MongoUrl
}

func (c Config) GetDatabase() string {
	return c.MongoDatabase
}

var instance *Config
var once sync.Once

func GetConfig() *Config {
	once.Do(func() {
		instance = &Config{}
	})
	return instance
}

func SetConfig(isNano bool, isAPI bool, mongoUrl string, database string, natsUrl string, lokiUrl string, logLevel string, port int,
	pkPath, ppPath,
	internalCatalogAPI, internalSharedAPI, internalWorkflowAPI, internalWorkspaceAPI,
	internalPeerAPI, internalDatacenterAPI string, internalSchedulerAPI string) *Config {
	GetConfig().IsNano = isNano
	GetConfig().IsApi = isAPI

	GetConfig().MongoUrl = mongoUrl
	GetConfig().MongoDatabase = database
	GetConfig().NATSUrl = natsUrl
	GetConfig().LokiUrl = lokiUrl
	GetConfig().LogLevel = logLevel
	GetConfig().Whitelist = true
	GetConfig().APIPort = port
	GetConfig().PrivateKeyPath = pkPath
	GetConfig().PublicKeyPath = ppPath

	GetConfig().InternalCatalogAPI = internalCatalogAPI
	GetConfig().InternalSharedAPI = internalSharedAPI
	GetConfig().InternalWorkflowAPI = internalWorkflowAPI
	GetConfig().InternalWorkspaceAPI = internalWorkspaceAPI
	GetConfig().InternalPeerAPI = internalPeerAPI
	GetConfig().InternalDatacenterAPI = internalDatacenterAPI
	GetConfig().InternalSchedulerAPI = internalSchedulerAPI
	return GetConfig()
}
