package config

import "eta/eta_mini_ht_api/common/contants"

// RedisOpts redis 连接属性
type RedisOpts struct {
	Host        string
	Username    string
	Password    string
	Database    int
	MaxIdle     int
	MaxActive   int
	IdleTimeout int
	DB          int
	MaxRetries  int
}

type RedisConfig struct {
	BaseConfig
	opts RedisOpts
}

func (r *RedisConfig) GetHost() string {
	return r.opts.Host
}
func (r *RedisConfig) GetDatabase() int {
	return r.opts.Database
}
func (r *RedisConfig) GetPassword() string {
	return r.opts.Password
}
func (r *RedisConfig) GetIdleTimeout() int {
	return r.opts.IdleTimeout
}
func (r *RedisConfig) GetMaxIdle() int {
	return r.opts.MaxIdle
}

func (r *RedisConfig) InitConfig() {
	opts := RedisOpts{
		Host:        r.GetString("host"),
		Username:    "",
		Password:    r.GetString("password"),
		Database:    r.GetInt("db"),
		MaxIdle:     10,
		MaxActive:   100,
		IdleTimeout: 10,
		DB:          0,
		MaxRetries:  3,
	}
	r.opts = opts
}
func NewRedis() Config {
	return &RedisConfig{
		BaseConfig: BaseConfig{prefix: contants.REDIS},
		opts:       RedisOpts{},
	}
}

func init() {
	Register(contants.REDIS, NewRedis)
}
