package services

import (
	"sync"

	"github.com/fiskerinc/cloud-services/pkg/redis"
	rm "github.com/fiskerinc/cloud-services/pkg/redis/tester"
	"github.com/fiskerinc/cloud-services/pkg/utils/envtool"
)

var (
	clientPoolOnce sync.Once
	clientPool     redis.ClientPoolInterface
	FilteringON    = envtool.GetEnv("OPTIMUS_FILTER_WARNINGS", "1")
)

func RedisClientPool() redis.ClientPoolInterface {
	clientPoolOnce.Do(func() {
		if clientPool != nil {
			return
		}

		if FilteringON == "0" {
			mockRedis := rm.MockRedis{}
			clientPool = rm.NewMockClientPool(&mockRedis)
			return
		}

		clientPool = redis.NewClientPool()
	})

	return clientPool
}

func SetRedisClientPool(cp redis.ClientPoolInterface) {
	clientPool = cp
}
