package redisdata

import (
	"fmt"
	"time"
)

const (
	KEY_PREFIX          string = "oppmg_"          //统一前缀
	KEY_USER_TOKEN      string = "token"           //登录token存储
	KEY_CAPTCHA_AUTH    string = "captch_auth"     //统一用户中心返回的验证码凭证
	KEY_USER_PERMISSION string = "user_permission" //用户操作权限
)

const (
	LOGIN_TOKEN_EXP  = 1800 * time.Second //token 过期时间30分钟
	CAPTCHA_AUTH_EXP = 300 * time.Second  // 验证码凭证 过期时间5分钟
)

type RedisLoginToken struct {
	AccessToken    string `json:"access_token"`
	RefreshToken   string `json:"refresh_token"`
	CurrentCompany int64  `json:"current_company"`
}

func GetKeyLoginToken(userid int64, companyid int64) string {
	key := fmt.Sprintf("%s%s:%d_%d", KEY_PREFIX, KEY_USER_TOKEN, userid, companyid)
	return key
}

func GetKeyCaptchAuth(phone string) string {
	key := fmt.Sprintf("%s%s:%s", KEY_PREFIX, KEY_CAPTCHA_AUTH, phone)
	return key
}

func GetKeyUserPermission(userid int64) string {
	key := fmt.Sprintf("%s%s:%d", KEY_PREFIX, KEY_USER_PERMISSION, userid)
	return key
}