package redis_key

import (
	"fmt"
	"github.com/alibaba/sentinel-golang/util"
	"github.com/fonchain_enterprise/micro-account/pkg/common/utils"
	"time"
)

const (
	mobile = "mobile:"
	token  = "token:"
)

func UserDailyGetCoinKey(userId uint32) string {
	return fmt.Sprintf("coin:micro:user::id:%d:daily:%s", userId, time.Now().Format(util.DateFormat))
}

func UserRegisterGetCoinKey(userId uint32) string {
	return fmt.Sprintf("coin:micro:user::id:%d:register", userId)
}

func UserCoinLock(domain string, key uint32) string {
	return fmt.Sprintf("%s:lock:user:%d", domain, key)
}

func GetAccountKey(domain, key string) string {
	return domain + ":" + mobile + key
}

func VerityCode(domain, key string) string {
	return domain + ":code:time:" + mobile + key
}

func BlackListKey(domain string) string {
	return domain + ":blackList:" + mobile
}

func GetOnlyAccountKey(domain, key string) string {
	return domain + ":only:" + mobile + key
}

func GetTokenInfo(domain, key string) string {
	return domain + ":" + token + "info:" + utils.Get16MD5Encode(key)
}

func GetIpAddressKey(key string) string {
	return "ip_address:" + key
}

func GetTokenLogoutInfo(domain, key string) string {
	return domain + ":" + token + "logout_err:" + key
}

func GetAccountRegisterKey(domain, key string) string {
	return domain + ":register:" + mobile + key
}

func GetAccountKeyCountToday(domain, key string) string {
	return domain + ":count:date:" + time.Now().Format("2006-01-02") + ":" + mobile + key
}

func GetAccountKeyCountTodayHour(domain, telNum, scope string) string {
	return domain + ":count:date:" + scope + ":" + time.Now().Format("2006-01-02 15") + ":" + telNum
}

func MinLimit(domain, telNum, scope string) string {
	return domain + ":count:min_limit:" + scope + ":" + telNum
}

func GetChangeTelKey(domain, key string, id string) string {
	return domain + ":changeTel:" + mobile + id + ":" + key
}

func GetOneMinuteKey(domain, key string, id string) string {
	return domain + ":minute:" + mobile + id + ":" + key
}

func GetNowNewTelById(domain string, id string) string {
	return domain + ":now_tel:" + id
}

func GetBoxAccessToken(key string) string {
	return "box:access_token:" + key
}

func GetWxAccessToken(key string) string {
	return "box:access_token:" + key
}

// GetCheckPasswordRate 限制解密 频率
func GetCheckPasswordRate(domain, tel string) string {
	return domain + ":check:psd:" + mobile + tel
}
