package config

// @Time    : 2024/8/21 14:30
// @Author  : lvhongmeng

type CentralConfig struct {
	ServerConfig ServerConfig `mapstructure:"server"`
}

type ServerConfig struct {
	Env                           string `mapstructure:"env" default:"prod"`
	OverwriteDefault              string `mapstructure:"overwriteDefault" default:"no"` // Flag to specify whether `devtier` section is given in configure file
	HttpListenAddr                string `mapstructure:"httpListenAddr" default:":8080"`
	MetricsPort                   string `mapstructure:"metricsPort" default:"9090"`
	KubeConfigPath                string `mapstructure:"kubeConfigPath"`
	TiDBManagementServiceEndpoint string `mapstructure:"ManagementServiceEndpoint" default:"http://regional-server.regional-server-system"`
	LocalMode                     bool   `mapstructure:"localMode" default:"false"`
	LogLevel                      string `mapstructure:"logLevel" default:"info"`
	Provider                      string `mapstructure:"provider" default:""`
}

var globalConf = &CentralConfig{}

func (c *ServerConfig) IsGiven() bool {
	return c.OverwriteDefault == "no"
}

func (c *CentralConfig) CurrentEnv() string {
	return c.ServerConfig.Env
}
func (c *CentralConfig) IsProd() bool {
	return c.CurrentEnv() == "prod"
}
func (c *CentralConfig) IsDev() bool {
	return c.CurrentEnv() == "dev"
}
func (c *CentralConfig) IsStaging() bool {
	return c.CurrentEnv() == "staging"
}
