package playroomCfg

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

const (
	CFG_PLAYROOM_CONST           = "PlayroomConst"
	CFG_PLAYROOM_DECORATE        = "PlayroomDecorate"
	CFG_PLAYROOM_MOOD            = "PlayroomMood"
	CFG_PLAYROOM_PHYSIOLOGY      = "PlayroomPhysiology"
	CFG_PLAYROOM_PHYSIOLOGY_TYPE = "PlayroomPhysiologyType"
	CFG_PLAYROOM_SHOP            = "PlayroomShop"
	CFG_PLAYROOM_DRESS           = "PlayroomDress"
	CFG_PLAYROOM_AIR             = "PlayroomAir"
)

func init() {
	gamedata.InitCfg(CFG_PLAYROOM_CONST)
	gamedata.InitCfg(CFG_PLAYROOM_DECORATE)
	gamedata.InitCfg(CFG_PLAYROOM_MOOD)
	gamedata.InitCfg(CFG_PLAYROOM_PHYSIOLOGY)
	gamedata.InitCfg(CFG_PLAYROOM_PHYSIOLOGY_TYPE)
	gamedata.InitCfg(CFG_PLAYROOM_SHOP)
	gamedata.InitCfg(CFG_PLAYROOM_DRESS)
	gamedata.InitCfg(CFG_PLAYROOM_AIR)
}

func GetShopItem(Id int) (int, []*item.Item) {
	data, err := gamedata.GetDataByIntKey(CFG_PLAYROOM_SHOP, Id)
	if err != nil {
		return 0, nil
	}
	return gamedata.GetIntValue(data, "ItemId"), gamedata.GetItemList(data, "Cost")
}

func GetUnLockLv() int {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "Lv")
	if err != nil {
		return 999
	}
	return gamedata.GetIntValue(data, "Value")
}

func GetGameOutline() int {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "GameOutline")
	if err != nil {
		return 999
	}
	return gamedata.GetIntValue(data, "Value")
}

func GetOrderStar() int {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "Star")
	if err != nil {
		return 1000
	}
	return gamedata.GetIntValue(data, "Value")
}

func GetRewardStar() int {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "RewardStar")
	if err != nil {
		return 1000
	}
	return gamedata.GetIntValue(data, "Value")
}

func GetTriggerCd() int {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "CD")
	if err != nil {
		return 1000
	}
	return gamedata.GetIntValue(data, "Value")
}

func GetNormalItem() (int, int) {
	data1, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "NormalFoodId")
	if err != nil {
		return 0, 0
	}
	data2, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "NormalCleanId")
	if err != nil {
		return 0, 0
	}
	return gamedata.GetIntValue(data1, "Value"), gamedata.GetIntValue(data2, "Value")
}

func GetPremiumItem() (int, int) {
	data1, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "PremiumFoodId")
	if err != nil {
		return 0, 0
	}
	data2, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "PremiumCleanId")
	if err != nil {
		return 0, 0
	}
	return gamedata.GetIntValue(data1, "Value"), gamedata.GetIntValue(data2, "Value")
}

func GetVisitorItem() int {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "VisitorItem")
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "Value")
}
func GetWorkItem() int {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "WorkItem")
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "Value")
}

func GetWorkChargeId() int {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "WorkChargeId")
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "Value")
}

func GetJackpotNum() int {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "Jackpot")
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "Value")
}

func GetInteract(Id, Type int) (int, []*item.Item, int) {
	data, err := gamedata.GetDataByIntKey(CFG_PLAYROOM_MOOD, Id)
	if err != nil {
		return 0, nil, 0
	}
	if Type == 1 {
		return gamedata.GetIntValue(data, "Type"), gamedata.GetItemList(data, "Cost"), gamedata.GetIntValue(data, "Effect")
	}
	return gamedata.GetIntValue(data, "Type"), gamedata.GetItemList(data, "Cost2"), gamedata.GetIntValue(data, "Effect")
}

func GetInteractPhysiology(Id int) (int, int) {
	data, err := gamedata.GetDataByIntKey(CFG_PLAYROOM_MOOD, Id)
	if err != nil {
		return 0, 0
	}
	return gamedata.GetIntValue(data, "PType"), gamedata.GetIntValue(data, "PEffect")
}

func GetInitDecorate() []int {
	r := make([]int, 0)
	data, err := gamedata.GetData(CFG_PLAYROOM_DECORATE)
	if err != nil {
		return []int{}
	}
	for k, v := range data {
		if gamedata.GetIntValue(v, "Init") == 1 {
			r = append(r, GoUtil.Int(k))
		}
	}
	return r
}

func GetDecorateList() []int {
	r := make([]int, 0)
	data, err := gamedata.GetData(CFG_PLAYROOM_DECORATE)
	if err != nil {
		return []int{}
	}
	for k := range data {
		r = append(r, GoUtil.Int(k))
	}
	return r
}

func GetBuyItem(Id int) ([]*item.Item, []*item.Item) {
	data, err := gamedata.GetDataByIntKey(CFG_PLAYROOM_MOOD, Id)
	if err != nil {
		return nil, nil
	}
	return gamedata.GetItemList(data, "Cost2"), gamedata.GetItemList(data, "Buy")
}

func GetPhysiologyMax(Id int) int {
	data, err := gamedata.GetDataByIntKey(CFG_PLAYROOM_PHYSIOLOGY_TYPE, Id)
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "Max")
}

func GetPhysiologyDuration(Id int, Num int) int {
	data, err := gamedata.GetData(CFG_PLAYROOM_PHYSIOLOGY)
	if err != nil {
		return 0
	}
	for _, v := range data {
		Type := gamedata.GetIntValue(v, "Type")
		if Type != Id {
			continue
		}
		Min := gamedata.GetIntValue(v, "Min")
		Max := gamedata.GetIntValue(v, "Max")
		if Num >= Min && Num <= Max {
			return gamedata.GetIntValue(v, "Per")
		}
	}
	return 0
}

func GetPhysiologyTypeList() []int {
	r := make([]int, 0)
	data, err := gamedata.GetData(CFG_PLAYROOM_PHYSIOLOGY_TYPE)
	if err != nil {
		return []int{}
	}
	for k := range data {
		r = append(r, GoUtil.Int(k))
	}
	return r
}

func GetMoodEffect(Id int) (int, int) {
	data, err := gamedata.GetDataByIntKey(CFG_PLAYROOM_PHYSIOLOGY_TYPE, Id)
	if err != nil {
		return 0, 0
	}
	return gamedata.GetIntValue(data, "MType"), gamedata.GetIntValue(data, "MEffect")
}

func IsStokeCat(Id int) bool {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "StokeCatId")
	if err != nil {
		return false
	}
	return gamedata.GetIntValue(data, "Value") == Id
}

func IsTakeCat(Id int) bool {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "TakeCatId")
	if err != nil {
		return false
	}
	Ids := gamedata.GetIntSliceValue(data, "Value")
	return GoUtil.InArray(Id, Ids)
}

func IsPlayCat(Id int) bool {
	data, err := gamedata.GetDataByKey(CFG_PLAYROOM_CONST, "PlayCatId")
	if err != nil {
		return false
	}
	Ids := gamedata.GetIntSliceValue(data, "Value")
	return GoUtil.InArray(Id, Ids)
}

func GetInitAirList() []int {
	r := make([]int, 0)
	data, err := gamedata.GetData(CFG_PLAYROOM_AIR)
	if err != nil {
		return []int{}
	}
	for k, v := range data {
		if gamedata.GetIntValue(v, "Init") == 1 {
			r = append(r, GoUtil.Int(k))
		}
	}
	return r
}

func GetAirList() []int {
	r := make([]int, 0)
	data, err := gamedata.GetData(CFG_PLAYROOM_AIR)
	if err != nil {
		return []int{}
	}
	for k := range data {
		r = append(r, GoUtil.Int(k))
	}
	return r
}

func GetInitDressList() []int {
	r := make([]int, 0)
	data, err := gamedata.GetData(CFG_PLAYROOM_DRESS)
	if err != nil {
		return []int{}
	}
	for k, v := range data {
		if gamedata.GetIntValue(v, "Init") == 1 {
			r = append(r, GoUtil.Int(k))
		}
	}
	return r
}

func GetDressList() []int {
	r := make([]int, 0)
	data, err := gamedata.GetData(CFG_PLAYROOM_DRESS)
	if err != nil {
		return []int{}
	}
	for k := range data {
		r = append(r, GoUtil.Int(k))
	}
	return r
}

func GetDressPart(Id int) int {
	data, err := gamedata.GetDataByIntKey(CFG_PLAYROOM_DRESS, Id)
	if err != nil {
		return 0
	}
	return gamedata.GetIntValue(data, "IPart")
}
