package raceCfg

import (
	"server/game/mod/item"
	"server/gamedata"
)

const (
	CFG_RACE_TEMPLATE = "RaceTemplate"
	CFG_RACE_PASS     = "RacePass"
)

func init() {
	gamedata.InitCfg(CFG_RACE_TEMPLATE)
	gamedata.InitCfg(CFG_RACE_PASS)
}

func GetRaceNum(Pass int) int {
	data, err := gamedata.GetDataByIntKey(CFG_RACE_PASS, Pass)
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "Num")
}

func GetRaceNeed(Pass int) int {
	data, err := gamedata.GetDataByIntKey(CFG_RACE_PASS, Pass)
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "Need")
}

func GetMaxPass(Id int) int {
	data, err := gamedata.GetDataByIntKey(CFG_RACE_TEMPLATE, Id)
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "PassNum")
}
func GetActivityItemId(Id int) int {
	data, err := gamedata.GetDataByIntKey(CFG_RACE_TEMPLATE, Id)
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "ItemId")
}
func GetCD(Id int) int {
	data, err := gamedata.GetDataByIntKey(CFG_RACE_PASS, Id)
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "Cd")
}

func GetCoin(Id int) int {
	data, err := gamedata.GetDataByIntKey(CFG_RACE_TEMPLATE, Id)
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "ItemId")
}

func GetExtraReward(Id int) []*item.Item {
	data, err := gamedata.GetDataByIntKey(CFG_RACE_PASS, Id)
	if err != nil {
		return nil
	}
	return gamedata.GetItemList(data, "ExtraReward")
}

func GetReward(Id int) []*item.Item {
	data, err := gamedata.GetDataByIntKey(CFG_RACE_PASS, Id)
	if err != nil {
		return nil
	}
	return gamedata.GetItemList(data, "Reward")
}
