package collectCfg

import (
	"server/game/mod/item"
	GoUtil "server/game_util"
	"server/gamedata"
	"server/pkg/github.com/name5566/leaf/log"
)

const (
	CFG_COLLECT         = "Collect"
	CFG_COLLECT_JACKPOT = "CollectJackpot"
)

func init() {
	gamedata.InitCfg(CFG_COLLECT)
	gamedata.InitCfg(CFG_COLLECT_JACKPOT)
}

func GetJackpotId() []int {
	data, err := gamedata.GetData(CFG_COLLECT_JACKPOT)
	if err != nil {
		log.Debug("GetJackpotId err:%v", err)
		return nil
	}
	ret := make([]int, 0, len(data))
	for k := range data {
		ret = append(ret, GoUtil.Int(k))
	}
	return ret
}

func GetJackpotItems(Id int) []*item.Item {
	data, err := gamedata.GetDataByIntKey(CFG_COLLECT_JACKPOT, Id)
	if err != nil {
		log.Debug("GetJackpotItems err:%v, Id=%d", err, Id)
		return nil
	}
	return gamedata.GetItemList(data, "Items")
}

func GetRewardNeed(Id int) int {
	data, err := gamedata.GetDataByIntKey(CFG_COLLECT, Id)
	if err != nil {
		log.Debug("GetRewardNeed err:%v, Id=%d", err, Id)
		return 0
	}
	return gamedata.GetIntValue(data, "Need")
}

func GetRewardType(Id int) int {
	data, err := gamedata.GetDataByIntKey(CFG_COLLECT, Id)
	if err != nil {
		log.Debug("GetRewardType err:%v, Id=%d", err, Id)
		return 0
	}
	return gamedata.GetIntValue(data, "Type")
}
