// Tool Url: https://github.com/jinzhu/configor

package config

// Database configuration
type CentralConfig struct {
	ServerConf     ServerConfig     `mapstructure:"server"`
	SentryConf     SentryConfig     `mapstructure:"sentry"`
	MysqlConf      MysqlConfig      `mapstructure:"mysql"`
	GrpcConf       GrpcConfig       `mapstructure:"grpc"`
	MessageSvcConf MessageSvcConfig `mapstructure:"messagesvc"`
}

type MessageSvcConfig struct {
	OpenAIEndpoint    string `mapstructure:"openaiEndpoint" default:"https://api.openai.com"`
	OpenAIApiKey      string `mapstructure:"openaiApiKey" required:"true"`
	OpenAIModel       string `mapstructure:"openaiModel" default:"text-davinci-003"`
	SqlEditorEndpoint string `mapstructure:"sqlEditorEndpoint" default:"https://us-west-2.nightly.shared.aws.tidbcloud.com"`
	MaxRetryCount     int    `mapstructure:"maxRetryCount" default:"3"`
	MaxDelaySeconds   int    `mapstructure:"maxDelaySeconds" default:"10"`
}

type ServerConfig struct {
	LogLevel    string `mapstructure:"logLevel" default:"info"`
	GrpcPort    string `mapstructure:"grpcPort" default:"10000"`
	HttpPort    string `mapstructure:"httpPort" default:"10010"`
	MetricsPort string `mapstructure:"metricsPort" default:"9090"`
	LocalMode   bool   `mapstructure:"localMode" default:"false"`
}

type GrpcConfig struct {
	AccountProviderSvcAddr string `mapstructure:"accountProviderSvcAddr" default:"account-provider-grpc:10000"`
	DataAPISvcAddr         string `mapstructure:"dataAPISvcAddr" default:"dataservice-dataapi-service:10000"`
}

type SentryConfig struct {
	DSN         string `mapstructure:"dsn"`
	Environment string `mapstructure:"env"`
	LogLevel    string `mapstructure:"logLevel" default:"warn"`
}

type MysqlConfig struct {
	Host     string `mapstructure:"host"  required:"true"`
	User     string `mapstructure:"user" default:"dataservices"`
	Port     uint   `mapstructure:"port" default:"4000"`
	Password string `mapstructure:"password" required:"true"`
	Database string `mapstructure:"database" default:"dataservices"`
	CharSet  string `mapstructure:"charset"  default:"utf8"`
	TimeZone string `mapstructure:"timezone"  default:"UTC"`
}

var globalConf = &CentralConfig{}

func IsLocalMode() bool {
	if globalConf.ServerConf.LocalMode {
		return true
	}
	return false
}
