package jackpot

import (
	"context"
	"fmt"
	"github.com/go-redis/redis/v8"
	"strconv"
)

func JackpotSet(rdb *redis.Client, gameId int, chips int64) {
	key := fmt.Sprintf("Jackpot:%d", gameId)
	_, _ = rdb.Set(context.Background(), key, chips, 0).Result()
}

func JackpotAdd(rdb *redis.Client, gameId int, chips int64) int64 {
	key := fmt.Sprintf("Jackpot:%d", gameId)
	v, _ := rdb.IncrBy(context.Background(), key, chips).Result()
	return v
}

func JackpotGet(rdb *redis.Client, gameId int) int64 {
	key := fmt.Sprintf("Jackpot:%d", gameId)
	jp := rdb.Get(context.Background(), key).Val()
	result, _ := strconv.ParseInt(jp, 10, 64)
	return result
}

// jp系统池，玩家部分利润进入该池，重置jackpot池时，从这里扣除。系统池反映系统盈亏
func JackpotSystemAdd(rdb *redis.Client, gameId int, chips int64) int64 {
	key := fmt.Sprintf("JackpotSystem:%d", gameId)
	value, _ := rdb.IncrBy(context.Background(), key, chips).Result()
	return value
}

func JackpotSystemGet(rdb *redis.Client, gameId int) int64 {
	key := fmt.Sprintf("JackpotSystem:%d", gameId)
	jp := rdb.Get(context.Background(), key).Val()
	result, _ := strconv.ParseInt(jp, 10, 64)
	return result
}

// 玩家总赎回
func JackpotUserRepaidAdd(rdb *redis.Client, gameId int, chips int64) int64 {
	key := fmt.Sprintf("JackpotUserRepaid:%d", gameId)
	value, _ := rdb.IncrBy(context.Background(), key, chips).Result()
	return value
}

// jp池重置次数
func JackpotInitCountAdd(rdb *redis.Client, gameId int) int64 {
	key := fmt.Sprintf("JackpotInitCount:%d", gameId)
	count, _ := rdb.IncrBy(context.Background(), key, 1).Result()
	return count
}
