package config

var globalConf = &TiDBMgmtPortalConfig{}

type TiDBMgmtPortalConfig struct {
	TiDBMgmtServiceConfig TiDBMgmtServiceConfig  `mapstructure:"tidbMgmtService"`
	Auth                  Auth                   `mapstructure:"auth"`
	RBAC                  RBAC                   `mapstructure:"rbac"`
	AccountService        AccountService         `mapstructure:"accountService"`
	IPIPServer            IPIPServer             `mapstructure:"ipip"`
	CompatAPI             CompatAPI              `mapstructure:"compatApi"`
	AllowAndLockList      AllowAndLockListConfig `mapstructure:"allowAndLockList"`
	Cors                  CorsConfig             `mapstructure:"cors"`
}

type TiDBMgmtServiceConfig struct {
	LocalMode bool   `mapstructure:"localMode" default:"false"`
	Address   string `mapstructure:"address"   default:"localhost:10001"`
}

type Auth struct {
	LocalMode bool `mapstructure:"localMode" default:"false"`
}

type RBAC struct {
	LocalMode bool `mapstructure:"localMode" default:"false"`
}

type AccountService struct {
	LocalMode  bool   `mapstructure:"localMode"  default:"false"`
	Address    string `mapstructure:"address"    default:"localhost:10002"`
	AclAddress string `mapstructure:"aclAddress" default:"localhost:10002"`
}

type IPIPServer struct {
	LocalMode bool   `mapstructure:"localMode" default:"false"`
	Address   string `mapstructure:"address"   default:"ipip-svc.nightly-ms:8080"`
}

type CompatAPI struct {
	Enable bool `mapstructure:"enable" default:"false"`
}

type AllowAndLockListConfig struct {
	Enable         bool   `mapstructure:"enable"         default:"true"`
	OneConfigName  string `mapstructure:"oneConfigName"  default:"oneconfig-allow-lock-list/list.yaml"`
	ReloadInterval int    `mapstructure:"reloadInterval" default:"600"` // unit: second

	// if true, cache the allow list and lock list,
	// you can change the value of allow list and lock list in the configMap,
	// and the cache will be cleaned up after the reloadInterval
	// so should set the reloadInterval to a reasonable value
	EnableCache bool `mapstructure:"cache" default:"true"`
}

type CorsConfig struct {
	AllowOrigins []string `mapstructure:"allowOrigins"`
}
